Commit 7182ad91 authored by David Lawrence's avatar David Lawrence
Browse files

removed the mutex method

parent af97e49f
......@@ -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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment