123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title><GMainContext>: </title>
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
- <link rel="home" href="index.html" title="">
- <link rel="up" href="ch01.html" title="GLib">
- <link rel="prev" href="re32.html" title="<%GLibLogWriterOutput>">
- <link rel="next" href="re34.html" title="<GMainLoop>">
- <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
- <link rel="stylesheet" href="style.css" type="text/css">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
- <td width="100%" align="left" class="shortcuts"></td>
- <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
- <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
- <td><a accesskey="p" href="re32.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
- <td><a accesskey="n" href="re34.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
- </tr></table>
- <div class="refentry">
- <a name="id-1.1.34"></a><div class="titlepage"></div>
- <div class="refnamediv">
- <h2><GMainContext></h2>
- <p><GMainContext></p>
- </div>
- <div class="refsect1">
- <a name="id-1.1.34.2"></a><h2>Description</h2>
- <p>The <code class="code">GMainContext</code> struct is an opaque data
- type representing a set of sources to be handled in a main loop.</p>
- </div>
- <div class="refsect1">
- <a name="id-1.1.34.3"></a><h2>Functions</h2>
- <div class="refsect2">
- <a name="id-1.1.34.3.2"></a><h3>acquire?</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:acquire? self))
- </pre></div>
- <p>Tries to become the owner of the specified context.
- If some other thread is the owner of the context,
- returns <code class="constant">FALSE</code> immediately. Ownership is properly
- recursive: the owner can require ownership again
- and will release ownership when <code class="function">g_main_context_release()</code>
- is called as many times as <code class="function">g_main_context_acquire()</code>.
- </p>
- <p>You must be the owner of a context before you
- can call <code class="function">g_main_context_prepare()</code>, <code class="function">g_main_context_query()</code>,
- <code class="function">g_main_context_check()</code>, <code class="function">g_main_context_dispatch()</code>.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.2.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.3"></a><h3>add-poll</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:add-poll self fd priority))
- </pre></div>
- <p>Adds a file descriptor to the set of file descriptors polled for
- this context. This will very seldom be used directly. Instead
- a typical event source will use <code class="function">g_source_add_unix_fd()</code> instead.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.3.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span> (or <code class="constant">NULL</code> for the default context)</p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>fd</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GPollFD</span> structure holding information about a file
- descriptor to watch.</p>
- <p>Passed as <code class="code">fd</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>priority</p></td>
- <td class="parameter_description">
- <p>the priority for this file descriptor which should be
- the same as the priority used for <code class="function">g_source_attach()</code> to ensure that the
- file descriptor is polled whenever the results may be needed.</p>
- <p>Passed as <code class="code">priority</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.4"></a><h3>check?</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:check? self max-priority fds))
- </pre></div>
- <p>Passes the results of polling back to the main loop.
- </p>
- <p>You must have successfully acquired the context with
- <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.4.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>max_priority</p></td>
- <td class="parameter_description">
- <p>the maximum numerical priority of sources to check</p>
- <p>Passed as <code class="code">max-priority</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>fds</p></td>
- <td class="parameter_description">
- <p>array of <span class="type">GPollFD</span>'s that was passed to
- the last call to <code class="function">g_main_context_query()</code></p>
- <p>Passed as <code class="code">fds</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>n_fds</p></td>
- <td class="parameter_description">
- <p>return value of <code class="function">g_main_context_query()</code></p>
- <p>Inferred from <code class="code">fds</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.5"></a><h3>dispatch</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:dispatch self))
- </pre></div>
- <p>Dispatches all pending sources.
- </p>
- <p>You must have successfully acquired the context with
- <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.5.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.6"></a><h3>find-source-by-id</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:find-source-by-id self source-id))
- </pre></div>
- <p>Finds a <span class="type">GSource</span> given a pair of context and ID.
- </p>
- <p>It is a programmer error to attempt to look up a non-existent source.
- </p>
- <p>More specifically: source IDs can be reissued after a source has been
- destroyed and therefore it is never valid to use this function with a
- source ID which may have already been removed. An example is when
- scheduling an idle to run in another thread with <code class="function">g_idle_add()</code>: the
- idle may already have run and been removed by the time this function
- is called on its (now invalid) source ID. This source ID may have
- been reissued, leading to the operation being performed against the
- wrong source.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.6.6"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>source_id</p></td>
- <td class="parameter_description">
- <p>the source ID, as returned by <code class="function">g_source_get_id()</code>.</p>
- <p>Passed as <code class="code">source-id</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.7"></a><h3>find-source-by-user-data</h3>
- <div class="informalexample"><pre class="programlisting">(define-values
- (%return)
- (main-context:find-source-by-user-data self user-data))
- </pre></div>
- <p>Finds a source with the given user data for the callback. If
- multiple sources exist with the same user data, the first
- one found will be returned.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.7.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>user_data</p></td>
- <td class="parameter_description">
- <p>the user_data for the callback.</p>
- <p>Passed as <code class="code">user-data</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.8"></a><h3>invoke-full</h3>
- <div class="informalexample"><pre class="programlisting">(define-values
- ()
- (main-context:invoke-full self priority function data notify))
- </pre></div>
- <p>Invokes a function in such a way that <em class="parameter"><code>context</code></em> is owned during the
- invocation of <em class="parameter"><code>function</code></em>.
- </p>
- <p>This function is the same as <code class="function">g_main_context_invoke()</code> except that it
- lets you specify the priority in case <em class="parameter"><code>function</code></em> ends up being
- scheduled as an idle and also lets you give a <span class="type">GDestroyNotify</span> for <em class="parameter"><code>data</code></em>.
- </p>
- <p><em class="parameter"><code>notify</code></em> should not assume that it is called from any particular
- thread or with any particular context acquired.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.8.6"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>priority</p></td>
- <td class="parameter_description">
- <p>the priority at which to run <em class="parameter"><code>function</code></em></p>
- <p>Passed as <code class="code">priority</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>function</p></td>
- <td class="parameter_description">
- <p>function to call</p>
- <p>Passed as <code class="code">function</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>data</p></td>
- <td class="parameter_description">
- <p>data to pass to <em class="parameter"><code>function</code></em></p>
- <p>Passed as <code class="code">data</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>notify</p></td>
- <td class="parameter_description">
- <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>
- <p>Passed as <code class="code">notify</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.9"></a><h3>is-owner?</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:is-owner? self))
- </pre></div>
- <p>Determines whether this thread holds the (recursive)
- ownership of this <span class="type">GMainContext</span>. This is useful to
- know before waiting on another thread that may be
- blocking to get ownership of <em class="parameter"><code>context</code></em>.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.9.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.10"></a><h3>iteration?</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:iteration? self may-block))
- </pre></div>
- <p>Runs a single iteration for the given main loop. This involves
- checking to see if any event sources are ready to be processed,
- then if no events sources are ready and <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, waiting
- for a source to become ready, then dispatching the highest priority
- events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em> is <code class="constant">FALSE</code>
- sources are not waited to become ready, only those highest priority
- events sources will be dispatched (if any), that are ready at this
- given moment without further waiting.
- </p>
- <p>Note that even when <em class="parameter"><code>may_block</code></em> is <code class="constant">TRUE</code>, it is still possible for
- <code class="function">g_main_context_iteration()</code> to return <code class="constant">FALSE</code>, since the wait may
- be interrupted for other reasons than an event source becoming ready.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.10.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>may_block</p></td>
- <td class="parameter_description">
- <p>whether the call may block.</p>
- <p>Passed as <code class="code">may-block</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.11"></a><h3>pending?</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:pending? self))
- </pre></div>
- <p>Checks if any sources have pending events for the given context.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.11.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.12"></a><h3>pop-thread-default</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:pop-thread-default self))
- </pre></div>
- <p>Pops <em class="parameter"><code>context</code></em> off the thread-default context stack (verifying that
- it was on the top of the stack).</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.12.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span> object, or <code class="constant">NULL</code></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.13"></a><h3>prepare</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return priority) (main-context:prepare self))
- </pre></div>
- <p>Prepares to poll sources within a main loop. The resulting information
- for polling is determined by calling g_main_context_query ().
- </p>
- <p>You must have successfully acquired the context with
- <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.13.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>priority</p></td>
- <td class="parameter_description">
- <p>location to store priority of highest priority
- source already ready.</p>
- <p>Passed as <code class="code">priority</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.14"></a><h3>push-thread-default</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:push-thread-default self))
- </pre></div>
- <p>Acquires <em class="parameter"><code>context</code></em> and sets it as the thread-default context for the
- current thread. This will cause certain asynchronous operations
- (such as most [gio][gio]-based I/O) which are
- started in this thread to run under <em class="parameter"><code>context</code></em> and deliver their
- results to its main loop, rather than running under the global
- default context in the main thread. Note that calling this function
- changes the context returned by <code class="function">g_main_context_get_thread_default()</code>,
- not the one returned by <code class="function">g_main_context_default()</code>, so it does not affect
- the context used by functions like <code class="function">g_idle_add()</code>.
- </p>
- <p>Normally you would call this function shortly after creating a new
- thread, passing it a <span class="type">GMainContext</span> which will be run by a
- <span class="type">GMainLoop</span> in that thread, to set a new default context for all
- async operations in that thread. In this case you may not need to
- ever call <code class="function">g_main_context_pop_thread_default()</code>, assuming you want the
- new <span class="type">GMainContext</span> to be the default for the whole lifecycle of the
- thread.
- </p>
- <p>If you don't have control over how the new thread was created (e.g.
- in the new thread isn't newly created, or if the thread life
- cycle is managed by a <span class="type">GThreadPool</span>), it is always suggested to wrap
- the logic that needs to use the new <span class="type">GMainContext</span> inside a
- <code class="function">g_main_context_push_thread_default()</code> / <code class="function">g_main_context_pop_thread_default()</code>
- pair, otherwise threads that are re-used will end up never explicitly
- releasing the <span class="type">GMainContext</span> reference they hold.
- </p>
- <p>In some cases you may want to schedule a single operation in a
- non-default context, or temporarily use a non-default context in
- the main thread. In that case, you can wrap the call to the
- asynchronous operation inside a
- <code class="function">g_main_context_push_thread_default()</code> /
- <code class="function">g_main_context_pop_thread_default()</code> pair, but it is up to you to
- ensure that no other asynchronous operations accidentally get
- started while the non-default context is active.
- </p>
- <p>Beware that libraries that predate this function may not correctly
- handle being used from a thread with a thread-default context. Eg,
- see <code class="function">g_file_supports_thread_contexts()</code>.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.14.8"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span>, or <code class="constant">NULL</code> for the global default context</p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.15"></a><h3>query!</h3>
- <div class="informalexample"><pre class="programlisting">(define-values
- (%return timeout- fds)
- (main-context:query! self max-priority fds))
- </pre></div>
- <p>Determines information necessary to poll this main loop.
- </p>
- <p>You must have successfully acquired the context with
- <code class="function">g_main_context_acquire()</code> before you may call this function.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.15.5"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>max_priority</p></td>
- <td class="parameter_description">
- <p>maximum priority source to check</p>
- <p>Passed as <code class="code">max-priority</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>timeout_</p></td>
- <td class="parameter_description">
- <p>location to store timeout to be used in polling</p>
- <p>Passed as <code class="code">timeout-</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>fds</p></td>
- <td class="parameter_description">
- <p>location to
- store <span class="type">GPollFD</span> records that need to be polled.</p>
- <p>Passed as <code class="code">fds</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>n_fds</p></td>
- <td class="parameter_description">
- <p>length of <em class="parameter"><code>fds</code></em>.</p>
- <p>Inferred from <code class="code">fds</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.16"></a><h3>ref</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref self))
- </pre></div>
- <p>Increases the reference count on a <span class="type">GMainContext</span> object by one.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.16.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.17"></a><h3>release</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:release self))
- </pre></div>
- <p>Releases ownership of a context previously acquired by this thread
- with <code class="function">g_main_context_acquire()</code>. If the context was acquired multiple
- times, the ownership will be released only when <code class="function">g_main_context_release()</code>
- is called as many times as it was acquired.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.17.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.18"></a><h3>remove-poll</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:remove-poll self fd))
- </pre></div>
- <p>Removes file descriptor from the set of file descriptors to be
- polled for a particular context.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.18.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table>
- <tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr>
- <tr>
- <td class="parameter_name"><p>fd</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GPollFD</span> descriptor previously added with <code class="function">g_main_context_add_poll()</code></p>
- <p>Passed as <code class="code">fd</code></p>
- </td>
- </tr>
- </table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.19"></a><h3>unref</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:unref self))
- </pre></div>
- <p>Decreases the reference count on a <span class="type">GMainContext</span> object by one. If
- the result is zero, free the context and free all associated memory.</p>
- <div class="refsect3">
- <a name="id-1.1.34.3.19.4"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.20"></a><h3>wakeup</h3>
- <div class="informalexample"><pre class="programlisting">(define-values () (main-context:wakeup self))
- </pre></div>
- <p>If <em class="parameter"><code>context</code></em> is currently blocking in <code class="function">g_main_context_iteration()</code>
- waiting for a source to become ready, cause it to stop blocking
- and return. Otherwise, cause the next invocation of
- <code class="function">g_main_context_iteration()</code> to return without blocking.
- </p>
- <p>This API is useful for low-level control over <span class="type">GMainContext</span>; for
- example, integrating it with main loop implementations such as
- <span class="type">GMainLoop</span>.
- </p>
- <p>Another related use for this function is when implementing a main
- loop with a termination condition, computed from multiple threads:
- </p>
- <div class="informalexample"><pre class="programlisting">
- #define NUM_TASKS 10
- static volatile gint tasks_remaining = NUM_TASKS;
- ...
-
- while (g_atomic_int_get (&tasks_remaining) != 0)
- g_main_context_iteration (NULL, TRUE);
- </pre></div>
-
- <p>Then in a thread:
- </p>
- <div class="informalexample"><pre class="programlisting">
- perform_work();
- if (g_atomic_int_dec_and_test (&tasks_remaining))
- g_main_context_wakeup (NULL);
- </pre></div>
- <div class="refsect3">
- <a name="id-1.1.34.3.20.8"></a><h4>Parameters</h4>
- <div class="informaltable"><table><tr>
- <td class="parameter_name"><p>context</p></td>
- <td class="parameter_description">
- <p>a <span class="type">GMainContext</span></p>
- <p>Passed as <code class="code">self</code></p>
- </td>
- </tr></table></div>
- </div>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.21"></a><h3>main-context:new</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:new))
- </pre></div>
- <p>Undocumented</p>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.22"></a><h3>main-context:default</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:default))
- </pre></div>
- <p>Returns the global default main context. This is the main context
- used for main loop functions when a main loop is not explicitly
- specified, and corresponds to the "main" main loop. See also
- <code class="function">g_main_context_get_thread_default()</code>.</p>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.23"></a><h3>main-context:get-thread-default</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:get-thread-default))
- </pre></div>
- <p>Gets the thread-default <span class="type">GMainContext</span> for this thread. Asynchronous
- operations that want to be able to be run in contexts other than
- the default one should call this method or
- <code class="function">g_main_context_ref_thread_default()</code> to get a <span class="type">GMainContext</span> to add
- their <span class="type">GSources</span> to. (Note that even in single-threaded
- programs applications may sometimes want to temporarily push a
- non-default context, so it is not safe to assume that this will
- always return <code class="constant">NULL</code> if you are running in the default thread.)
- </p>
- <p>If you need to hold a reference on the context, use
- <code class="function">g_main_context_ref_thread_default()</code> instead.</p>
- </div>
- <div class="refsect2">
- <a name="id-1.1.34.3.24"></a><h3>main-context:ref-thread-default</h3>
- <div class="informalexample"><pre class="programlisting">(define-values (%return) (main-context:ref-thread-default))
- </pre></div>
- <p>Gets the thread-default <span class="type">GMainContext</span> for this thread, as with
- <code class="function">g_main_context_get_thread_default()</code>, but also adds a reference to
- it with <code class="function">g_main_context_ref()</code>. In addition, unlike
- <code class="function">g_main_context_get_thread_default()</code>, if the thread-default context
- is the global default context, this will return that <span class="type">GMainContext</span>
- (with a ref added to it) rather than returning <code class="constant">NULL</code>.</p>
- </div>
- </div>
- </div>
- <div class="footer">
- <hr>Generated by GTK-Doc V1.33.1</div>
- </body>
- </html>
|