is_true_threads(), write_status()

This commit is contained in:
David Rose 2007-06-23 00:10:56 +00:00
parent f90469bbfe
commit 26306d6e3e
13 changed files with 134 additions and 4 deletions

View File

@ -226,10 +226,9 @@ get_current_pipeline_stage() {
////////////////////////////////////////////////////////////////////
// Function: Thread::is_threading_supported
// 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::
is_threading_supported() {
@ -239,6 +238,22 @@ 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
// Access: Published, Static

View File

@ -117,6 +117,18 @@ output(ostream &out) const {
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
// Access: Public

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,6 +48,16 @@ is_threading_supported() {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: ThreadSimpleImpl::is_true_threads
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ThreadSimpleImpl::
is_true_threads() {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: ThreadSimpleImpl::sleep
// Access: Public, Static
@ -106,3 +116,14 @@ INLINE double ThreadSimpleImpl::
get_start_time() const {
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);
}

View File

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

View File

@ -254,6 +254,48 @@ set_current_thread(ThreadSimpleImpl *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
// Access: Private, Static

View File

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

View File

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

View File

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