gasyncqueue.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #ifndef __G_ASYNCQUEUE_H__
00028 #define __G_ASYNCQUEUE_H__
00029 
00030 #include <gthread.h>
00031 
00032 G_BEGIN_DECLS
00033 
00034 typedef struct _GAsyncQueue     GAsyncQueue;
00035 
00036 /* Asyncronous Queues, can be used to communicate between threads
00037  */
00038 
00039 /* Get a new GAsyncQueue with the ref_count 1 */
00040 GAsyncQueue*  g_async_queue_new                (void);
00041 
00042 /* Lock and unlock an GAsyncQueue, all functions lock the queue for
00043  * themselves, but in certain cirumstances you want to hold the lock longer,
00044  * thus you lock the queue, call the *_unlocked functions and unlock it again
00045  */
00046 void          g_async_queue_lock               (GAsyncQueue *queue);
00047 void          g_async_queue_unlock             (GAsyncQueue *queue);
00048 
00049 /* Ref and unref the GAsyncQueue. g_async_queue_unref_unlocked makes
00050  * no sense, as after the unreffing the Queue might be gone and can't
00051  * be unlocked. So you have a function to call, if you don't hold the
00052  * lock (g_async_queue_unref) and one to call, when you already hold
00053  * the lock (g_async_queue_unref_and_unlock). After that however, you
00054  * don't hold the lock anymore and the Queue might in fact be
00055  * destroyed, if you unrefed to zero */
00056 void          g_async_queue_ref                (GAsyncQueue *queue);
00057 void          g_async_queue_ref_unlocked       (GAsyncQueue *queue);
00058 void          g_async_queue_unref              (GAsyncQueue *queue);
00059 void          g_async_queue_unref_and_unlock   (GAsyncQueue *queue);
00060 
00061 /* Push data into the async queue. Must not be NULL */
00062 void          g_async_queue_push               (GAsyncQueue *queue,
00063                                                 gpointer     data);
00064 void          g_async_queue_push_unlocked      (GAsyncQueue *queue,
00065                                                 gpointer     data);
00066 
00067 /* Pop data from the async queue, when no data is there, the thread is blocked
00068  * until data arrives */
00069 gpointer      g_async_queue_pop                (GAsyncQueue *queue);
00070 gpointer      g_async_queue_pop_unlocked       (GAsyncQueue *queue);
00071 
00072 /* Try to pop data, NULL is returned in case of empty queue */
00073 gpointer      g_async_queue_try_pop            (GAsyncQueue *queue);
00074 gpointer      g_async_queue_try_pop_unlocked   (GAsyncQueue *queue);
00075 
00076 /* Wait for data until at maximum until end_time is reached, NULL is returned
00077  * in case of empty queue*/
00078 gpointer      g_async_queue_timed_pop          (GAsyncQueue *queue,
00079                                                 GTimeVal    *end_time);
00080 gpointer      g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
00081                                                 GTimeVal    *end_time);
00082 
00083 /* Return the length of the queue, negative values mean, that threads
00084  * are waiting, positve values mean, that there are entries in the
00085  * queue. Actually this function returns the length of the queue minus
00086  * the number of waiting threads, g_async_queue_length == 0 could also
00087  * mean 'n' entries in the queue and 'n' thread waiting, such can
00088  * happen due to locking of the queue or due to scheduling. */
00089 gint          g_async_queue_length             (GAsyncQueue *queue);
00090 gint          g_async_queue_length_unlocked    (GAsyncQueue *queue);
00091 
00092 G_END_DECLS
00093 
00094 #endif /* __G_ASYNCQUEUE_H__ */
00095 

Generated on Tue Jul 5 14:14:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1