Browse Source

is_true_threads(), write_status()

David Rose 18 years ago
parent
commit
26306d6e3e

+ 19 - 4
panda/src/pipeline/thread.I

@@ -226,10 +226,9 @@ get_current_pipeline_stage() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Thread::is_threading_supported
 //     Function: Thread::is_threading_supported
 //       Access: Published, Static
 //       Access: Published, Static
-//  Description: Returns true if a real threading library is available
-//               that supports threads, or false if no threading
-//               library is available (and Thread::start() will always
-//               fail).
+//  Description: Returns true if threading support has been compiled
+//               in and enabled, or false if no threading is available
+//               (and Thread::start() will always fail).
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool Thread::
 INLINE bool Thread::
 is_threading_supported() {
 is_threading_supported() {
@@ -239,6 +238,22 @@ is_threading_supported() {
   return ThreadImpl::is_threading_supported();
   return ThreadImpl::is_threading_supported();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Thread::is_true_threads
+//       Access: Published, Static
+//  Description: Returns true if a real threading library is available
+//               that supports actual OS-implemented threads, or false
+//               if the only threading we can provide is simulated
+//               user-space threading.
+////////////////////////////////////////////////////////////////////
+INLINE bool Thread::
+is_true_threads() {
+  if (!support_threads) {
+    return false;
+  }
+  return ThreadImpl::is_true_threads();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Thread::sleep
 //     Function: Thread::sleep
 //       Access: Published, Static
 //       Access: Published, Static

+ 12 - 0
panda/src/pipeline/thread.cxx

@@ -117,6 +117,18 @@ output(ostream &out) const {
   out << get_type() << " " << get_name();
   out << get_type() << " " << get_name();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Thread::write_status
+//       Access: Published, Static
+//  Description:
+////////////////////////////////////////////////////////////////////
+void Thread::
+write_status(ostream &out) {
+#ifdef SIMPLE_THREADS
+  ThreadImpl::write_status(out);
+#endif
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Thread::start
 //     Function: Thread::start
 //       Access: Public
 //       Access: Public

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

@@ -75,12 +75,14 @@ PUBLISHED:
   INLINE static Thread *get_current_thread();
   INLINE static Thread *get_current_thread();
   INLINE static int get_current_pipeline_stage();
   INLINE static int get_current_pipeline_stage();
   INLINE static bool is_threading_supported();
   INLINE static bool is_threading_supported();
+  INLINE static bool is_true_threads();
   BLOCKING INLINE static void sleep(double seconds);
   BLOCKING INLINE static void sleep(double seconds);
 
 
   BLOCKING INLINE static void force_yield();
   BLOCKING INLINE static void force_yield();
   BLOCKING INLINE static void consider_yield();
   BLOCKING INLINE static void consider_yield();
 
 
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
+  static void write_status(ostream &out);
 
 
   INLINE bool is_started() const;
   INLINE bool is_started() const;
 
 

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

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

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

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

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

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

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

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

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

@@ -48,6 +48,16 @@ is_threading_supported() {
   return true;
   return true;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadSimpleImpl::is_true_threads
+//       Access: Public, Static
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE bool ThreadSimpleImpl::
+is_true_threads() {
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadSimpleImpl::sleep
 //     Function: ThreadSimpleImpl::sleep
 //       Access: Public, Static
 //       Access: Public, Static
@@ -106,3 +116,14 @@ INLINE double ThreadSimpleImpl::
 get_start_time() const {
 get_start_time() const {
   return _start_time;
   return _start_time;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadSimpleImpl::write_status
+//       Access: Public, Static
+//  Description: Writes a list of threads running and threads blocked.
+////////////////////////////////////////////////////////////////////
+void ThreadSimpleImpl::
+write_status(ostream &out) {
+  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
+  manager->write_status(out);
+}

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

@@ -77,6 +77,7 @@ public:
   INLINE static Thread *get_current_thread();
   INLINE static Thread *get_current_thread();
   INLINE static void bind_thread(Thread *thread);
   INLINE static void bind_thread(Thread *thread);
   INLINE static bool is_threading_supported();
   INLINE static bool is_threading_supported();
+  INLINE static bool is_true_threads();
   INLINE static void sleep(double seconds);
   INLINE static void sleep(double seconds);
   INLINE static void yield();
   INLINE static void yield();
   INLINE static void consider_yield();
   INLINE static void consider_yield();
@@ -87,6 +88,8 @@ public:
 
 
   INLINE double get_start_time() const;
   INLINE double get_start_time() const;
 
 
+  INLINE static void write_status(ostream &out);
+
 private:
 private:
   static void st_begin_thread(void *data);
   static void st_begin_thread(void *data);
   void begin_thread();
   void begin_thread();

+ 42 - 0
panda/src/pipeline/threadSimpleManager.cxx

@@ -254,6 +254,48 @@ set_current_thread(ThreadSimpleImpl *current_thread) {
   _current_thread = current_thread;
   _current_thread = current_thread;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: ThreadSimpleManager::write_status
+//       Access: Public
+//  Description: Writes a list of threads running and threads blocked.
+////////////////////////////////////////////////////////////////////
+void ThreadSimpleManager::
+write_status(ostream &out) const {
+  out << "Currently running: " << *_current_thread->_parent_obj << "\n";
+
+  out << "Ready:";
+  FifoThreads::const_iterator ti;
+  for (ti = _ready.begin(); ti != _ready.end(); ++ti) {
+    out << " " << *(*ti)->_parent_obj;
+  }
+  out << "\n";
+
+  double now = get_current_time();
+  out << "Sleeping:";
+  // Copy and sort for convenience.
+  Sleeping s2 = _sleeping;
+  sort(s2.begin(), s2.end(), CompareStartTime());
+  Sleeping::const_iterator si;
+  for (si = s2.begin(); si != s2.end(); ++si) {
+    out << " " << *(*si)->_parent_obj << "(" << (*si)->_start_time - now
+        << "s)";
+  }
+  out << "\n";
+
+  Blocked::const_iterator bi;
+  for (bi = _blocked.begin(); bi != _blocked.end(); ++bi) {
+    BlockerSimple *blocker = (*bi).first;
+    const FifoThreads &threads = (*bi).second;
+    out << "On blocker " << blocker << ":\n";
+    FifoThreads::const_iterator ti;
+    for (ti = threads.begin(); ti != threads.end(); ++ti) {
+      ThreadSimpleImpl *thread = (*ti);
+      out << " " << *thread->_parent_obj;
+    }
+    out << "\n";
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ThreadSimpleManager::init_pointers
 //     Function: ThreadSimpleManager::init_pointers
 //       Access: Private, Static
 //       Access: Private, Static

+ 2 - 0
panda/src/pipeline/threadSimpleManager.h

@@ -70,6 +70,8 @@ public:
   INLINE double get_current_time() const;
   INLINE double get_current_time() const;
   INLINE static ThreadSimpleManager *get_global_ptr();
   INLINE static ThreadSimpleManager *get_global_ptr();
 
 
+  void write_status(ostream &out) const;
+
 private:
 private:
   static void init_pointers();
   static void init_pointers();
 
 

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

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

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

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