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