4 This file is part of PulseAudio.
6 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
31 #include <pulsecore/hashmap.h>
36 CRITICAL_SECTION mutex
;
40 pa_hashmap
*wait_events
;
43 pa_mutex
* pa_mutex_new(pa_bool_t recursive
, pa_bool_t inherit_priority
) {
46 m
= pa_xnew(pa_mutex
, 1);
48 InitializeCriticalSection(&m
->mutex
);
53 void pa_mutex_free(pa_mutex
*m
) {
56 DeleteCriticalSection(&m
->mutex
);
60 void pa_mutex_lock(pa_mutex
*m
) {
63 EnterCriticalSection(&m
->mutex
);
66 void pa_mutex_unlock(pa_mutex
*m
) {
69 LeaveCriticalSection(&m
->mutex
);
72 pa_cond
*pa_cond_new(void) {
75 c
= pa_xnew(pa_cond
, 1);
76 c
->wait_events
= pa_hashmap_new(NULL
, NULL
);
77 assert(c
->wait_events
);
82 void pa_cond_free(pa_cond
*c
) {
85 pa_hashmap_free(c
->wait_events
, NULL
, NULL
);
89 void pa_cond_signal(pa_cond
*c
, int broadcast
) {
92 if (pa_hashmap_size(c
->wait_events
) == 0)
96 SetEvent(pa_hashmap_get_first(c
->wait_events
));
104 pa_hashmap_iterate(c
->wait_events
, &iter
, &key
);
107 event
= (HANDLE
)pa_hashmap_get(c
->wait_events
, key
);
113 int pa_cond_wait(pa_cond
*c
, pa_mutex
*m
) {
119 event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
122 pa_hashmap_put(c
->wait_events
, event
, event
);
126 WaitForSingleObject(event
, INFINITE
);
130 pa_hashmap_remove(c
->wait_events
, event
);