1
/* Async Jitter Queue based on g_async_queue
3
* Farsight Voice+Video library
4
* Copyright 2007 Collabora Ltd,
5
* Copyright 2007 Nokia Corporation
6
* @author: Philippe Khalaf <philippe.khalaf@collabora.co.uk>.
9
/* GLIB - Library of useful routines for C programming
10
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
12
* This library is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU Lesser General Public
14
* License as published by the Free Software Foundation; either
15
* version 2 of the License, or (at your option) any later version.
17
* This library is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
* Lesser General Public License for more details.
22
* You should have received a copy of the GNU Lesser General Public
23
* License along with this library; if not, write to the
24
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25
* Boston, MA 02111-1307, USA.
29
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
30
* file for a list of people on the GLib Team. See the ChangeLog
31
* files for a list of changes. These files are distributed with
32
* GLib at ftp://ftp.gtk.org/pub/gtk/.
35
#ifndef __ASYNCJITTERQUEUE_H__
36
#define __ASYNCJITTERQUEUE_H__
39
#include <glib/gthread.h>
43
typedef struct _AsyncJitterQueue AsyncJitterQueue;
45
/* Asyncronous Queues, can be used to communicate between threads
48
/* Get a new AsyncJitterQueue with the ref_count 1 */
49
AsyncJitterQueue* async_jitter_queue_new (void);
51
/* Lock and unlock a AsyncJitterQueue. All functions lock the queue for
52
* themselves, but in certain cirumstances you want to hold the lock longer,
53
* thus you lock the queue, call the *_unlocked functions and unlock it again.
55
void async_jitter_queue_lock (AsyncJitterQueue *queue);
56
void async_jitter_queue_unlock (AsyncJitterQueue *queue);
58
/* Ref and unref the AsyncJitterQueue. */
59
AsyncJitterQueue* async_jitter_queue_ref (AsyncJitterQueue *queue);
60
void async_jitter_queue_unref (AsyncJitterQueue *queue);
61
#ifndef G_DISABLE_DEPRECATED
62
/* You don't have to hold the lock for calling *_ref and *_unref anymore. */
63
void async_jitter_queue_ref_unlocked (AsyncJitterQueue *queue);
64
void async_jitter_queue_unref_and_unlock (AsyncJitterQueue *queue);
65
#endif /* !G_DISABLE_DEPRECATED */
67
void async_jitter_queue_set_low_threshold (AsyncJitterQueue *queue,
69
void async_jitter_queue_set_high_threshold (AsyncJitterQueue *queue,
72
void async_jitter_queue_set_max_queue_length (AsyncJitterQueue *queue,
75
/* Push data into the async queue. Must not be NULL. */
76
void async_jitter_queue_push (AsyncJitterQueue *queue,
78
void async_jitter_queue_push_unlocked (AsyncJitterQueue *queue,
80
gboolean async_jitter_queue_push_sorted (AsyncJitterQueue *queue,
82
GCompareDataFunc func,
85
void async_jitter_queue_insert_after_unlocked(AsyncJitterQueue *queue,
89
gboolean async_jitter_queue_push_sorted_unlocked(AsyncJitterQueue *queue,
91
GCompareDataFunc func,
94
/* Pop data from the async queue. When no data is there, the thread is blocked
95
* until data arrives. */
96
gpointer async_jitter_queue_pop (AsyncJitterQueue *queue);
97
gpointer async_jitter_queue_pop_unlocked (AsyncJitterQueue *queue);
99
/* Try to pop data. NULL is returned in case of empty queue. */
100
gpointer async_jitter_queue_try_pop (AsyncJitterQueue *queue);
101
gpointer async_jitter_queue_try_pop_unlocked (AsyncJitterQueue *queue);
103
/* Wait for data until at maximum until end_time is reached. NULL is returned
104
* in case of empty queue. */
105
gpointer async_jitter_queue_timed_pop (AsyncJitterQueue *queue,
107
gpointer async_jitter_queue_timed_pop_unlocked (AsyncJitterQueue *queue,
110
/* Return the length of the queue. Negative values mean that threads
111
* are waiting, positve values mean that there are entries in the
112
* queue. Actually this function returns the length of the queue minus
113
* the number of waiting threads, async_jitter_queue_length == 0 could also
114
* mean 'n' entries in the queue and 'n' thread waiting. Such can
115
* happen due to locking of the queue or due to scheduling. */
116
gint async_jitter_queue_length (AsyncJitterQueue *queue);
117
gint async_jitter_queue_length_unlocked (AsyncJitterQueue *queue);
119
void async_jitter_queue_set_flushing_unlocked (AsyncJitterQueue* queue,
120
GFunc free_func, gpointer user_data);
121
void async_jitter_queue_unset_flushing_unlocked (AsyncJitterQueue* queue);
122
void async_jitter_queue_set_blocking_unlocked (AsyncJitterQueue* queue,
125
async_jitter_queue_length_ts_units_unlocked (AsyncJitterQueue *queue);
129
#endif /* __ASYNCJITTERQUEUE_H__ */