1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Threads: GDK 2 Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="GDK 2 Reference Manual">
<link rel="up" href="reference.html" title="API Reference">
<link rel="prev" href="gdk2-Properties-and-Atoms.html" title="Properties and Atoms">
<link rel="next" href="gdk2-Input.html" title="Input">
<meta name="generator" content="GTK-Doc V1.33.0 (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">
<a href="#" class="shortcut">Top</a><span id="nav_description"> <span class="dim">|</span>
<a href="#gdk2-Threads.description" class="shortcut">Description</a></span>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="reference.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="gdk2-Properties-and-Atoms.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gdk2-Input.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="gdk2-Threads"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="gdk2-Threads.top_of_page"></a>Threads</span></h2>
<p>Threads</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="gdk2-Threads.functions"></a><h2>Functions</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="functions_proto_type">
<col class="functions_proto_name">
</colgroup>
<tbody>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="gdk2-Threads.html#GDK-THREADS-ENTER:CAPS" title="GDK_THREADS_ENTER">GDK_THREADS_ENTER</a></td>
</tr>
<tr>
<td class="define_keyword">#define</td>
<td class="function_name"><a class="link" href="gdk2-Threads.html#GDK-THREADS-LEAVE:CAPS" title="GDK_THREADS_LEAVE">GDK_THREADS_LEAVE</a></td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-init" title="gdk_threads_init ()">gdk_threads_init</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-enter" title="gdk_threads_enter ()">gdk_threads_enter</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-leave" title="gdk_threads_leave ()">gdk_threads_leave</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-set-lock-functions" title="gdk_threads_set_lock_functions ()">gdk_threads_set_lock_functions</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-idle" title="gdk_threads_add_idle ()">gdk_threads_add_idle</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-idle-full" title="gdk_threads_add_idle_full ()">gdk_threads_add_idle_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout" title="gdk_threads_add_timeout ()">gdk_threads_add_timeout</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-full" title="gdk_threads_add_timeout_full ()">gdk_threads_add_timeout_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-seconds" title="gdk_threads_add_timeout_seconds ()">gdk_threads_add_timeout_seconds</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">guint</span>
</td>
<td class="function_name">
<a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-seconds-full" title="gdk_threads_add_timeout_seconds_full ()">gdk_threads_add_timeout_seconds_full</a> <span class="c_punctuation">()</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="gdk2-Threads.other"></a><h2>Types and Values</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="other_proto_type">
<col class="other_proto_name">
</colgroup>
<tbody><tr>
<td class="variable_type">extern GMutex *</td>
<td class="function_name"><a class="link" href="gdk2-Threads.html#gdk-threads-mutex" title="gdk_threads_mutex">gdk_threads_mutex</a></td>
</tr></tbody>
</table></div>
</div>
<div class="refsect1">
<a name="gdk2-Threads.includes"></a><h2>Includes</h2>
<pre class="synopsis">#include <gdk/gdk.h>
</pre>
</div>
<div class="refsect1">
<a name="gdk2-Threads.description"></a><h2>Description</h2>
</div>
<div class="refsect1">
<a name="gdk2-Threads.functions_details"></a><h2>Functions</h2>
<div class="refsect2">
<a name="GDK-THREADS-ENTER:CAPS"></a><h3>GDK_THREADS_ENTER</h3>
<pre class="programlisting">#define GDK_THREADS_ENTER()</pre>
</div>
<hr>
<div class="refsect2">
<a name="GDK-THREADS-LEAVE:CAPS"></a><h3>GDK_THREADS_LEAVE</h3>
<pre class="programlisting">#define GDK_THREADS_LEAVE()</pre>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-init"></a><h3>gdk_threads_init ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
gdk_threads_init (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>Initializes GDK so that it can be used from multiple threads
in conjunction with <a class="link" href="gdk2-Threads.html#gdk-threads-enter" title="gdk_threads_enter ()"><code class="function">gdk_threads_enter()</code></a> and <a class="link" href="gdk2-Threads.html#gdk-threads-leave" title="gdk_threads_leave ()"><code class="function">gdk_threads_leave()</code></a>.
<code class="function">g_thread_init()</code> must be called previous to this function.</p>
<p>This call must be made before any use of the main loop from
GTK+; to be safe, call it before <a href="https://developer.gnome.org/gtk4/gtk4-General.html#gtk-init"><code class="function">gtk_init()</code></a>.</p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-enter"></a><h3>gdk_threads_enter ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
gdk_threads_enter (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-leave"></a><h3>gdk_threads_leave ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
gdk_threads_leave (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-set-lock-functions"></a><h3>gdk_threads_set_lock_functions ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>
gdk_threads_set_lock_functions (<em class="parameter"><code><span class="type">GCallback</span> enter_fn</code></em>,
<em class="parameter"><code><span class="type">GCallback</span> leave_fn</code></em>);</pre>
<p>Allows the application to replace the standard method that
GDK uses to protect its data structures. Normally, GDK
creates a single <span class="type">GMutex</span> that is locked by <a class="link" href="gdk2-Threads.html#gdk-threads-enter" title="gdk_threads_enter ()"><code class="function">gdk_threads_enter()</code></a>,
and released by <a class="link" href="gdk2-Threads.html#gdk-threads-leave" title="gdk_threads_leave ()"><code class="function">gdk_threads_leave()</code></a>; using this function an
application provides, instead, a function <em class="parameter"><code>enter_fn</code></em>
that is
called by <a class="link" href="gdk2-Threads.html#gdk-threads-enter" title="gdk_threads_enter ()"><code class="function">gdk_threads_enter()</code></a> and a function <em class="parameter"><code>leave_fn</code></em>
that is
called by <a class="link" href="gdk2-Threads.html#gdk-threads-leave" title="gdk_threads_leave ()"><code class="function">gdk_threads_leave()</code></a>.</p>
<p>The functions must provide at least same locking functionality
as the default implementation, but can also do extra application
specific processing.</p>
<p>As an example, consider an application that has its own recursive
lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
the GTK+ lock when entering a recursive main loop, the application
must temporarily release its lock as well.</p>
<p>Most threaded GTK+ apps won't need to use this method.</p>
<p>This method must be called before <a class="link" href="gdk2-Threads.html#gdk-threads-init" title="gdk_threads_init ()"><code class="function">gdk_threads_init()</code></a>, and cannot
be called multiple times.</p>
<div class="refsect3">
<a name="gdk-threads-set-lock-functions.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>enter_fn</p></td>
<td class="parameter_description"><p>function called to guard GDK</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>leave_fn</p></td>
<td class="parameter_description"><p>function called to release the guard</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<p class="since">Since: <a class="link" href="api-index-2-4.html#api-index-2.4">2.4</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-idle"></a><h3>gdk_threads_add_idle ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_idle (<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>);</pre>
<p>A wrapper for the common usage of <a class="link" href="gdk2-Threads.html#gdk-threads-add-idle-full" title="gdk_threads_add_idle_full ()"><code class="function">gdk_threads_add_idle_full()</code></a>
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT_IDLE</span>.</p>
<p>See <a class="link" href="gdk2-Threads.html#gdk-threads-add-idle-full" title="gdk_threads_add_idle_full ()"><code class="function">gdk_threads_add_idle_full()</code></a>.</p>
<div class="refsect3">
<a name="gdk-threads-add-idle.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-idle.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-12.html#api-index-2.12">2.12</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-idle-full"></a><h3>gdk_threads_add_idle_full ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_idle_full (<em class="parameter"><code><span class="type">gint</span> priority</code></em>,
<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>,
<em class="parameter"><code><span class="type">GDestroyNotify</span> notify</code></em>);</pre>
<p>Adds a function to be called whenever there are no higher priority
events pending. If the function returns <code class="literal">FALSE</code> it is automatically
removed from the list of event sources and will not be called again.</p>
<p>This variant of <code class="function">g_idle_add_full()</code> calls <em class="parameter"><code>function</code></em>
with the GDK lock
held. It can be thought of a MT-safe version for GTK+ widgets for the
following use case, where you have to worry about <code class="function">idle_callback()</code>
running in thread A and accessing <em class="parameter"><code>self</code></em>
after it has been finalized
in thread B:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="k">static</span> <span class="n">gboolean</span>
<span class="nf">idle_callback</span> <span class="p">(</span><span class="n">gpointer</span> <span class="n">data</span><span class="p">)</span>
<span class="p">{</span>
<span class="cm">/* gdk_threads_enter(); would be needed for g_idle_add() */</span>
<span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">data</span><span class="p">;</span>
<span class="cm">/* do stuff with self */</span>
<span class="n">self</span><span class="o">-></span><span class="n">idle_id</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="cm">/* gdk_threads_leave(); would be needed for g_idle_add() */</span>
<span class="k">return</span> <span class="n">FALSE</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">static</span> <span class="kt">void</span>
<span class="nf">some_widget_do_stuff_later</span> <span class="p">(</span><span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">self</span><span class="o">-></span><span class="n">idle_id</span> <span class="o">=</span> <span class="n">gdk_threads_add_idle</span> <span class="p">(</span><span class="n">idle_callback</span><span class="p">,</span> <span class="n">self</span><span class="p">)</span>
<span class="cm">/* using g_idle_add() here would require thread protection in the callback */</span>
<span class="p">}</span>
<span class="k">static</span> <span class="kt">void</span>
<span class="nf">some_widget_finalize</span> <span class="p">(</span><span class="n">GObject</span> <span class="o">*</span><span class="n">object</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">SOME_WIDGET</span> <span class="p">(</span><span class="n">object</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">self</span><span class="o">-></span><span class="n">idle_id</span><span class="p">)</span>
<span class="n">g_source_remove</span> <span class="p">(</span><span class="n">self</span><span class="o">-></span><span class="n">idle_id</span><span class="p">);</span>
<span class="n">G_OBJECT_CLASS</span> <span class="p">(</span><span class="n">parent_class</span><span class="p">)</span><span class="o">-></span><span class="n">finalize</span> <span class="p">(</span><span class="n">object</span><span class="p">);</span>
<span class="p">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<div class="refsect3">
<a name="gdk-threads-add-idle-full.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description"><p>the priority of the idle source. Typically this will be in the
range btweeen <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>notify</p></td>
<td class="parameter_description"><p>function to call when the idle is removed, or <code class="literal">NULL</code>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-idle-full.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-12.html#api-index-2.12">2.12</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-timeout"></a><h3>gdk_threads_add_timeout ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_timeout (<em class="parameter"><code><span class="type">guint</span> interval</code></em>,
<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>);</pre>
<p>A wrapper for the common usage of <a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-full" title="gdk_threads_add_timeout_full ()"><code class="function">gdk_threads_add_timeout_full()</code></a>
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT</span>.</p>
<p>See <a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-full" title="gdk_threads_add_timeout_full ()"><code class="function">gdk_threads_add_timeout_full()</code></a>.</p>
<div class="refsect3">
<a name="gdk-threads-add-timeout.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>interval</p></td>
<td class="parameter_description"><p>the time between calls to the function, in milliseconds
(1/1000ths of a second)</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-timeout.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-12.html#api-index-2.12">2.12</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-timeout-full"></a><h3>gdk_threads_add_timeout_full ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_timeout_full (<em class="parameter"><code><span class="type">gint</span> priority</code></em>,
<em class="parameter"><code><span class="type">guint</span> interval</code></em>,
<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>,
<em class="parameter"><code><span class="type">GDestroyNotify</span> notify</code></em>);</pre>
<p>Sets a function to be called at regular intervals holding the GDK lock,
with the given priority. The function is called repeatedly until it
returns <code class="literal">FALSE</code>, at which point the timeout is automatically destroyed
and the function will not be called again. The <em class="parameter"><code>notify</code></em>
function is
called when the timeout is destroyed. The first call to the
function will be at the end of the first <em class="parameter"><code>interval</code></em>
.</p>
<p>Note that timeout functions may be delayed, due to the processing of other
event sources. Thus they should not be relied on for precise timing.
After each call to the timeout function, the time of the next
timeout is recalculated based on the current time and the given interval
(it does not try to 'catch up' time lost in delays).</p>
<p>This variant of <code class="function">g_timeout_add_full()</code> can be thought of a MT-safe version
for GTK+ widgets for the following use case:</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="k">static</span> <span class="n">gboolean</span> <span class="nf">timeout_callback</span> <span class="p">(</span><span class="n">gpointer</span> <span class="n">data</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">data</span><span class="p">;</span>
<span class="cm">/* do stuff with self */</span>
<span class="n">self</span><span class="o">-></span><span class="n">timeout_id</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">return</span> <span class="n">FALSE</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">static</span> <span class="kt">void</span> <span class="nf">some_widget_do_stuff_later</span> <span class="p">(</span><span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">self</span><span class="o">-></span><span class="n">timeout_id</span> <span class="o">=</span> <span class="n">g_timeout_add</span> <span class="p">(</span><span class="n">timeout_callback</span><span class="p">,</span> <span class="n">self</span><span class="p">)</span>
<span class="p">}</span>
<span class="k">static</span> <span class="kt">void</span> <span class="nf">some_widget_finalize</span> <span class="p">(</span><span class="n">GObject</span> <span class="o">*</span><span class="n">object</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">SomeWidget</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">SOME_WIDGET</span> <span class="p">(</span><span class="n">object</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">self</span><span class="o">-></span><span class="n">timeout_id</span><span class="p">)</span>
<span class="n">g_source_remove</span> <span class="p">(</span><span class="n">self</span><span class="o">-></span><span class="n">timeout_id</span><span class="p">);</span>
<span class="n">G_OBJECT_CLASS</span> <span class="p">(</span><span class="n">parent_class</span><span class="p">)</span><span class="o">-></span><span class="n">finalize</span> <span class="p">(</span><span class="n">object</span><span class="p">);</span>
<span class="p">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p></p>
<div class="refsect3">
<a name="gdk-threads-add-timeout-full.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description"><p>the priority of the timeout source. Typically this will be in the
range between <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>interval</p></td>
<td class="parameter_description"><p>the time between calls to the function, in milliseconds
(1/1000ths of a second)</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>notify</p></td>
<td class="parameter_description"><p>function to call when the timeout is removed, or <code class="literal">NULL</code>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-timeout-full.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-12.html#api-index-2.12">2.12</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-timeout-seconds"></a><h3>gdk_threads_add_timeout_seconds ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_timeout_seconds (<em class="parameter"><code><span class="type">guint</span> interval</code></em>,
<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>);</pre>
<p>A wrapper for the common usage of <a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-seconds-full" title="gdk_threads_add_timeout_seconds_full ()"><code class="function">gdk_threads_add_timeout_seconds_full()</code></a>
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT</span>.</p>
<p>For details, see <a class="link" href="gdk2-Threads.html#gdk-threads-add-timeout-full" title="gdk_threads_add_timeout_full ()"><code class="function">gdk_threads_add_timeout_full()</code></a>.</p>
<div class="refsect3">
<a name="gdk-threads-add-timeout-seconds.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>interval</p></td>
<td class="parameter_description"><p>the time between calls to the function, in seconds</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-timeout-seconds.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-14.html#api-index-2.14">2.14</a></p>
</div>
<hr>
<div class="refsect2">
<a name="gdk-threads-add-timeout-seconds-full"></a><h3>gdk_threads_add_timeout_seconds_full ()</h3>
<pre class="programlisting"><span class="returnvalue">guint</span>
gdk_threads_add_timeout_seconds_full (<em class="parameter"><code><span class="type">gint</span> priority</code></em>,
<em class="parameter"><code><span class="type">guint</span> interval</code></em>,
<em class="parameter"><code><span class="type">GSourceFunc</span> function</code></em>,
<em class="parameter"><code><span class="type">gpointer</span> data</code></em>,
<em class="parameter"><code><span class="type">GDestroyNotify</span> notify</code></em>);</pre>
<p>A variant of <code class="function">gdk_threads_add_timout_full()</code> with second-granularity.
See <code class="function">g_timeout_add_seconds_full()</code> for a discussion of why it is
a good idea to use this function if you don't need finer granularity.</p>
<div class="refsect3">
<a name="gdk-threads-add-timeout-seconds-full.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>priority</p></td>
<td class="parameter_description"><p>the priority of the timeout source. Typically this will be in the
range between <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>interval</p></td>
<td class="parameter_description"><p>the time between calls to the function, in seconds</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>function</p></td>
<td class="parameter_description"><p>function to call</p></td>
<td class="parameter_annotations"> </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></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>notify</p></td>
<td class="parameter_description"><p>function to call when the timeout is removed, or <code class="literal">NULL</code>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="gdk-threads-add-timeout-seconds-full.returns"></a><h4>Returns</h4>
<p> the ID (greater than 0) of the event source.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-14.html#api-index-2.14">2.14</a></p>
</div>
</div>
<div class="refsect1">
<a name="gdk2-Threads.other_details"></a><h2>Types and Values</h2>
<div class="refsect2">
<a name="gdk-threads-mutex"></a><h3>gdk_threads_mutex</h3>
<pre class="programlisting">extern GMutex *gdk_threads_mutex; /* private */
</pre>
<div class="warning"><p><code class="literal">gdk_threads_mutex</code> is deprecated and should not be used in newly-written code.</p></div>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.0</div>
</body>
</html>
|