зеркало из https://github.com/mozilla/gecko-dev.git
Bug 185687: added PR_CallOnceWithArg, a version of PR_CallOnce that allows
the callers to pass an argument to the call-once function. Modified files: prinit.h nspr.def prinit.c
This commit is contained in:
Родитель
65a9359e6e
Коммит
0b4f800fbf
|
@ -220,11 +220,19 @@ typedef struct PRCallOnceType {
|
|||
|
||||
typedef PRStatus (PR_CALLBACK *PRCallOnceFN)(void);
|
||||
|
||||
typedef PRStatus (PR_CALLBACK *PRCallOnceWithArgFN)(void *arg);
|
||||
|
||||
NSPR_API(PRStatus) PR_CallOnce(
|
||||
PRCallOnceType *once,
|
||||
PRCallOnceFN func
|
||||
);
|
||||
|
||||
NSPR_API(PRStatus) PR_CallOnceWithArg(
|
||||
PRCallOnceType *once,
|
||||
PRCallOnceWithArgFN func,
|
||||
void *arg
|
||||
);
|
||||
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
|
|
|
@ -819,6 +819,31 @@ PR_IMPLEMENT(PRStatus) PR_CallOnce(
|
|||
return once->status;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRStatus) PR_CallOnceWithArg(
|
||||
PRCallOnceType *once,
|
||||
PRCallOnceWithArgFN func,
|
||||
void *arg)
|
||||
{
|
||||
if (!_pr_initialized) _PR_ImplicitInitialization();
|
||||
|
||||
if (!once->initialized) {
|
||||
if (PR_AtomicSet(&once->inProgress, 1) == 0) {
|
||||
once->status = (*func)(arg);
|
||||
PR_Lock(mod_init.ml);
|
||||
once->initialized = 1;
|
||||
PR_NotifyAllCondVar(mod_init.cv);
|
||||
PR_Unlock(mod_init.ml);
|
||||
} else {
|
||||
PR_Lock(mod_init.ml);
|
||||
while (!once->initialized) {
|
||||
PR_WaitCondVar(mod_init.cv, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
PR_Unlock(mod_init.ml);
|
||||
}
|
||||
}
|
||||
return once->status;
|
||||
}
|
||||
|
||||
PRBool _PR_Obsolete(const char *obsolete, const char *preferred)
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
|
|
|
@ -392,5 +392,6 @@ NSPR_4.1 {
|
|||
|
||||
NSPR_4.3 {
|
||||
global:
|
||||
PR_CallOnceWithArg;
|
||||
PR_GetLibraryFilePathname;
|
||||
} NSPR_4.1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче