mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-25 06:59:52 -05:00
add two new macros PA_ONCE_BEGIN and PA_ONCE_END which allow usage of pa_once without declaring a function to be called
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1820 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
04ed0f9536
commit
bf274cb617
2 changed files with 65 additions and 20 deletions
|
|
@ -39,8 +39,38 @@ typedef struct pa_once {
|
|||
.done = PA_ATOMIC_INIT(0) \
|
||||
}
|
||||
|
||||
typedef void (*pa_once_func_t) (void);
|
||||
/* Not to be called directly, use the macros defined below instead */
|
||||
int pa_once_begin(pa_once *o);
|
||||
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() {
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue