Commit 9fbefe0a authored by Bob Halley's avatar Bob Halley

convert back to UNIX text format

parent 0fc87fa2
#include <isc/condition.h>
#include <isc/assertions.h>
#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 <isc/condition.h>
#include <isc/assertions.h>
#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);
}
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_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));
}
......@@ -9,14 +9,14 @@
#include <isc/mutex.h>
#include <isc/time.h>
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 *,
......
......@@ -7,14 +7,14 @@
#include <isc/result.h>
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 */
......@@ -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 */
#include <isc/thread.h>
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/thread.h>
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);
}
......@@ -4,8 +4,8 @@
#include <string.h>
#include <time.h>
#include <errno.h>
#include <windows.h>
#include <windows.h>
#include <isc/assertions.h>
#include <isc/unexpect.h>
......@@ -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);
}
......
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