checking in the recent efforts at optimizing clam
[feisty_meow.git] / nucleus / library / processes / ethread.cpp
index 30efcc88878033f628939ddd23d36a1543e714c7..57d851ef7bdf2cee6a4495ce986c33dfed9e2a7c 100644 (file)
 #include <structures/static_memory_gremlin.h>
 #include <timely/time_control.h>
 
-#ifdef __WIN32__
-  #include <process.h>
-#elif defined(__UNIX__)
+//#ifdef _MSC_VER
+//  #include <process.h>
+//#elif defined(__UNIX__) || defined(__GNU_WINDOWS__)
   #include <pthread.h>
-#else
-  #error unknown OS for thread support.
-#endif
+//#else
+  //#error unknown OS for thread support.
+//#endif
 
 using namespace basis;
 using namespace loggers;
@@ -88,36 +88,36 @@ ethread::ethread()
 : _thread_ready(false),
   _thread_active(false),
   _stop_thread(false),
-  _data(NIL),
-#ifdef __UNIX__
+  _data(NULL_POINTER),
+//#ifdef _MSC_VER
+//  _handle(0),
+//#else
   _handle(new pthread_t),
-#elif defined(__WIN32__)
-  _handle(0),
-#endif
+//#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__
+  _data(NULL_POINTER),
+//#ifdef _MSC_VER
+//  _handle(0),
+//#else
   _handle(new pthread_t),
-#elif defined(__WIN32__)
-  _handle(0),
-#endif
+//#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,9 +127,9 @@ ethread::~ethread()
 {
   stop();
   WHACK(_next_activation);
-#ifdef __UNIX__
+//#ifndef _MSC_VER
   WHACK(_handle);
-#endif
+//#endif
 }
 
 ///void ethread::pre_thread() {}
@@ -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,8 @@ 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
@@ -178,6 +179,7 @@ bool ethread::start(void *thread_data)
     if (_handle != -1) success = true;
     else error = critical_events::system_error();
 #endif
+*/
     if (success) break;  // got it created.
     LOG("failed to create thread; trying again...");
     time_control::sleep_ms(SNOOZE_FOR_RETRY);
@@ -197,7 +199,8 @@ 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)) {
@@ -205,6 +208,7 @@ void ethread::stop()
       break;
     }
 #endif
+*/
     time_control::sleep_ms(10);  // wait for thread to leave.
   }
 }
@@ -213,26 +217,26 @@ void ethread::exempt_stop()
 {
   _thread_active = false;
   _thread_ready = false;
-#ifdef __WIN32__
-  _handle = 0;
-#endif
+//#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__)
-void ethread::one_shot_thread_driver(void *hidden_pointer)
-#else
-#error unknown thread signature.
-#endif
+//#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;
-#else
-  if (!manager) return;
-#endif
+//#ifndef _MSC_VER
+  if (!manager) return NULL_POINTER;
+//#else
+  //if (!manager) return;
+//#endif
 #ifdef COUNT_THREADS
   _current_threads().increment();
 #endif
@@ -244,29 +248,29 @@ void ethread::one_shot_thread_driver(void *hidden_pointer)
 #ifdef COUNT_THREADS
   _current_threads().decrement();
 #endif
-#ifdef __UNIX__
-  pthread_exit(NIL);
-  return NIL;
-#else
-  _endthread();
-#endif
+//#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__)
-void ethread::periodic_thread_driver(void *hidden_pointer)
-#else
-#error unknown thread signature.
-#endif
+//#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 (!manager) return;
-#endif
+//#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
+  if (!manager) return NULL_POINTER;
+//#elif defined(_MSC_VER)
+//  if (!manager) return;
+//#endif
 #ifdef COUNT_THREADS
   _current_threads().increment();
 #endif
@@ -316,12 +320,12 @@ 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__)
-  _endthread();
-#endif
+//#ifndef _MSC_VER
+  pthread_exit(NULL_POINTER);
+  return NULL_POINTER;
+//#else
+  //_endthread();
+//#endif
 }
 
 } //namespace.