2 This file is part of PulseAudio.
4 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/xmalloc.h>
29 #include <pulsecore/hashmap.h>
34 CRITICAL_SECTION mutex;
38 pa_hashmap *wait_events;
41 pa_mutex* pa_mutex_new(pa_bool_t recursive, pa_bool_t inherit_priority) {
44 m = pa_xnew(pa_mutex, 1);
46 InitializeCriticalSection(&m->mutex);
51 void pa_mutex_free(pa_mutex *m) {
54 DeleteCriticalSection(&m->mutex);
58 void pa_mutex_lock(pa_mutex *m) {
61 EnterCriticalSection(&m->mutex);
64 void pa_mutex_unlock(pa_mutex *m) {
67 LeaveCriticalSection(&m->mutex);
70 pa_cond *pa_cond_new(void) {
73 c = pa_xnew(pa_cond, 1);
74 c->wait_events = pa_hashmap_new(NULL, NULL);
75 assert(c->wait_events);
80 void pa_cond_free(pa_cond *c) {
83 pa_hashmap_free(c->wait_events, NULL, NULL);
87 void pa_cond_signal(pa_cond *c, int broadcast) {
90 if (pa_hashmap_size(c->wait_events) == 0)
94 SetEvent(pa_hashmap_get_first(c->wait_events));
102 pa_hashmap_iterate(c->wait_events, &iter, &key);
105 event = (HANDLE)pa_hashmap_get(c->wait_events, key);
111 int pa_cond_wait(pa_cond *c, pa_mutex *m) {
117 event = CreateEvent(NULL, FALSE, FALSE, NULL);
120 pa_hashmap_put(c->wait_events, event, event);
124 WaitForSingleObject(event, INFINITE);
128 pa_hashmap_remove(c->wait_events, event);