diff options
author | wtc%netscape.com <devnull@localhost> | 2003-01-20 20:13:09 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2003-01-20 20:13:09 +0000 |
commit | b3af7f8011858c28477bd93f9740d2d7b9b2cc6f (patch) | |
tree | 67f4e48f831f816de87fbdfbb04bc2834fd3ec77 | |
parent | 8a8687fd4ed58964231134923b07c8a6742d21c8 (diff) | |
download | nspr-hg-b3af7f8011858c28477bd93f9740d2d7b9b2cc6f.tar.gz |
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
Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rw-r--r-- | pr/include/prinit.h | 8 | ||||
-rw-r--r-- | pr/src/misc/prinit.c | 25 | ||||
-rw-r--r-- | pr/src/nspr.def | 1 |
3 files changed, 34 insertions, 0 deletions
diff --git a/pr/include/prinit.h b/pr/include/prinit.h index 050cb15e..ad2a6f1f 100644 --- a/pr/include/prinit.h +++ b/pr/include/prinit.h @@ -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 diff --git a/pr/src/misc/prinit.c b/pr/src/misc/prinit.c index cd55a9fb..04c92226 100644 --- a/pr/src/misc/prinit.c +++ b/pr/src/misc/prinit.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) diff --git a/pr/src/nspr.def b/pr/src/nspr.def index 75f3f890..aa1d8417 100644 --- a/pr/src/nspr.def +++ b/pr/src/nspr.def @@ -392,5 +392,6 @@ NSPR_4.1 { NSPR_4.3 { global: + PR_CallOnceWithArg; PR_GetLibraryFilePathname; } NSPR_4.1; |