mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
removed the mutex method
This commit is contained in:
parent
af97e49f21
commit
7182ad9121
@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: once.h,v 1.1 1999/09/23 18:14:16 tale Exp $ */
|
||||
/* $Id: once.h,v 1.2 1999/10/06 19:25:41 tale Exp $ */
|
||||
|
||||
#ifndef ISC_ONCE_H
|
||||
#define ISC_ONCE_H 1
|
||||
@ -27,19 +27,13 @@ ISC_LANG_BEGINDECLS
|
||||
|
||||
typedef struct {
|
||||
int status;
|
||||
#ifndef ISC_ONCE_USE_MUTEX
|
||||
int counter;
|
||||
#endif
|
||||
} isc_once_t;
|
||||
|
||||
#define ISC_ONCE_INIT_NEEDED 0
|
||||
#define ISC_ONCE_INIT_DONE 1
|
||||
|
||||
#ifdef ISC_ONCE_USE_MUTEX
|
||||
#define ISC_ONCE_INIT { ISC_ONCE_INIT_NEEDED }
|
||||
#else
|
||||
#define ISC_ONCE_INIT { ISC_ONCE_INIT_NEEDED, 1 }
|
||||
#endif
|
||||
|
||||
isc_result_t
|
||||
isc_once_do(isc_once_t *controller, void(*function)(void));
|
||||
|
@ -15,73 +15,15 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: once.c,v 1.1 1999/09/23 18:14:16 tale Exp $ */
|
||||
/* $Id: once.c,v 1.2 1999/10/06 19:25:41 tale Exp $ */
|
||||
|
||||
/* Principal Authors: DCL */
|
||||
|
||||
#ifdef ISC_ONCE_USE_MUTEX
|
||||
#include <stdio.h>
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <isc/once.h>
|
||||
#include <isc/assertions.h>
|
||||
|
||||
#ifdef ISC_ONCE_USE_MUTEX
|
||||
|
||||
/*
|
||||
* XXXDCL someone (me? bob?) should decide which method to use,
|
||||
* the mutex method or the InterlockedDecrement method.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_once_do(isc_once_t *controller, void(*function)(void))
|
||||
|
||||
{
|
||||
char mutex_name[64];
|
||||
HANDLE mutex;
|
||||
|
||||
REQUIRE(controller != NULL && function != NULL);
|
||||
|
||||
if (controller->status == ISC_ONCE_INIT_NEEDED) {
|
||||
|
||||
/*
|
||||
* Create a name that is associated only with this process
|
||||
* and controller.
|
||||
*/
|
||||
sprintf(mutex_name, "__isc_once_do_%ld:%p",
|
||||
getpid(), controller);
|
||||
|
||||
/*
|
||||
* Create the mutex (or attach to the existing mutex)
|
||||
* and lock it.
|
||||
*/
|
||||
mutex = CreateMutex(NULL, FALSE, mutex_name);
|
||||
if (mutex == NULL)
|
||||
return (ISC_R_UNEXPECTED);
|
||||
if (WaitForSingleObject(mutex, INFINITE) == WAIT_FAILED)
|
||||
return (ISC_R_UNEXPECTED);
|
||||
|
||||
/*
|
||||
* Recheck need for initialization now that
|
||||
* the controller is locked.
|
||||
*/
|
||||
if (controller->status == ISC_ONCE_INIT_NEEDED) {
|
||||
function();
|
||||
controller->status = ISC_ONCE_INIT_DONE;
|
||||
}
|
||||
|
||||
ReleaseMutex(mutex);
|
||||
CloseHandle(mutex);
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
#else /* not ISC_ONCE_USE_MUTEX, use InterlockedDecrement instead */
|
||||
|
||||
isc_result_t
|
||||
isc_once_do(isc_once_t *controller, void(*function)(void))
|
||||
|
||||
@ -106,5 +48,3 @@ isc_once_do(isc_once_t *controller, void(*function)(void))
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* ISC_ONCE_USE_MUTEX */
|
||||
|
Loading…
x
Reference in New Issue
Block a user