re33.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GMainContext&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re32.html" title="&lt;%GLibLogWriterOutput&gt;">
  10. <link rel="next" href="re34.html" title="&lt;GMainLoop&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re32.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re34.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.34"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GMainContext&gt;</h2>
  26. <p>&lt;GMainContext&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.34.2"></a><h2>Description</h2>
  30. <p>The <code class="code">GMainContext</code> struct is an opaque data
  31. type representing a set of sources to be handled in a main loop.</p>
  32. </div>
  33. <div class="refsect1">
  34. <a name="id-1.1.34.3"></a><h2>Functions</h2>
  35. <div class="refsect2">
  36. <a name="id-1.1.34.3.2"></a><h3>acquire?</h3>
  37. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:acquire? self))
  38. </pre></div>
  39. <p>Tries to become the owner of the specified context.
  40. If some other thread is the owner of the context,
  41. returns <code class="constant">FALSE</code> immediately. Ownership is properly
  42. recursive: the owner can require ownership again
  43. and will release ownership when <code class="function">g_main_context_release()</code>
  44. is called as many times as <code class="function">g_main_context_acquire()</code>.
  45. </p>
  46. <p>You must be the owner of a context before you
  47. can call <code class="function">g_main_context_prepare()</code>, <code class="function">g_main_context_query()</code>,
  48. <code class="function">g_main_context_check()</code>, <code class="function">g_main_context_dispatch()</code>.</p>
  49. <div class="refsect3">
  50. <a name="id-1.1.34.3.2.5"></a><h4>Parameters</h4>
  51. <div class="informaltable"><table><tr>
  52. <td class="parameter_name"><p>context</p></td>
  53. <td class="parameter_description">
  54. <p>a <span class="type">GMainContext</span></p>
  55. <p>Passed as <code class="code">self</code></p>
  56. </td>
  57. </tr></table></div>
  58. </div>
  59. </div>
  60. <div class="refsect2">
  61. <a name="id-1.1.34.3.3"></a><h3>add-poll</h3>
  62. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:add-poll self fd priority))
  63. </pre></div>
  64. <p>Adds a file descriptor to the set of file descriptors polled for
  65. this context. This will very seldom be used directly. Instead
  66. a typical event source will use <code class="function">g_source_add_unix_fd()</code> instead.</p>
  67. <div class="refsect3">
  68. <a name="id-1.1.34.3.3.4"></a><h4>Parameters</h4>
  69. <div class="informaltable"><table>
  70. <tr>
  71. <td class="parameter_name"><p>context</p></td>
  72. <td class="parameter_description">
  73. <p>a <span class="type">GMainContext</span> (or <code class="constant">NULL</code> for the default context)</p>
  74. <p>Passed as <code class="code">self</code></p>
  75. </td>
  76. </tr>
  77. <tr>
  78. <td class="parameter_name"><p>fd</p></td>
  79. <td class="parameter_description">
  80. <p>a <span class="type">GPollFD</span> structure holding information about a file
  81. descriptor to watch.</p>
  82. <p>Passed as <code class="code">fd</code></p>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td class="parameter_name"><p>priority</p></td>
  87. <td class="parameter_description">
  88. <p>the priority for this file descriptor which should be
  89. the same as the priority used for <code class="function">g_source_attach()</code> to ensure that the
  90. file descriptor is polled whenever the results may be needed.</p>
  91. <p>Passed as <code class="code">priority</code></p>
  92. </td>
  93. </tr>
  94. </table></div>
  95. </div>
  96. </div>
  97. <div class="refsect2">
  98. <a name="id-1.1.34.3.4"></a><h3>check?</h3>
  99. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:check? self max-priority fds))
  100. </pre></div>
  101. <p>Passes the results of polling back to the main loop.
  102. </p>
  103. <p>You must have successfully acquired the context with
  104. <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
  105. <div class="refsect3">
  106. <a name="id-1.1.34.3.4.5"></a><h4>Parameters</h4>
  107. <div class="informaltable"><table>
  108. <tr>
  109. <td class="parameter_name"><p>context</p></td>
  110. <td class="parameter_description">
  111. <p>a <span class="type">GMainContext</span></p>
  112. <p>Passed as <code class="code">self</code></p>
  113. </td>
  114. </tr>
  115. <tr>
  116. <td class="parameter_name"><p>max_priority</p></td>
  117. <td class="parameter_description">
  118. <p>the maximum numerical priority of sources to check</p>
  119. <p>Passed as <code class="code">max-priority</code></p>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td class="parameter_name"><p>fds</p></td>
  124. <td class="parameter_description">
  125. <p>array of <span class="type">GPollFD</span>'s that was passed to
  126. the last call to <code class="function">g_main_context_query()</code></p>
  127. <p>Passed as <code class="code">fds</code></p>
  128. </td>
  129. </tr>
  130. <tr>
  131. <td class="parameter_name"><p>n_fds</p></td>
  132. <td class="parameter_description">
  133. <p>return value of <code class="function">g_main_context_query()</code></p>
  134. <p>Inferred from <code class="code">fds</code></p>
  135. </td>
  136. </tr>
  137. </table></div>
  138. </div>
  139. </div>
  140. <div class="refsect2">
  141. <a name="id-1.1.34.3.5"></a><h3>dispatch</h3>
  142. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:dispatch self))
  143. </pre></div>
  144. <p>Dispatches all pending sources.
  145. </p>
  146. <p>You must have successfully acquired the context with
  147. <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
  148. <div class="refsect3">
  149. <a name="id-1.1.34.3.5.5"></a><h4>Parameters</h4>
  150. <div class="informaltable"><table><tr>
  151. <td class="parameter_name"><p>context</p></td>
  152. <td class="parameter_description">
  153. <p>a <span class="type">GMainContext</span></p>
  154. <p>Passed as <code class="code">self</code></p>
  155. </td>
  156. </tr></table></div>
  157. </div>
  158. </div>
  159. <div class="refsect2">
  160. <a name="id-1.1.34.3.6"></a><h3>find-source-by-id</h3>
  161. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:find-source-by-id self source-id))
  162. </pre></div>
  163. <p>Finds a <span class="type">GSource</span> given a pair of context and ID.
  164. </p>
  165. <p>It is a programmer error to attempt to look up a non-existent source.
  166. </p>
  167. <p>More specifically: source IDs can be reissued after a source has been
  168. destroyed and therefore it is never valid to use this function with a
  169. source ID which may have already been removed. An example is when
  170. scheduling an idle to run in another thread with <code class="function">g_idle_add()</code>: the
  171. idle may already have run and been removed by the time this function
  172. is called on its (now invalid) source ID. This source ID may have
  173. been reissued, leading to the operation being performed against the
  174. wrong source.</p>
  175. <div class="refsect3">
  176. <a name="id-1.1.34.3.6.6"></a><h4>Parameters</h4>
  177. <div class="informaltable"><table>
  178. <tr>
  179. <td class="parameter_name"><p>context</p></td>
  180. <td class="parameter_description">
  181. <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
  182. <p>Passed as <code class="code">self</code></p>
  183. </td>
  184. </tr>
  185. <tr>
  186. <td class="parameter_name"><p>source_id</p></td>
  187. <td class="parameter_description">
  188. <p>the source ID, as returned by <code class="function">g_source_get_id()</code>.</p>
  189. <p>Passed as <code class="code">source-id</code></p>
  190. </td>
  191. </tr>
  192. </table></div>
  193. </div>
  194. </div>
  195. <div class="refsect2">
  196. <a name="id-1.1.34.3.7"></a><h3>find-source-by-user-data</h3>
  197. <div class="informalexample"><pre class="programlisting">(define-values
  198. (%return)
  199. (main-context:find-source-by-user-data self user-data))
  200. </pre></div>
  201. <p>Finds a source with the given user data for the callback. If
  202. multiple sources exist with the same user data, the first
  203. one found will be returned.</p>
  204. <div class="refsect3">
  205. <a name="id-1.1.34.3.7.4"></a><h4>Parameters</h4>
  206. <div class="informaltable"><table>
  207. <tr>
  208. <td class="parameter_name"><p>context</p></td>
  209. <td class="parameter_description">
  210. <p>a <span class="type">GMainContext</span></p>
  211. <p>Passed as <code class="code">self</code></p>
  212. </td>
  213. </tr>
  214. <tr>
  215. <td class="parameter_name"><p>user_data</p></td>
  216. <td class="parameter_description">
  217. <p>the user_data for the callback.</p>
  218. <p>Passed as <code class="code">user-data</code></p>
  219. </td>
  220. </tr>
  221. </table></div>
  222. </div>
  223. </div>
  224. <div class="refsect2">
  225. <a name="id-1.1.34.3.8"></a><h3>invoke-full</h3>
  226. <div class="informalexample"><pre class="programlisting">(define-values
  227. ()
  228. (main-context:invoke-full self priority function data notify))
  229. </pre></div>
  230. <p>Invokes a function in such a way that <em class="parameter"><code>context</code></em> is owned during the
  231. invocation of <em class="parameter"><code>function</code></em>.
  232. </p>
  233. <p>This function is the same as <code class="function">g_main_context_invoke()</code> except that it
  234. lets you specify the priority in case <em class="parameter"><code>function</code></em> ends up being
  235. scheduled as an idle and also lets you give a <span class="type">GDestroyNotify</span> for <em class="parameter"><code>data</code></em>.
  236. </p>
  237. <p><em class="parameter"><code>notify</code></em> should not assume that it is called from any particular
  238. thread or with any particular context acquired.</p>
  239. <div class="refsect3">
  240. <a name="id-1.1.34.3.8.6"></a><h4>Parameters</h4>
  241. <div class="informaltable"><table>
  242. <tr>
  243. <td class="parameter_name"><p>context</p></td>
  244. <td class="parameter_description">
  245. <p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code></p>
  246. <p>Passed as <code class="code">self</code></p>
  247. </td>
  248. </tr>
  249. <tr>
  250. <td class="parameter_name"><p>priority</p></td>
  251. <td class="parameter_description">
  252. <p>the priority at which to run <em class="parameter"><code>function</code></em></p>
  253. <p>Passed as <code class="code">priority</code></p>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td class="parameter_name"><p>function</p></td>
  258. <td class="parameter_description">
  259. <p>function to call</p>
  260. <p>Passed as <code class="code">function</code></p>
  261. </td>
  262. </tr>
  263. <tr>
  264. <td class="parameter_name"><p>data</p></td>
  265. <td class="parameter_description">
  266. <p>data to pass to <em class="parameter"><code>function</code></em></p>
  267. <p>Passed as <code class="code">data</code></p>
  268. </td>
  269. </tr>
  270. <tr>
  271. <td class="parameter_name"><p>notify</p></td>
  272. <td class="parameter_description">
  273. <p>a function to call when <em class="parameter"><code>data</code></em> is no longer in use, or <code class="constant">NULL</code>.</p>
  274. <p>Passed as <code class="code">notify</code></p>
  275. </td>
  276. </tr>
  277. </table></div>
  278. </div>
  279. </div>
  280. <div class="refsect2">
  281. <a name="id-1.1.34.3.9"></a><h3>is-owner?</h3>
  282. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:is-owner? self))
  283. </pre></div>
  284. <p>Determines whether this thread holds the (recursive)
  285. ownership of this <span class="type">GMainContext</span>. This is useful to
  286. know before waiting on another thread that may be
  287. blocking to get ownership of <em class="parameter"><code>context</code></em>.</p>
  288. <div class="refsect3">
  289. <a name="id-1.1.34.3.9.4"></a><h4>Parameters</h4>
  290. <div class="informaltable"><table><tr>
  291. <td class="parameter_name"><p>context</p></td>
  292. <td class="parameter_description">
  293. <p>a <span class="type">GMainContext</span></p>
  294. <p>Passed as <code class="code">self</code></p>
  295. </td>
  296. </tr></table></div>
  297. </div>
  298. </div>
  299. <div class="refsect2">
  300. <a name="id-1.1.34.3.10"></a><h3>iteration?</h3>
  301. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:iteration? self may-block))
  302. </pre></div>
  303. <p>Runs a single iteration for the given main loop. This involves
  304. checking to see if any event sources are ready to be processed,
  305. then if no events sources are ready and <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, waiting
  306. for a source to become ready, then dispatching the highest priority
  307. events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em> is <code class="constant">FALSE</code>
  308. sources are not waited to become ready, only those highest priority
  309. events sources will be dispatched (if any), that are ready at this
  310. given moment without further waiting.
  311. </p>
  312. <p>Note that even when <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, it is still possible for
  313. <code class="function">g_main_context_iteration()</code> to return <code class="constant">FALSE</code>, since the wait may
  314. be interrupted for other reasons than an event source becoming ready.</p>
  315. <div class="refsect3">
  316. <a name="id-1.1.34.3.10.5"></a><h4>Parameters</h4>
  317. <div class="informaltable"><table>
  318. <tr>
  319. <td class="parameter_name"><p>context</p></td>
  320. <td class="parameter_description">
  321. <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
  322. <p>Passed as <code class="code">self</code></p>
  323. </td>
  324. </tr>
  325. <tr>
  326. <td class="parameter_name"><p>may_block</p></td>
  327. <td class="parameter_description">
  328. <p>whether the call may block.</p>
  329. <p>Passed as <code class="code">may-block</code></p>
  330. </td>
  331. </tr>
  332. </table></div>
  333. </div>
  334. </div>
  335. <div class="refsect2">
  336. <a name="id-1.1.34.3.11"></a><h3>pending?</h3>
  337. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:pending? self))
  338. </pre></div>
  339. <p>Checks if any sources have pending events for the given context.</p>
  340. <div class="refsect3">
  341. <a name="id-1.1.34.3.11.4"></a><h4>Parameters</h4>
  342. <div class="informaltable"><table><tr>
  343. <td class="parameter_name"><p>context</p></td>
  344. <td class="parameter_description">
  345. <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
  346. <p>Passed as <code class="code">self</code></p>
  347. </td>
  348. </tr></table></div>
  349. </div>
  350. </div>
  351. <div class="refsect2">
  352. <a name="id-1.1.34.3.12"></a><h3>pop-thread-default</h3>
  353. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:pop-thread-default self))
  354. </pre></div>
  355. <p>Pops <em class="parameter"><code>context</code></em> off the thread-default context stack (verifying that
  356. it was on the top of the stack).</p>
  357. <div class="refsect3">
  358. <a name="id-1.1.34.3.12.4"></a><h4>Parameters</h4>
  359. <div class="informaltable"><table><tr>
  360. <td class="parameter_name"><p>context</p></td>
  361. <td class="parameter_description">
  362. <p>a <span class="type">GMainContext</span> object, or <code class="constant">NULL</code></p>
  363. <p>Passed as <code class="code">self</code></p>
  364. </td>
  365. </tr></table></div>
  366. </div>
  367. </div>
  368. <div class="refsect2">
  369. <a name="id-1.1.34.3.13"></a><h3>prepare</h3>
  370. <div class="informalexample"><pre class="programlisting">(define-values (%return priority) (main-context:prepare self))
  371. </pre></div>
  372. <p>Prepares to poll sources within a main loop. The resulting information
  373. for polling is determined by calling g_main_context_query ().
  374. </p>
  375. <p>You must have successfully acquired the context with
  376. <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
  377. <div class="refsect3">
  378. <a name="id-1.1.34.3.13.5"></a><h4>Parameters</h4>
  379. <div class="informaltable"><table>
  380. <tr>
  381. <td class="parameter_name"><p>context</p></td>
  382. <td class="parameter_description">
  383. <p>a <span class="type">GMainContext</span></p>
  384. <p>Passed as <code class="code">self</code></p>
  385. </td>
  386. </tr>
  387. <tr>
  388. <td class="parameter_name"><p>priority</p></td>
  389. <td class="parameter_description">
  390. <p>location to store priority of highest priority
  391. source already ready.</p>
  392. <p>Passed as <code class="code">priority</code></p>
  393. </td>
  394. </tr>
  395. </table></div>
  396. </div>
  397. </div>
  398. <div class="refsect2">
  399. <a name="id-1.1.34.3.14"></a><h3>push-thread-default</h3>
  400. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:push-thread-default self))
  401. </pre></div>
  402. <p>Acquires <em class="parameter"><code>context</code></em> and sets it as the thread-default context for the
  403. current thread. This will cause certain asynchronous operations
  404. (such as most [gio][gio]-based I/O) which are
  405. started in this thread to run under <em class="parameter"><code>context</code></em> and deliver their
  406. results to its main loop, rather than running under the global
  407. default context in the main thread. Note that calling this function
  408. changes the context returned by <code class="function">g_main_context_get_thread_default()</code>,
  409. not the one returned by <code class="function">g_main_context_default()</code>, so it does not affect
  410. the context used by functions like <code class="function">g_idle_add()</code>.
  411. </p>
  412. <p>Normally you would call this function shortly after creating a new
  413. thread, passing it a <span class="type">GMainContext</span> which will be run by a
  414. <span class="type">GMainLoop</span> in that thread, to set a new default context for all
  415. async operations in that thread. In this case you may not need to
  416. ever call <code class="function">g_main_context_pop_thread_default()</code>, assuming you want the
  417. new <span class="type">GMainContext</span> to be the default for the whole lifecycle of the
  418. thread.
  419. </p>
  420. <p>If you don't have control over how the new thread was created (e.g.
  421. in the new thread isn't newly created, or if the thread life
  422. cycle is managed by a <span class="type">GThreadPool</span>), it is always suggested to wrap
  423. the logic that needs to use the new <span class="type">GMainContext</span> inside a
  424. <code class="function">g_main_context_push_thread_default()</code> / <code class="function">g_main_context_pop_thread_default()</code>
  425. pair, otherwise threads that are re-used will end up never explicitly
  426. releasing the <span class="type">GMainContext</span> reference they hold.
  427. </p>
  428. <p>In some cases you may want to schedule a single operation in a
  429. non-default context, or temporarily use a non-default context in
  430. the main thread. In that case, you can wrap the call to the
  431. asynchronous operation inside a
  432. <code class="function">g_main_context_push_thread_default()</code> /
  433. <code class="function">g_main_context_pop_thread_default()</code> pair, but it is up to you to
  434. ensure that no other asynchronous operations accidentally get
  435. started while the non-default context is active.
  436. </p>
  437. <p>Beware that libraries that predate this function may not correctly
  438. handle being used from a thread with a thread-default context. Eg,
  439. see <code class="function">g_file_supports_thread_contexts()</code>.</p>
  440. <div class="refsect3">
  441. <a name="id-1.1.34.3.14.8"></a><h4>Parameters</h4>
  442. <div class="informaltable"><table><tr>
  443. <td class="parameter_name"><p>context</p></td>
  444. <td class="parameter_description">
  445. <p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code> for the global default context</p>
  446. <p>Passed as <code class="code">self</code></p>
  447. </td>
  448. </tr></table></div>
  449. </div>
  450. </div>
  451. <div class="refsect2">
  452. <a name="id-1.1.34.3.15"></a><h3>query!</h3>
  453. <div class="informalexample"><pre class="programlisting">(define-values
  454. (%return timeout- fds)
  455. (main-context:query! self max-priority fds))
  456. </pre></div>
  457. <p>Determines information necessary to poll this main loop.
  458. </p>
  459. <p>You must have successfully acquired the context with
  460. <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
  461. <div class="refsect3">
  462. <a name="id-1.1.34.3.15.5"></a><h4>Parameters</h4>
  463. <div class="informaltable"><table>
  464. <tr>
  465. <td class="parameter_name"><p>context</p></td>
  466. <td class="parameter_description">
  467. <p>a <span class="type">GMainContext</span></p>
  468. <p>Passed as <code class="code">self</code></p>
  469. </td>
  470. </tr>
  471. <tr>
  472. <td class="parameter_name"><p>max_priority</p></td>
  473. <td class="parameter_description">
  474. <p>maximum priority source to check</p>
  475. <p>Passed as <code class="code">max-priority</code></p>
  476. </td>
  477. </tr>
  478. <tr>
  479. <td class="parameter_name"><p>timeout_</p></td>
  480. <td class="parameter_description">
  481. <p>location to store timeout to be used in polling</p>
  482. <p>Passed as <code class="code">timeout-</code></p>
  483. </td>
  484. </tr>
  485. <tr>
  486. <td class="parameter_name"><p>fds</p></td>
  487. <td class="parameter_description">
  488. <p>location to
  489. store <span class="type">GPollFD</span> records that need to be polled.</p>
  490. <p>Passed as <code class="code">fds</code></p>
  491. </td>
  492. </tr>
  493. <tr>
  494. <td class="parameter_name"><p>n_fds</p></td>
  495. <td class="parameter_description">
  496. <p>length of <em class="parameter"><code>fds</code></em>.</p>
  497. <p>Inferred from <code class="code">fds</code></p>
  498. </td>
  499. </tr>
  500. </table></div>
  501. </div>
  502. </div>
  503. <div class="refsect2">
  504. <a name="id-1.1.34.3.16"></a><h3>ref</h3>
  505. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref self))
  506. </pre></div>
  507. <p>Increases the reference count on a <span class="type">GMainContext</span> object by one.</p>
  508. <div class="refsect3">
  509. <a name="id-1.1.34.3.16.4"></a><h4>Parameters</h4>
  510. <div class="informaltable"><table><tr>
  511. <td class="parameter_name"><p>context</p></td>
  512. <td class="parameter_description">
  513. <p>a <span class="type">GMainContext</span></p>
  514. <p>Passed as <code class="code">self</code></p>
  515. </td>
  516. </tr></table></div>
  517. </div>
  518. </div>
  519. <div class="refsect2">
  520. <a name="id-1.1.34.3.17"></a><h3>release</h3>
  521. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:release self))
  522. </pre></div>
  523. <p>Releases ownership of a context previously acquired by this thread
  524. with <code class="function">g_main_context_acquire()</code>. If the context was acquired multiple
  525. times, the ownership will be released only when <code class="function">g_main_context_release()</code>
  526. is called as many times as it was acquired.</p>
  527. <div class="refsect3">
  528. <a name="id-1.1.34.3.17.4"></a><h4>Parameters</h4>
  529. <div class="informaltable"><table><tr>
  530. <td class="parameter_name"><p>context</p></td>
  531. <td class="parameter_description">
  532. <p>a <span class="type">GMainContext</span></p>
  533. <p>Passed as <code class="code">self</code></p>
  534. </td>
  535. </tr></table></div>
  536. </div>
  537. </div>
  538. <div class="refsect2">
  539. <a name="id-1.1.34.3.18"></a><h3>remove-poll</h3>
  540. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:remove-poll self fd))
  541. </pre></div>
  542. <p>Removes file descriptor from the set of file descriptors to be
  543. polled for a particular context.</p>
  544. <div class="refsect3">
  545. <a name="id-1.1.34.3.18.4"></a><h4>Parameters</h4>
  546. <div class="informaltable"><table>
  547. <tr>
  548. <td class="parameter_name"><p>context</p></td>
  549. <td class="parameter_description">
  550. <p>a <span class="type">GMainContext</span></p>
  551. <p>Passed as <code class="code">self</code></p>
  552. </td>
  553. </tr>
  554. <tr>
  555. <td class="parameter_name"><p>fd</p></td>
  556. <td class="parameter_description">
  557. <p>a <span class="type">GPollFD</span> descriptor previously added with <code class="function">g_main_context_add_poll()</code></p>
  558. <p>Passed as <code class="code">fd</code></p>
  559. </td>
  560. </tr>
  561. </table></div>
  562. </div>
  563. </div>
  564. <div class="refsect2">
  565. <a name="id-1.1.34.3.19"></a><h3>unref</h3>
  566. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:unref self))
  567. </pre></div>
  568. <p>Decreases the reference count on a <span class="type">GMainContext</span> object by one. If
  569. the result is zero, free the context and free all associated memory.</p>
  570. <div class="refsect3">
  571. <a name="id-1.1.34.3.19.4"></a><h4>Parameters</h4>
  572. <div class="informaltable"><table><tr>
  573. <td class="parameter_name"><p>context</p></td>
  574. <td class="parameter_description">
  575. <p>a <span class="type">GMainContext</span></p>
  576. <p>Passed as <code class="code">self</code></p>
  577. </td>
  578. </tr></table></div>
  579. </div>
  580. </div>
  581. <div class="refsect2">
  582. <a name="id-1.1.34.3.20"></a><h3>wakeup</h3>
  583. <div class="informalexample"><pre class="programlisting">(define-values () (main-context:wakeup self))
  584. </pre></div>
  585. <p>If <em class="parameter"><code>context</code></em> is currently blocking in <code class="function">g_main_context_iteration()</code>
  586. waiting for a source to become ready, cause it to stop blocking
  587. and return. Otherwise, cause the next invocation of
  588. <code class="function">g_main_context_iteration()</code> to return without blocking.
  589. </p>
  590. <p>This API is useful for low-level control over <span class="type">GMainContext</span>; for
  591. example, integrating it with main loop implementations such as
  592. <span class="type">GMainLoop</span>.
  593. </p>
  594. <p>Another related use for this function is when implementing a main
  595. loop with a termination condition, computed from multiple threads:
  596. </p>
  597. <div class="informalexample"><pre class="programlisting">
  598. #define NUM_TASKS 10
  599. static volatile gint tasks_remaining = NUM_TASKS;
  600. ...
  601. while (g_atomic_int_get (&amp;tasks_remaining) != 0)
  602. g_main_context_iteration (NULL, TRUE);
  603. </pre></div>
  604. <p>Then in a thread:
  605. </p>
  606. <div class="informalexample"><pre class="programlisting">
  607. perform_work();
  608. if (g_atomic_int_dec_and_test (&amp;tasks_remaining))
  609. g_main_context_wakeup (NULL);
  610. </pre></div>
  611. <div class="refsect3">
  612. <a name="id-1.1.34.3.20.8"></a><h4>Parameters</h4>
  613. <div class="informaltable"><table><tr>
  614. <td class="parameter_name"><p>context</p></td>
  615. <td class="parameter_description">
  616. <p>a <span class="type">GMainContext</span></p>
  617. <p>Passed as <code class="code">self</code></p>
  618. </td>
  619. </tr></table></div>
  620. </div>
  621. </div>
  622. <div class="refsect2">
  623. <a name="id-1.1.34.3.21"></a><h3>main-context:new</h3>
  624. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:new))
  625. </pre></div>
  626. <p>Undocumented</p>
  627. </div>
  628. <div class="refsect2">
  629. <a name="id-1.1.34.3.22"></a><h3>main-context:default</h3>
  630. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:default))
  631. </pre></div>
  632. <p>Returns the global default main context. This is the main context
  633. used for main loop functions when a main loop is not explicitly
  634. specified, and corresponds to the "main" main loop. See also
  635. <code class="function">g_main_context_get_thread_default()</code>.</p>
  636. </div>
  637. <div class="refsect2">
  638. <a name="id-1.1.34.3.23"></a><h3>main-context:get-thread-default</h3>
  639. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:get-thread-default))
  640. </pre></div>
  641. <p>Gets the thread-default <span class="type">GMainContext</span> for this thread. Asynchronous
  642. operations that want to be able to be run in contexts other than
  643. the default one should call this method or
  644. <code class="function">g_main_context_ref_thread_default()</code> to get a <span class="type">GMainContext</span> to add
  645. their <span class="type">GSources</span> to. (Note that even in single-threaded
  646. programs applications may sometimes want to temporarily push a
  647. non-default context, so it is not safe to assume that this will
  648. always return <code class="constant">NULL</code> if you are running in the default thread.)
  649. </p>
  650. <p>If you need to hold a reference on the context, use
  651. <code class="function">g_main_context_ref_thread_default()</code> instead.</p>
  652. </div>
  653. <div class="refsect2">
  654. <a name="id-1.1.34.3.24"></a><h3>main-context:ref-thread-default</h3>
  655. <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref-thread-default))
  656. </pre></div>
  657. <p>Gets the thread-default <span class="type">GMainContext</span> for this thread, as with
  658. <code class="function">g_main_context_get_thread_default()</code>, but also adds a reference to
  659. it with <code class="function">g_main_context_ref()</code>. In addition, unlike
  660. <code class="function">g_main_context_get_thread_default()</code>, if the thread-default context
  661. is the global default context, this will return that <span class="type">GMainContext</span>
  662. (with a ref added to it) rather than returning <code class="constant">NULL</code>.</p>
  663. </div>
  664. </div>
  665. </div>
  666. <div class="footer">
  667. <hr>Generated by GTK-Doc V1.33.1</div>
  668. </body>
  669. </html>