X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Fprocesses%2Fethread.cpp;h=33f0a90b03e9f4c1fd4a8680798fce348d899962;hb=f5d845d81352418af0785b85412a35888c82486f;hp=30efcc88878033f628939ddd23d36a1543e714c7;hpb=3ea085ec301ed1399dfa1e9f3a240312dc95410b;p=feisty_meow.git diff --git a/nucleus/library/processes/ethread.cpp b/nucleus/library/processes/ethread.cpp index 30efcc88..33f0a90b 100644 --- a/nucleus/library/processes/ethread.cpp +++ b/nucleus/library/processes/ethread.cpp @@ -23,9 +23,9 @@ #include #include -#ifdef __WIN32__ +#ifdef _MSC_VER #include -#elif defined(__UNIX__) +#elif defined(__UNIX__) || defined(__GNU_WINDOWS__) #include #else #error unknown OS for thread support. @@ -88,36 +88,36 @@ ethread::ethread() : _thread_ready(false), _thread_active(false), _stop_thread(false), - _data(NIL), -#ifdef __UNIX__ - _handle(new pthread_t), -#elif defined(__WIN32__) + _data(NULL_POINTER), +#ifdef _MSC_VER _handle(0), +#else + _handle(new pthread_t), #endif _sleep_time(0), _periodic(false), _next_activation(new time_stamp), _how(TIGHT_INTERVAL) // unused. { -// FUNCDEF("constructor [one-shot]"); + FUNCDEF("constructor [one-shot]"); } ethread::ethread(int sleep_timer, timed_thread_types how) : _thread_ready(false), _thread_active(false), _stop_thread(false), - _data(NIL), -#ifdef __UNIX__ - _handle(new pthread_t), -#elif defined(__WIN32__) + _data(NULL_POINTER), +#ifdef _MSC_VER _handle(0), +#else + _handle(new pthread_t), #endif _sleep_time(sleep_timer), _periodic(true), _next_activation(new time_stamp), _how(how) { -// FUNCDEF("constructor [periodic]"); + FUNCDEF("constructor [periodic]"); if (sleep_timer < MINIMUM_SLEEP_PERIOD) { _sleep_time = MINIMUM_SLEEP_PERIOD; } @@ -127,7 +127,7 @@ ethread::~ethread() { stop(); WHACK(_next_activation); -#ifdef __UNIX__ +#ifndef _MSC_VER WHACK(_handle); #endif } @@ -155,7 +155,7 @@ bool ethread::start(void *thread_data) int error = 0; int attempts = 0; while (attempts++ < MAXIMUM_CREATE_ATTEMPTS) { -#ifdef __UNIX__ +#ifndef _MSC_VER pthread_attr_t attribs; // special flags for creation of thread. int aret = pthread_attr_init(&attribs); if (aret) LOG("failed to init attribs."); @@ -170,7 +170,7 @@ bool ethread::start(void *thread_data) (void *)this); if (!ret) success = true; else error = ret; -#elif defined(__WIN32__) +#else if (_periodic) _handle = _beginthread(periodic_thread_driver, 0, (void *)this); else @@ -197,7 +197,7 @@ void ethread::stop() cancel(); // tell thread to leave. if (!thread_started()) return; // not running. while (!thread_finished()) { -#ifdef __WIN32__ +#ifdef _MSC_VER int result = 0; if (!GetExitCodeThread((HANDLE)_handle, (LPDWORD)&result) || (result != STILL_ACTIVE)) { @@ -213,23 +213,23 @@ void ethread::exempt_stop() { _thread_active = false; _thread_ready = false; -#ifdef __WIN32__ +#ifdef _MSC_VER _handle = 0; #endif } -#ifdef __UNIX__ +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) void *ethread::one_shot_thread_driver(void *hidden_pointer) -#elif defined(__WIN32__) +#elif defined(_MSC_VER) void ethread::one_shot_thread_driver(void *hidden_pointer) #else #error unknown thread signature. #endif { -// FUNCDEF("one_shot_thread_driver"); + FUNCDEF("one_shot_thread_driver"); ethread *manager = (ethread *)hidden_pointer; -#ifdef __UNIX__ - if (!manager) return NIL; +#ifndef _MSC_VER + if (!manager) return NULL_POINTER; #else if (!manager) return; #endif @@ -244,27 +244,27 @@ void ethread::one_shot_thread_driver(void *hidden_pointer) #ifdef COUNT_THREADS _current_threads().decrement(); #endif -#ifdef __UNIX__ - pthread_exit(NIL); - return NIL; +#ifndef _MSC_VER + pthread_exit(NULL_POINTER); + return NULL_POINTER; #else _endthread(); #endif } -#ifdef __UNIX__ +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) void *ethread::periodic_thread_driver(void *hidden_pointer) -#elif defined(__WIN32__) +#elif defined(_MSC_VER) void ethread::periodic_thread_driver(void *hidden_pointer) #else #error unknown thread signature. #endif { -// FUNCDEF("periodic_thread_driver"); + FUNCDEF("periodic_thread_driver"); ethread *manager = (ethread *)hidden_pointer; -#ifdef __UNIX__ - if (!manager) return NIL; -#elif defined(__WIN32__) +#if defined(__UNIX__) || defined(__GNU_WINDOWS__) + if (!manager) return NULL_POINTER; +#elif defined(_MSC_VER) if (!manager) return; #endif #ifdef COUNT_THREADS @@ -316,10 +316,10 @@ void ethread::periodic_thread_driver(void *hidden_pointer) #ifdef COUNT_THREADS _current_threads().decrement(); #endif -#ifdef __UNIX__ - pthread_exit(NIL); - return NIL; -#elif defined(__WIN32__) +#ifndef _MSC_VER + pthread_exit(NULL_POINTER); + return NULL_POINTER; +#else _endthread(); #endif }