Add g_key_file_load_from_dirs for looking through a search path for a
[platform/upstream/glib.git] / glib / gasyncqueue.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #ifndef __G_ASYNCQUEUE_H__
28 #define __G_ASYNCQUEUE_H__
29
30 #include <glib/gthread.h>
31
32 G_BEGIN_DECLS
33
34 typedef struct _GAsyncQueue GAsyncQueue;
35
36 /* Asyncronous Queues, can be used to communicate between threads */
37
38 /* Get a new GAsyncQueue with the ref_count 1 */
39 GAsyncQueue*  g_async_queue_new                 (void);
40
41 /* Lock and unlock a GAsyncQueue. All functions lock the queue for
42  * themselves, but in certain cirumstances you want to hold the lock longer,
43  * thus you lock the queue, call the *_unlocked functions and unlock it again.
44  */
45 void         g_async_queue_lock                 (GAsyncQueue      *queue);
46 void         g_async_queue_unlock               (GAsyncQueue      *queue);
47
48 /* Ref and unref the GAsyncQueue. */
49 GAsyncQueue* g_async_queue_ref                  (GAsyncQueue      *queue);
50 void         g_async_queue_unref                (GAsyncQueue      *queue);
51
52 #ifndef G_DISABLE_DEPRECATED
53 /* You don't have to hold the lock for calling *_ref and *_unref anymore. */
54 void         g_async_queue_ref_unlocked         (GAsyncQueue      *queue);
55 void         g_async_queue_unref_and_unlock     (GAsyncQueue      *queue);
56 #endif /* !G_DISABLE_DEPRECATED */
57
58 /* Push data into the async queue. Must not be NULL. */
59 void         g_async_queue_push                 (GAsyncQueue      *queue,
60                                                  gpointer          data);
61 void         g_async_queue_push_unlocked        (GAsyncQueue      *queue,
62                                                  gpointer          data);
63
64 void         g_async_queue_push_sorted          (GAsyncQueue      *queue,
65                                                  gpointer          data,
66                                                  GCompareDataFunc  func,
67                                                  gpointer          user_data);
68 void         g_async_queue_push_sorted_unlocked (GAsyncQueue      *queue,
69                                                  gpointer          data,
70                                                  GCompareDataFunc  func,
71                                                  gpointer          user_data);
72
73 /* Pop data from the async queue. When no data is there, the thread is blocked
74  * until data arrives.
75  */
76 gpointer     g_async_queue_pop                  (GAsyncQueue      *queue);
77 gpointer     g_async_queue_pop_unlocked         (GAsyncQueue      *queue);
78
79 /* Try to pop data. NULL is returned in case of empty queue. */
80 gpointer     g_async_queue_try_pop              (GAsyncQueue      *queue);
81 gpointer     g_async_queue_try_pop_unlocked     (GAsyncQueue      *queue);
82
83
84
85 /* Wait for data until at maximum until end_time is reached. NULL is returned
86  * in case of empty queue. 
87  */
88 gpointer     g_async_queue_timed_pop            (GAsyncQueue      *queue,
89                                                  GTimeVal         *end_time);
90 gpointer     g_async_queue_timed_pop_unlocked   (GAsyncQueue      *queue,
91                                                  GTimeVal         *end_time);
92
93 /* Return the length of the queue. Negative values mean that threads
94  * are waiting, positve values mean that there are entries in the
95  * queue. Actually this function returns the length of the queue minus
96  * the number of waiting threads, g_async_queue_length == 0 could also
97  * mean 'n' entries in the queue and 'n' thread waiting. Such can
98  * happen due to locking of the queue or due to scheduling. 
99  */
100 gint         g_async_queue_length               (GAsyncQueue      *queue);
101 gint         g_async_queue_length_unlocked      (GAsyncQueue      *queue);
102 void         g_async_queue_sort                 (GAsyncQueue      *queue,
103                                                  GCompareDataFunc  func,
104                                                  gpointer          user_data);
105 void         g_async_queue_sort_unlocked        (GAsyncQueue      *queue,
106                                                  GCompareDataFunc  func,
107                                                  gpointer          user_data);
108
109 /* Private API */
110 GMutex*      _g_async_queue_get_mutex           (GAsyncQueue      *queue);
111
112 G_END_DECLS
113
114 #endif /* __G_ASYNCQUEUE_H__ */
115