2006-09-09 22:55:51 +00:00
|
|
|
#ifndef foopulseoncehfoo
|
|
|
|
|
#define foopulseoncehfoo
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2006 Lennart Poettering
|
|
|
|
|
|
2006-09-09 22:55:51 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
2009-03-03 20:23:02 +00:00
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
2006-09-09 22:55:51 +00:00
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-09-09 22:55:51 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-09-09 22:55:51 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2014-11-26 14:14:51 +01:00
|
|
|
License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2006-09-09 22:55:51 +00:00
|
|
|
***/
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/atomic.h>
|
2012-05-18 22:29:41 +02:00
|
|
|
#include <pulsecore/mutex.h>
|
2006-09-09 22:55:51 +00:00
|
|
|
|
|
|
|
|
typedef struct pa_once {
|
2012-05-18 22:29:41 +02:00
|
|
|
pa_static_mutex mutex;
|
|
|
|
|
pa_atomic_t done;
|
2007-10-28 19:13:50 +00:00
|
|
|
} pa_once;
|
2006-09-09 22:55:51 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#define PA_ONCE_INIT \
|
|
|
|
|
{ \
|
2012-05-18 22:29:41 +02:00
|
|
|
.mutex = PA_STATIC_MUTEX_INIT, \
|
2007-10-28 19:13:50 +00:00
|
|
|
.done = PA_ATOMIC_INIT(0) \
|
|
|
|
|
}
|
2006-09-09 22:55:51 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
/* Not to be called directly, use the macros defined below instead */
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_once_begin(pa_once *o);
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa_once_end(pa_once *o);
|
|
|
|
|
|
|
|
|
|
#define PA_ONCE_BEGIN \
|
|
|
|
|
do { \
|
|
|
|
|
static pa_once _once = PA_ONCE_INIT; \
|
|
|
|
|
if (pa_once_begin(&_once)) {{
|
|
|
|
|
|
|
|
|
|
#define PA_ONCE_END \
|
|
|
|
|
} \
|
|
|
|
|
pa_once_end(&_once); \
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Usage of these macros is like this:
|
|
|
|
|
|
|
|
|
|
void foo() {
|
2006-09-09 22:55:51 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
PA_ONCE_BEGIN {
|
|
|
|
|
|
|
|
|
|
... stuff to be called just once ...
|
|
|
|
|
|
|
|
|
|
} PA_ONCE_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Same API but calls a function */
|
|
|
|
|
typedef void (*pa_once_func_t) (void);
|
|
|
|
|
void pa_run_once(pa_once *o, pa_once_func_t f);
|
2006-09-09 22:55:51 +00:00
|
|
|
|
|
|
|
|
#endif
|