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  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 /*
00022  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00023  * file for a list of people on the GLib Team.  See the ChangeLog
00024  * files for a list of changes.  These files are distributed with
00025  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00026  */
00027 
00028 #ifndef __G_ASYNCQUEUE_H__
00029 #define __G_ASYNCQUEUE_H__
00030 
00031 #include <_ansi.h>
00032 #include <glib/gthread.h>
00033 
00034 G_BEGIN_DECLS
00035 
00036 typedef struct _GAsyncQueue GAsyncQueue;
00037 
00038 /* Asyncronous Queues, can be used to communicate between threads */
00039 
00040 /* Get a new GAsyncQueue with the ref_count 1 */
00041 IMPORT_C GAsyncQueue*  g_async_queue_new                (void);
00042 
00043 /* Lock and unlock a GAsyncQueue. All functions lock the queue for
00044  * themselves, but in certain cirumstances you want to hold the lock longer,
00045  * thus you lock the queue, call the *_unlocked functions and unlock it again.
00046  */
00047 IMPORT_C void          g_async_queue_lock               (GAsyncQueue *queue);
00048 IMPORT_C void          g_async_queue_unlock             (GAsyncQueue *queue);
00049 
00050 /* Ref and unref the GAsyncQueue. */
00051 IMPORT_C GAsyncQueue*  g_async_queue_ref                (GAsyncQueue *queue);
00052 IMPORT_C void          g_async_queue_unref              (GAsyncQueue *queue);
00053 
00054 #ifndef G_DISABLE_DEPRECATED
00055 /* You don't have to hold the lock for calling *_ref and *_unref anymore. */
00056 IMPORT_C void          g_async_queue_ref_unlocked       (GAsyncQueue *queue);
00057 IMPORT_C void          g_async_queue_unref_and_unlock   (GAsyncQueue *queue);
00058 #endif /* !G_DISABLE_DEPRECATED */
00059 
00060 /* Push data into the async queue. Must not be NULL. */
00061 IMPORT_C void          g_async_queue_push               (GAsyncQueue *queue,
00062                                                  gpointer          data);
00063 IMPORT_C void          g_async_queue_push_unlocked      (GAsyncQueue *queue,
00064                                                  gpointer          data);
00065 
00066 IMPORT_C void         g_async_queue_push_sorted          (GAsyncQueue      *queue,
00067                                                  gpointer          data,
00068                                                  GCompareDataFunc  func,
00069                                                  gpointer          user_data);
00070 IMPORT_C void         g_async_queue_push_sorted_unlocked (GAsyncQueue      *queue,
00071                                                  gpointer          data,
00072                                                  GCompareDataFunc  func,
00073                                                  gpointer          user_data);
00074 
00075 /* Pop data from the async queue. When no data is there, the thread is blocked
00076  * until data arrives.
00077  */
00078 IMPORT_C gpointer      g_async_queue_pop                (GAsyncQueue *queue);
00079 IMPORT_C gpointer      g_async_queue_pop_unlocked       (GAsyncQueue *queue);
00080 
00081 /* Try to pop data. NULL is returned in case of empty queue. */
00082 IMPORT_C gpointer      g_async_queue_try_pop            (GAsyncQueue *queue);
00083 IMPORT_C gpointer      g_async_queue_try_pop_unlocked   (GAsyncQueue *queue);
00084 
00085 
00086 
00087 /* Wait for data until at maximum until end_time is reached. NULL is returned
00088  * in case of empty queue. 
00089  */
00090 IMPORT_C gpointer      g_async_queue_timed_pop          (GAsyncQueue *queue,
00091                                                  GTimeVal         *end_time);
00092 IMPORT_C gpointer      g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
00093                                                  GTimeVal         *end_time);
00094 
00095 /* Return the length of the queue. Negative values mean that threads
00096  * are waiting, positve values mean that there are entries in the
00097  * queue. Actually this function returns the length of the queue minus
00098  * the number of waiting threads, g_async_queue_length == 0 could also
00099  * mean 'n' entries in the queue and 'n' thread waiting. Such can
00100  * happen due to locking of the queue or due to scheduling. 
00101  */
00102 IMPORT_C gint          g_async_queue_length             (GAsyncQueue *queue);
00103 IMPORT_C gint          g_async_queue_length_unlocked    (GAsyncQueue *queue);
00104 IMPORT_C void         g_async_queue_sort                 (GAsyncQueue      *queue,
00105                                                  GCompareDataFunc  func,
00106                                                  gpointer          user_data);
00107 IMPORT_C void         g_async_queue_sort_unlocked        (GAsyncQueue      *queue,
00108                                                  GCompareDataFunc  func,
00109                                                  gpointer          user_data);
00110 
00111 /* Private API */
00112 GMutex*      _g_async_queue_get_mutex           (GAsyncQueue      *queue);
00113 
00114 G_END_DECLS
00115 
00116 #endif /* __G_ASYNCQUEUE_H__ */
00117 

Copyright © Nokia Corporation 2001-2008
Back to top