Browse Source

Thread::is_simple_threads()

David Rose 15 years ago
parent
commit
5e09cff612

+ 20 - 0
panda/src/pipeline/thread.I

@@ -205,6 +205,26 @@ is_true_threads() {
   return ThreadImpl::is_true_threads();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Thread::is_simple_threads
+//       Access: Published, Static
+//  Description: Returns true if Panda is currently compiled for
+//               "simple threads", which is to say, cooperative
+//               context switching only, reducing the need for quite
+//               so many critical section protections.  This is not
+//               necessarily the opposite of "true threads", since one
+//               possible implementation of simple threads is via true
+//               threads with mutex protection to ensure only one runs
+//               at a time.
+////////////////////////////////////////////////////////////////////
+INLINE bool Thread::
+is_simple_threads() {
+  if (!support_threads) {
+    return false;
+  }
+  return ThreadImpl::is_simple_threads();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Thread::sleep
 //       Access: Published, Static

+ 1 - 0
panda/src/pipeline/thread.h

@@ -80,6 +80,7 @@ PUBLISHED:
   INLINE static int get_current_pipeline_stage();
   INLINE static bool is_threading_supported();
   INLINE static bool is_true_threads();
+  INLINE static bool is_simple_threads();
   BLOCKING INLINE static void sleep(double seconds);
 
   BLOCKING INLINE static void force_yield();

+ 10 - 0
panda/src/pipeline/threadDummyImpl.I

@@ -112,6 +112,16 @@ is_true_threads() {
   return false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadDummyImpl::is_simple_threads
+//       Access: Public, Static
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool ThreadDummyImpl::
+is_simple_threads() {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadDummyImpl::sleep
 //       Access: Public, Static

+ 1 - 0
panda/src/pipeline/threadDummyImpl.h

@@ -54,6 +54,7 @@ public:
   INLINE static void bind_thread(Thread *thread);
   INLINE static bool is_threading_supported();
   INLINE static bool is_true_threads();
+  INLINE static bool is_simple_threads();
   INLINE static void sleep(double seconds);
   INLINE static void yield();
   INLINE static void consider_yield();

+ 10 - 0
panda/src/pipeline/threadPosixImpl.I

@@ -95,6 +95,16 @@ is_true_threads() {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadPosixImpl::is_simple_threads
+//       Access: Public, Static
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool ThreadPosixImpl::
+is_simple_threads() {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadPosixImpl::sleep
 //       Access: Public, Static

+ 1 - 0
panda/src/pipeline/threadPosixImpl.h

@@ -50,6 +50,7 @@ public:
   INLINE static void bind_thread(Thread *thread);
   INLINE static bool is_threading_supported();
   INLINE static bool is_true_threads();
+  INLINE static bool is_simple_threads();
   INLINE static void sleep(double seconds);
   INLINE static void yield();
   INLINE static void consider_yield();

+ 10 - 0
panda/src/pipeline/threadSimpleImpl.I

@@ -72,6 +72,16 @@ is_true_threads() {
   return (is_os_threads != 0);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadSimpleImpl::is_simple_threads
+//       Access: Public, Static
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool ThreadSimpleImpl::
+is_simple_threads() {
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadSimpleImpl::sleep
 //       Access: Public, Static

+ 1 - 0
panda/src/pipeline/threadSimpleImpl.h

@@ -78,6 +78,7 @@ public:
   INLINE static void bind_thread(Thread *thread);
   INLINE static bool is_threading_supported();
   INLINE static bool is_true_threads();
+  INLINE static bool is_simple_threads();
   INLINE static void sleep(double seconds);
   INLINE static void yield();
   INLINE static void consider_yield();

+ 10 - 0
panda/src/pipeline/threadWin32Impl.I

@@ -95,6 +95,16 @@ is_true_threads() {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadWin32Impl::is_simple_threads
+//       Access: Public, Static
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool ThreadWin32Impl::
+is_simple_threads() {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadWin32Impl::sleep
 //       Access: Public, Static

+ 1 - 0
panda/src/pipeline/threadWin32Impl.h

@@ -49,6 +49,7 @@ public:
   INLINE static void bind_thread(Thread *thread);
   INLINE static bool is_threading_supported();
   INLINE static bool is_true_threads();
+  INLINE static bool is_simple_threads();
   INLINE static void sleep(double seconds);
   INLINE static void yield();
   INLINE static void consider_yield();