From 9fbefe0ace2ae7dba287f914b278153004bef428 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 23 Oct 1998 06:02:07 +0000 Subject: [PATCH] convert back to UNIX text format --- lib/isc/win32/condition.c | 213 +++++++++++++------------- lib/isc/win32/include/isc/condition.h | 12 +- lib/isc/win32/include/isc/mutex.h | 18 +-- lib/isc/win32/include/isc/thread.h | 6 +- lib/isc/win32/thread.c | 85 +++++----- lib/isc/win32/time.c | 11 +- 6 files changed, 175 insertions(+), 170 deletions(-) diff --git a/lib/isc/win32/condition.c b/lib/isc/win32/condition.c index ea3b2c87ff..9a926fd80b 100644 --- a/lib/isc/win32/condition.c +++ b/lib/isc/win32/condition.c @@ -1,110 +1,111 @@ - -#include -#include - -#define SIGNAL 0 -#define BROADCAST 1 - -isc_result_t -isc_condition_init(isc_condition_t *cond) { - HANDLE h; - - REQUIRE(cond != NULL); - - cond->waiters = 0; - h = CreateEvent(NULL, FALSE, FALSE, NULL); - if (h == NULL) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - cond->events[SIGNAL] = h; - h = CreateEvent(NULL, TRUE, FALSE, NULL); - if (h == NULL) { - (void)CloseHandle(cond->events[SIGNAL]); - /* XXX */ - return (ISC_R_UNEXPECTED); - } - cond->events[BROADCAST] = h; - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_condition_signal(isc_condition_t *cond) { - - REQUIRE(cond != NULL); - - if (cond->waiters > 0 && - !SetEvent(cond->events[SIGNAL])) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_condition_broadcast(isc_condition_t *cond) { - - REQUIRE(cond != NULL); - - if (cond->waiters > 0 && - !SetEvent(cond->events[BROADCAST])) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - return (ISC_R_SUCCESS); -} -isc_result_t -isc_condition_destroy(isc_condition_t *cond) { - - REQUIRE(cond != NULL); - - (void)CloseHandle(cond->events[SIGNAL]); - (void)CloseHandle(cond->events[BROADCAST]); - return (ISC_R_SUCCESS); +#include +#include + +#define SIGNAL 0 +#define BROADCAST 1 + +isc_result_t +isc_condition_init(isc_condition_t *cond) { + HANDLE h; + + REQUIRE(cond != NULL); + + cond->waiters = 0; + h = CreateEvent(NULL, FALSE, FALSE, NULL); + if (h == NULL) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + cond->events[SIGNAL] = h; + h = CreateEvent(NULL, TRUE, FALSE, NULL); + if (h == NULL) { + (void)CloseHandle(cond->events[SIGNAL]); + /* XXX */ + return (ISC_R_UNEXPECTED); + } + cond->events[BROADCAST] = h; + + return (ISC_R_SUCCESS); } - -static -isc_result_t -wait(isc_condition_t *cond, isc_mutex_t *mutex, - DWORD milliseconds) -{ - DWORD result; - - cond->waiters++; - LeaveCriticalSection(mutex); - result = WaitForMultipleObjects(2, cond->events, FALSE, - milliseconds); - if (result == WAIT_FAILED) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - EnterCriticalSection(mutex); - cond->waiters--; - if (cond->waiters == 0 && - !ResetEvent(cond->events[BROADCAST])) { - /* XXX */ - LeaveCriticalSection(mutex); - return (ISC_R_UNEXPECTED); - } - - if (result == WAIT_TIMEOUT) - return (ISC_R_TIMEDOUT); - - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_condition_wait(isc_condition_t *cond, isc_mutex_t *mutex) { - return (wait(cond, mutex, INFINITE)); -} - -isc_result_t + +isc_result_t +isc_condition_signal(isc_condition_t *cond) { + + REQUIRE(cond != NULL); + + if (cond->waiters > 0 && + !SetEvent(cond->events[SIGNAL])) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_condition_broadcast(isc_condition_t *cond) { + + REQUIRE(cond != NULL); + + if (cond->waiters > 0 && + !SetEvent(cond->events[BROADCAST])) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_condition_destroy(isc_condition_t *cond) { + + REQUIRE(cond != NULL); + + (void)CloseHandle(cond->events[SIGNAL]); + (void)CloseHandle(cond->events[BROADCAST]); + + return (ISC_R_SUCCESS); +} + +static +isc_result_t +wait(isc_condition_t *cond, isc_mutex_t *mutex, DWORD milliseconds) { + DWORD result; + + cond->waiters++; + LeaveCriticalSection(mutex); + result = WaitForMultipleObjects(2, cond->events, FALSE, milliseconds); + if (result == WAIT_FAILED) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + EnterCriticalSection(mutex); + cond->waiters--; + if (cond->waiters == 0 && + !ResetEvent(cond->events[BROADCAST])) { + /* XXX */ + LeaveCriticalSection(mutex); + return (ISC_R_UNEXPECTED); + } + + if (result == WAIT_TIMEOUT) + return (ISC_R_TIMEDOUT); + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_condition_wait(isc_condition_t *cond, isc_mutex_t *mutex) { + return (wait(cond, mutex, INFINITE)); +} + +isc_result_t isc_condition_waituntil(isc_condition_t *cond, isc_mutex_t *mutex, - isc_time_t t) -{ - DWORD milliseconds; - - milliseconds = 100; /* XXX */ - return (wait(cond, mutex, milliseconds)); + isc_time_t t) +{ + DWORD milliseconds; + + milliseconds = 100; /* XXX */ + return (wait(cond, mutex, milliseconds)); } diff --git a/lib/isc/win32/include/isc/condition.h b/lib/isc/win32/include/isc/condition.h index 9689b8e210..c927381eda 100644 --- a/lib/isc/win32/include/isc/condition.h +++ b/lib/isc/win32/include/isc/condition.h @@ -9,14 +9,14 @@ #include #include -typedef struct isc_condition { - HANDLE events[2]; - unsigned int waiters; +typedef struct isc_condition { + HANDLE events[2]; + unsigned int waiters; } isc_condition_t; - -isc_result_t isc_condition_init(isc_condition_t *); + +isc_result_t isc_condition_init(isc_condition_t *); isc_result_t isc_condition_wait(isc_condition_t *, isc_mutex_t *); -isc_result_t isc_condition_signal(isc_condition_t *); +isc_result_t isc_condition_signal(isc_condition_t *); isc_result_t isc_condition_broadcast(isc_condition_t *); isc_result_t isc_condition_destroy(isc_condition_t *); isc_result_t isc_condition_waituntil(isc_condition_t *, isc_mutex_t *, diff --git a/lib/isc/win32/include/isc/mutex.h b/lib/isc/win32/include/isc/mutex.h index 5564440338..8f694ace75 100644 --- a/lib/isc/win32/include/isc/mutex.h +++ b/lib/isc/win32/include/isc/mutex.h @@ -7,14 +7,14 @@ #include typedef CRITICAL_SECTION isc_mutex_t; - -#define isc_mutex_init(mp) \ - (InitializeCriticalSection((mp)), ISC_R_SUCCESS) -#define isc_mutex_lock(mp) \ - (EnterCriticalSection((mp)), ISC_R_SUCCESS) -#define isc_mutex_unlock(mp) \ - (LeaveCriticalSection((mp)), ISC_R_SUCCESS) -#define isc_mutex_destroy(mp) \ - (DeleteCriticalSection((mp)), ISC_R_SUCCESS) + +#define isc_mutex_init(mp) \ + (InitializeCriticalSection((mp)), ISC_R_SUCCESS) +#define isc_mutex_lock(mp) \ + (EnterCriticalSection((mp)), ISC_R_SUCCESS) +#define isc_mutex_unlock(mp) \ + (LeaveCriticalSection((mp)), ISC_R_SUCCESS) +#define isc_mutex_destroy(mp) \ + (DeleteCriticalSection((mp)), ISC_R_SUCCESS) #endif /* ISC_MUTEX_H */ diff --git a/lib/isc/win32/include/isc/thread.h b/lib/isc/win32/include/isc/thread.h index c22915ff86..f3550e42b4 100644 --- a/lib/isc/win32/include/isc/thread.h +++ b/lib/isc/win32/include/isc/thread.h @@ -12,10 +12,10 @@ typedef LPVOID isc_threadarg_t; typedef isc_threadresult_t (WINAPI *isc_threadfunc_t)(isc_threadarg_t); isc_result_t isc_thread_create(isc_threadfunc_t, isc_threadarg_t, - isc_thread_t *); -isc_result_t isc_thread_join(isc_thread_t, isc_threadresult_t *); + isc_thread_t *); +isc_result_t isc_thread_join(isc_thread_t, isc_threadresult_t *); isc_result_t isc_thread_detach(isc_thread_t); -#define isc_thread_self \ +#define isc_thread_self \ (unsigned long)GetCurrentThreadId #endif /* ISC_THREAD_H */ diff --git a/lib/isc/win32/thread.c b/lib/isc/win32/thread.c index b5b90c18b5..5c80ff9e5f 100644 --- a/lib/isc/win32/thread.c +++ b/lib/isc/win32/thread.c @@ -1,41 +1,44 @@ - -#include - -isc_result_t -isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg, - isc_thread_t *threadp) -{ - HANDLE h; - DWORD id; - - h = CreateThread(NULL, 0, start, arg, 0, &id); - if (h == NULL) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - - *threadp = h; - - return (ISC_R_SUCCESS); -} - -isc_result_t -isc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) { - DWORD result; - - result = WaitForSingleObject(thread, INFINITE); - if (result != WAIT_OBJECT_0) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - if (rp != NULL && !GetExitCodeThread(thread, rp)) { - /* XXX */ - return (ISC_R_UNEXPECTED); - } - return (ISC_R_SUCCESS); -} - -isc_result_t isc_thread_detach(isc_thread_t thread) { - /* XXX */ - return (ISC_R_SUCCESS); -} + +#include + +isc_result_t +isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg, + isc_thread_t *threadp) +{ + HANDLE h; + DWORD id; + + h = CreateThread(NULL, 0, start, arg, 0, &id); + if (h == NULL) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + + *threadp = h; + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) { + DWORD result; + + result = WaitForSingleObject(thread, INFINITE); + if (result != WAIT_OBJECT_0) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + if (rp != NULL && !GetExitCodeThread(thread, rp)) { + /* XXX */ + return (ISC_R_UNEXPECTED); + } + + return (ISC_R_SUCCESS); +} + +isc_result_t isc_thread_detach(isc_thread_t thread) { + + /* XXX */ + + return (ISC_R_SUCCESS); +} diff --git a/lib/isc/win32/time.c b/lib/isc/win32/time.c index 78c85f09d2..a62e47cd51 100644 --- a/lib/isc/win32/time.c +++ b/lib/isc/win32/time.c @@ -4,8 +4,8 @@ #include #include #include - -#include + +#include #include #include @@ -19,10 +19,11 @@ isc_time_get(isc_time_t t) { */ REQUIRE(t != NULL); - - /* XXX No nanoseconds! */ - t->seconds = (unsigned long)time(NULL); + + /* XXX No nanoseconds! */ + t->seconds = (unsigned long)time(NULL); t->nanoseconds = 0; + return (ISC_R_SUCCESS); }