]>
code.delx.au - pulseaudio/blob - src/pulsecore/once-win32.c
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
33 #include <pulsecore/mutex.h>
37 void pa_once(pa_once_t
*control
, pa_once_func_t func
) {
44 /* Create the global mutex */
45 sprintf(name
, "pulse%d", (int)GetCurrentProcessId());
47 mutex
= CreateMutex(NULL
, FALSE
, name
);
50 /* Create the local mutex */
51 WaitForSingleObject(mutex
, INFINITE
);
53 control
->mutex
= pa_mutex_new(1);
58 /* Execute function */
59 pa_mutex_lock(control
->mutex
);
60 if (!control
->once_value
) {
61 control
->once_value
= 1;
64 pa_mutex_unlock(control
->mutex
);
66 /* Caveat: We have to make sure that the once func has completed
67 * before returning, even if the once func is not actually
68 * executed by us. Hence the awkward locking. */