gmain: use Linux eventfd() for main context wake up
[glib.git] / glib / gasyncqueue.h
blob9da43e36da0c43b82a7ea8dc5b9e74cf56eca3d8
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
31 #ifndef __G_ASYNCQUEUE_H__
32 #define __G_ASYNCQUEUE_H__
34 #include <glib/gthread.h>
36 G_BEGIN_DECLS
38 typedef struct _GAsyncQueue GAsyncQueue;
40 /* Asyncronous Queues, can be used to communicate between threads */
42 /* Get a new GAsyncQueue with the ref_count 1 */
43 GAsyncQueue* g_async_queue_new (void);
45 GAsyncQueue* g_async_queue_new_full (GDestroyNotify item_free_func);
47 /* Lock and unlock a GAsyncQueue. All functions lock the queue for
48 * themselves, but in certain cirumstances you want to hold the lock longer,
49 * thus you lock the queue, call the *_unlocked functions and unlock it again.
51 void g_async_queue_lock (GAsyncQueue *queue);
52 void g_async_queue_unlock (GAsyncQueue *queue);
54 /* Ref and unref the GAsyncQueue. */
55 GAsyncQueue* g_async_queue_ref (GAsyncQueue *queue);
56 void g_async_queue_unref (GAsyncQueue *queue);
58 #ifndef G_DISABLE_DEPRECATED
59 /* You don't have to hold the lock for calling *_ref and *_unref anymore. */
60 void g_async_queue_ref_unlocked (GAsyncQueue *queue);
61 void g_async_queue_unref_and_unlock (GAsyncQueue *queue);
62 #endif /* !G_DISABLE_DEPRECATED */
64 /* Push data into the async queue. Must not be NULL. */
65 void g_async_queue_push (GAsyncQueue *queue,
66 gpointer data);
67 void g_async_queue_push_unlocked (GAsyncQueue *queue,
68 gpointer data);
70 void g_async_queue_push_sorted (GAsyncQueue *queue,
71 gpointer data,
72 GCompareDataFunc func,
73 gpointer user_data);
74 void g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
75 gpointer data,
76 GCompareDataFunc func,
77 gpointer user_data);
79 /* Pop data from the async queue. When no data is there, the thread is blocked
80 * until data arrives.
82 gpointer g_async_queue_pop (GAsyncQueue *queue);
83 gpointer g_async_queue_pop_unlocked (GAsyncQueue *queue);
85 /* Try to pop data. NULL is returned in case of empty queue. */
86 gpointer g_async_queue_try_pop (GAsyncQueue *queue);
87 gpointer g_async_queue_try_pop_unlocked (GAsyncQueue *queue);
91 /* Wait for data until at maximum until end_time is reached. NULL is returned
92 * in case of empty queue.
94 gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
95 GTimeVal *end_time);
96 gpointer g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
97 GTimeVal *end_time);
99 /* Return the length of the queue. Negative values mean that threads
100 * are waiting, positve values mean that there are entries in the
101 * queue. Actually this function returns the length of the queue minus
102 * the number of waiting threads, g_async_queue_length == 0 could also
103 * mean 'n' entries in the queue and 'n' thread waiting. Such can
104 * happen due to locking of the queue or due to scheduling.
106 gint g_async_queue_length (GAsyncQueue *queue);
107 gint g_async_queue_length_unlocked (GAsyncQueue *queue);
108 void g_async_queue_sort (GAsyncQueue *queue,
109 GCompareDataFunc func,
110 gpointer user_data);
111 void g_async_queue_sort_unlocked (GAsyncQueue *queue,
112 GCompareDataFunc func,
113 gpointer user_data);
115 /* Private API */
116 GMutex* _g_async_queue_get_mutex (GAsyncQueue *queue);
118 G_END_DECLS
120 #endif /* __G_ASYNCQUEUE_H__ */