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 #ifndef __G_ASYNCQUEUE_H__
28 #define __G_ASYNCQUEUE_H__
34 typedef struct _GAsyncQueue GAsyncQueue;
36 /* Asyncronous Queues, can be used to communicate between threads
39 /* Get a new GAsyncQueue with the ref_count 1 */
40 GAsyncQueue* g_async_queue_new (void);
42 /* Lock and unlock an GAsyncQueue, all functions lock the queue for
43 * themselves, but in certain cirumstances you want to hold the lock longer,
44 * thus you lock the queue, call the *_unlocked functions and unlock it again
46 void g_async_queue_lock (GAsyncQueue *queue);
47 void g_async_queue_unlock (GAsyncQueue *queue);
49 /* Ref and unref the GAsyncQueue. g_async_queue_unref_unlocked makes
50 * no sense, as after the unreffing the Queue might be gone and can't
51 * be unlocked. So you have a function to call, if you don't hold the
52 * lock (g_async_queue_unref) and one to call, when you already hold
53 * the lock (g_async_queue_unref_and_unlock). After that however, you
54 * don't hold the lock anymore and the Queue might in fact be
55 * destroyed, if you unrefed to zero */
56 void g_async_queue_ref (GAsyncQueue *queue);
57 void g_async_queue_ref_unlocked (GAsyncQueue *queue);
58 void g_async_queue_unref (GAsyncQueue *queue);
59 void g_async_queue_unref_and_unlock (GAsyncQueue *queue);
61 /* Push data into the async queue. Must not be NULL */
62 void g_async_queue_push (GAsyncQueue *queue,
64 void g_async_queue_push_unlocked (GAsyncQueue *queue,
67 /* Pop data from the async queue, when no data is there, the thread is blocked
68 * until data arrives */
69 gpointer g_async_queue_pop (GAsyncQueue *queue);
70 gpointer g_async_queue_pop_unlocked (GAsyncQueue *queue);
72 /* Try to pop data, NULL is returned in case of empty queue */
73 gpointer g_async_queue_try_pop (GAsyncQueue *queue);
74 gpointer g_async_queue_try_pop_unlocked (GAsyncQueue *queue);
76 /* Wait for data until at maximum until end_time is reached, NULL is returned
77 * in case of empty queue*/
78 gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
80 gpointer g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
83 /* Return the length of the queue, negative values mean, that threads
84 * are waiting, positve values mean, that there are entries in the
85 * queue. Actually this function returns the length of the queue minus
86 * the number of waiting threads, g_async_queue_length == 0 could also
87 * mean 'n' entries in the queue and 'n' thread waiting, such can
88 * happen due to locking of the queue or due to scheduling. */
89 gint g_async_queue_length (GAsyncQueue *queue);
90 gint g_async_queue_length_unlocked (GAsyncQueue *queue);
94 #endif /* __G_ASYNCQUEUE_H__ */