mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 11:28:17 -04:00
remove more nspr cruft
This commit is contained in:
parent
b7f11dd932
commit
ebeda0b51a
@ -20,7 +20,6 @@
|
|||||||
conditionVarFullDirect.h conditionVarFullDirect.I \
|
conditionVarFullDirect.h conditionVarFullDirect.I \
|
||||||
conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I \
|
conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I \
|
||||||
conditionVarImpl.h \
|
conditionVarImpl.h \
|
||||||
conditionVarNsprImpl.h conditionVarNsprImpl.I \
|
|
||||||
conditionVarPosixImpl.h conditionVarPosixImpl.I \
|
conditionVarPosixImpl.h conditionVarPosixImpl.I \
|
||||||
conditionVarWin32Impl.h conditionVarWin32Impl.I \
|
conditionVarWin32Impl.h conditionVarWin32Impl.I \
|
||||||
conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I \
|
conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I \
|
||||||
@ -51,7 +50,6 @@
|
|||||||
reMutexDirect.h reMutexDirect.I \
|
reMutexDirect.h reMutexDirect.I \
|
||||||
reMutexHolder.I reMutexHolder.h \
|
reMutexHolder.I reMutexHolder.h \
|
||||||
threadDummyImpl.h threadDummyImpl.I thread.h thread.I threadImpl.h \
|
threadDummyImpl.h threadDummyImpl.I thread.h thread.I threadImpl.h \
|
||||||
threadNsprImpl.h threadNsprImpl.I \
|
|
||||||
threadPosixImpl.h threadPosixImpl.I \
|
threadPosixImpl.h threadPosixImpl.I \
|
||||||
threadWin32Impl.h threadWin32Impl.I \
|
threadWin32Impl.h threadWin32Impl.I \
|
||||||
threadPriority.h
|
threadPriority.h
|
||||||
@ -65,7 +63,6 @@
|
|||||||
conditionVarFullDebug.cxx \
|
conditionVarFullDebug.cxx \
|
||||||
conditionVarFullDirect.cxx \
|
conditionVarFullDirect.cxx \
|
||||||
conditionVarFullWin32Impl.cxx \
|
conditionVarFullWin32Impl.cxx \
|
||||||
conditionVarNsprImpl.cxx \
|
|
||||||
conditionVarPosixImpl.cxx \
|
conditionVarPosixImpl.cxx \
|
||||||
conditionVarWin32Impl.cxx \
|
conditionVarWin32Impl.cxx \
|
||||||
conditionVarSpinlockImpl.cxx \
|
conditionVarSpinlockImpl.cxx \
|
||||||
@ -94,7 +91,6 @@
|
|||||||
reMutexDirect.cxx \
|
reMutexDirect.cxx \
|
||||||
reMutexHolder.cxx \
|
reMutexHolder.cxx \
|
||||||
thread.cxx threadDummyImpl.cxx \
|
thread.cxx threadDummyImpl.cxx \
|
||||||
threadNsprImpl.cxx \
|
|
||||||
threadPosixImpl.cxx \
|
threadPosixImpl.cxx \
|
||||||
threadWin32Impl.cxx
|
threadWin32Impl.cxx
|
||||||
|
|
||||||
@ -108,7 +104,6 @@
|
|||||||
conditionVarFullDirect.h conditionVarFullDirect.I \
|
conditionVarFullDirect.h conditionVarFullDirect.I \
|
||||||
conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I \
|
conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I \
|
||||||
conditionVarImpl.h \
|
conditionVarImpl.h \
|
||||||
conditionVarNsprImpl.h conditionVarNsprImpl.I \
|
|
||||||
conditionVarPosixImpl.h conditionVarPosixImpl.I \
|
conditionVarPosixImpl.h conditionVarPosixImpl.I \
|
||||||
conditionVarWin32Impl.h conditionVarWin32Impl.I \
|
conditionVarWin32Impl.h conditionVarWin32Impl.I \
|
||||||
conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I \
|
conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I \
|
||||||
@ -139,7 +134,6 @@
|
|||||||
reMutexDirect.h reMutexDirect.I \
|
reMutexDirect.h reMutexDirect.I \
|
||||||
reMutexHolder.I reMutexHolder.h \
|
reMutexHolder.I reMutexHolder.h \
|
||||||
threadDummyImpl.h threadDummyImpl.I thread.h thread.I threadImpl.h \
|
threadDummyImpl.h threadDummyImpl.I thread.h thread.I threadImpl.h \
|
||||||
threadNsprImpl.h threadNsprImpl.I \
|
|
||||||
threadPosixImpl.h threadPosixImpl.I \
|
threadPosixImpl.h threadPosixImpl.I \
|
||||||
threadWin32Impl.h threadWin32Impl.I \
|
threadWin32Impl.h threadWin32Impl.I \
|
||||||
threadPriority.h
|
threadPriority.h
|
||||||
|
@ -47,12 +47,6 @@ typedef ConditionVarFullWin32Impl ConditionVarFullImpl;
|
|||||||
typedef ConditionVarPosixImpl ConditionVarImpl;
|
typedef ConditionVarPosixImpl ConditionVarImpl;
|
||||||
typedef ConditionVarPosixImpl ConditionVarFullImpl;
|
typedef ConditionVarPosixImpl ConditionVarFullImpl;
|
||||||
|
|
||||||
#elif defined(THREAD_NSPR_IMPL)
|
|
||||||
|
|
||||||
#include "conditionVarNsprImpl.h"
|
|
||||||
typedef ConditionVarNsprImpl ConditionVarImpl;
|
|
||||||
typedef ConditionVarNsprImpl ConditionVarFullImpl;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
// Filename: conditionVarNsprImpl.I
|
|
||||||
// Created by: drose (09Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ConditionVarNsprImpl::Constructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE ConditionVarNsprImpl::
|
|
||||||
ConditionVarNsprImpl(MutexNsprImpl &mutex) {
|
|
||||||
_cvar = PR_NewCondVar(mutex._lock);
|
|
||||||
nassertv(_cvar != (PRCondVar *)NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ConditionVarNsprImpl::Destructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE ConditionVarNsprImpl::
|
|
||||||
~ConditionVarNsprImpl() {
|
|
||||||
PR_DestroyCondVar(_cvar);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ConditionVarNsprImpl::wait
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ConditionVarNsprImpl::
|
|
||||||
wait() {
|
|
||||||
int status = PR_WaitCondVar(_cvar, PR_INTERVAL_NO_TIMEOUT);
|
|
||||||
nassertv(status == PR_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ConditionVarNsprImpl::signal
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ConditionVarNsprImpl::
|
|
||||||
signal() {
|
|
||||||
int status = PR_NotifyCondVar(_cvar);
|
|
||||||
nassertv(status == PR_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ConditionVarNsprImpl::signal_all
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ConditionVarNsprImpl::
|
|
||||||
signal_all() {
|
|
||||||
int status = PR_NotifyAllCondVar(_cvar);
|
|
||||||
nassertv(status == PR_SUCCESS);
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
// Filename: conditionVarNsprImpl.cxx
|
|
||||||
// Created by: drose (09Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "selectThreadImpl.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
|
||||||
|
|
||||||
#include "conditionVarNsprImpl.h"
|
|
||||||
|
|
||||||
#endif // HAVE_NSPR
|
|
@ -1,55 +0,0 @@
|
|||||||
// Filename: conditionVarNsprImpl.h
|
|
||||||
// Created by: drose (09Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef CONDITIONVARNSPRIMPL_H
|
|
||||||
#define CONDITIONVARNSPRIMPL_H
|
|
||||||
|
|
||||||
#include "pandabase.h"
|
|
||||||
#include "selectThreadImpl.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
|
||||||
|
|
||||||
#include "mutexNsprImpl.h"
|
|
||||||
#include "pnotify.h"
|
|
||||||
|
|
||||||
#include <prcvar.h>
|
|
||||||
|
|
||||||
class MutexNsprImpl;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Class : ConditionVarNsprImpl
|
|
||||||
// Description : Uses NSPR to implement a conditionVar.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
class EXPCL_PANDA ConditionVarNsprImpl {
|
|
||||||
public:
|
|
||||||
INLINE ConditionVarNsprImpl(MutexNsprImpl &mutex);
|
|
||||||
INLINE ~ConditionVarNsprImpl();
|
|
||||||
|
|
||||||
INLINE void wait();
|
|
||||||
INLINE void signal();
|
|
||||||
INLINE void signal_all();
|
|
||||||
|
|
||||||
private:
|
|
||||||
PRCondVar *_cvar;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "conditionVarNsprImpl.I"
|
|
||||||
|
|
||||||
#endif // HAVE_NSPR
|
|
||||||
|
|
||||||
#endif
|
|
@ -5,7 +5,6 @@
|
|||||||
#include "conditionVarFull.cxx"
|
#include "conditionVarFull.cxx"
|
||||||
#include "conditionVarFullDebug.cxx"
|
#include "conditionVarFullDebug.cxx"
|
||||||
#include "conditionVarFullDirect.cxx"
|
#include "conditionVarFullDirect.cxx"
|
||||||
#include "conditionVarNsprImpl.cxx"
|
|
||||||
#include "conditionVarPosixImpl.cxx"
|
#include "conditionVarPosixImpl.cxx"
|
||||||
#include "conditionVarWin32Impl.cxx"
|
#include "conditionVarWin32Impl.cxx"
|
||||||
#include "conditionVarSpinlockImpl.cxx"
|
#include "conditionVarSpinlockImpl.cxx"
|
||||||
|
@ -15,6 +15,5 @@
|
|||||||
#include "reMutexHolder.cxx"
|
#include "reMutexHolder.cxx"
|
||||||
#include "thread.cxx"
|
#include "thread.cxx"
|
||||||
#include "threadDummyImpl.cxx"
|
#include "threadDummyImpl.cxx"
|
||||||
#include "threadNsprImpl.cxx"
|
|
||||||
#include "threadPosixImpl.cxx"
|
#include "threadPosixImpl.cxx"
|
||||||
#include "threadWin32Impl.cxx"
|
#include "threadWin32Impl.cxx"
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
|
|
||||||
#undef HAVE_LONG_LONG // NSPR and Python both define this.
|
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
@ -132,7 +132,6 @@ private:
|
|||||||
friend class ThreadDummyImpl;
|
friend class ThreadDummyImpl;
|
||||||
friend class ThreadWin32Impl;
|
friend class ThreadWin32Impl;
|
||||||
friend class ThreadPosixImpl;
|
friend class ThreadPosixImpl;
|
||||||
friend class ThreadNsprImpl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
INLINE ostream &operator << (ostream &out, const Thread &thread);
|
INLINE ostream &operator << (ostream &out, const Thread &thread);
|
||||||
|
@ -37,11 +37,6 @@ typedef ThreadWin32Impl ThreadImpl;
|
|||||||
#include "threadPosixImpl.h"
|
#include "threadPosixImpl.h"
|
||||||
typedef ThreadPosixImpl ThreadImpl;
|
typedef ThreadPosixImpl ThreadImpl;
|
||||||
|
|
||||||
#elif defined(THREAD_NSPR_IMPL)
|
|
||||||
|
|
||||||
#include "threadNsprImpl.h"
|
|
||||||
typedef ThreadNsprImpl ThreadImpl;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
// Filename: threadNsprImpl.I
|
|
||||||
// Created by: drose (08Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::Constructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE ThreadNsprImpl::
|
|
||||||
ThreadNsprImpl(Thread *parent_obj) :
|
|
||||||
_parent_obj(parent_obj)
|
|
||||||
{
|
|
||||||
_thread = (PRThread *)NULL;
|
|
||||||
_joinable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::prepare_for_exit
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ThreadNsprImpl::
|
|
||||||
prepare_for_exit() {
|
|
||||||
PR_Cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::get_current_thread
|
|
||||||
// Access: Public, Static
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE Thread *ThreadNsprImpl::
|
|
||||||
get_current_thread() {
|
|
||||||
if (!_got_pt_ptr_index) {
|
|
||||||
init_pt_ptr_index();
|
|
||||||
}
|
|
||||||
return (Thread *)PR_GetThreadPrivate(_pt_ptr_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::bind_thread
|
|
||||||
// Access: Public, Static
|
|
||||||
// Description: Associates the indicated Thread object with the
|
|
||||||
// currently-executing thread. You should not call this
|
|
||||||
// directly; use Thread::bind_thread() instead.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ThreadNsprImpl::
|
|
||||||
bind_thread(Thread *thread) {
|
|
||||||
if (!_got_pt_ptr_index) {
|
|
||||||
init_pt_ptr_index();
|
|
||||||
}
|
|
||||||
PRStatus result = PR_SetThreadPrivate(_pt_ptr_index, thread);
|
|
||||||
nassertv(result == PR_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::is_threading_supported
|
|
||||||
// Access: Public, Static
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE bool ThreadNsprImpl::
|
|
||||||
is_threading_supported() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::sleep
|
|
||||||
// Access: Public, Static
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void ThreadNsprImpl::
|
|
||||||
sleep(double seconds) {
|
|
||||||
PR_Sleep((int)(PR_TicksPerSecond() * seconds));
|
|
||||||
}
|
|
@ -1,234 +0,0 @@
|
|||||||
// Filename: threadNsprImpl.cxx
|
|
||||||
// Created by: drose (08Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "threadNsprImpl.h"
|
|
||||||
#include "selectThreadImpl.h"
|
|
||||||
|
|
||||||
#ifdef THREAD_NSPR_IMPL
|
|
||||||
|
|
||||||
#include "pointerTo.h"
|
|
||||||
#include "config_pipeline.h"
|
|
||||||
|
|
||||||
PRUintn ThreadNsprImpl::_pt_ptr_index = 0;
|
|
||||||
bool ThreadNsprImpl::_got_pt_ptr_index = false;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::Destructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
ThreadNsprImpl::
|
|
||||||
~ThreadNsprImpl() {
|
|
||||||
if (thread_cat.is_debug()) {
|
|
||||||
thread_cat.debug() << "Deleting thread " << _parent_obj->get_name() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the thread object is destructing, it means the last pointer
|
|
||||||
// has gone away. This can happen in one of three cases:
|
|
||||||
|
|
||||||
// (1) start() was never called, and the last user reference has
|
|
||||||
// gone away. In this case, we should do nothing.
|
|
||||||
|
|
||||||
// (2) There are no more user references, and the thread is still
|
|
||||||
// running but is about to exit root_func(). In this case, no one
|
|
||||||
// will ever call join().
|
|
||||||
|
|
||||||
// (3) The thread terminated a while ago, and the last user
|
|
||||||
// reference has just gone away. In this case, we should call
|
|
||||||
// join() if no one else has, to clean up whatever internal
|
|
||||||
// structures NSPR might keep around for a non-detached thread.
|
|
||||||
|
|
||||||
|
|
||||||
if (_thread == (PRThread *)NULL) {
|
|
||||||
// Since the _thread pointer is still NULL, we must either be in
|
|
||||||
// case (1), or case (3) but someone else has already called
|
|
||||||
// join(). Do nothing.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRThread *current_thread = PR_GetCurrentThread();
|
|
||||||
if (current_thread == _thread) {
|
|
||||||
// Since we are currently executing *this* thread, we must be in
|
|
||||||
// case (2). Unfortunately, we cannot now indicate we need to
|
|
||||||
// clean up the thread, since NSPR doesn't have an interface to
|
|
||||||
// make a thread unjoinable after it has been created, and a
|
|
||||||
// thread can't join itself (can it?).
|
|
||||||
if (_joinable) {
|
|
||||||
thread_cat.warning()
|
|
||||||
<< "thread " << _parent_obj->get_name() << " was never joined.\n";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is case (3). The pointer went away and the thread has
|
|
||||||
// already terminated; furthermore, no one has called join() yet.
|
|
||||||
// We should do it.
|
|
||||||
join();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::start
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
bool ThreadNsprImpl::
|
|
||||||
start(ThreadPriority priority, bool global, bool joinable) {
|
|
||||||
_mutex.lock();
|
|
||||||
if (thread_cat.is_debug()) {
|
|
||||||
thread_cat.debug() << "Starting " << *_parent_obj << "\n";
|
|
||||||
}
|
|
||||||
nassertd(_thread == (PRThread *)NULL) {
|
|
||||||
_mutex.release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_joinable = joinable;
|
|
||||||
|
|
||||||
if (!_got_pt_ptr_index) {
|
|
||||||
init_pt_ptr_index();
|
|
||||||
}
|
|
||||||
|
|
||||||
PRThreadPriority nspr_pri;
|
|
||||||
|
|
||||||
switch (priority) {
|
|
||||||
case TP_low:
|
|
||||||
nspr_pri = PR_PRIORITY_LOW;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TP_high:
|
|
||||||
nspr_pri = PR_PRIORITY_HIGH;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TP_urgent:
|
|
||||||
nspr_pri = PR_PRIORITY_URGENT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TP_normal:
|
|
||||||
default:
|
|
||||||
nspr_pri = PR_PRIORITY_NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRThreadScope nspr_scope = (global) ? PR_GLOBAL_THREAD : PR_LOCAL_THREAD;
|
|
||||||
|
|
||||||
PRThreadState nspr_state = (_joinable) ? PR_JOINABLE_THREAD : PR_UNJOINABLE_THREAD;
|
|
||||||
|
|
||||||
// Increment the parent object's reference count first. The thread
|
|
||||||
// will eventually decrement it when it terminates.
|
|
||||||
_parent_obj->ref();
|
|
||||||
_thread =
|
|
||||||
PR_CreateThread(PR_USER_THREAD, &root_func, (void *)_parent_obj,
|
|
||||||
nspr_pri, nspr_scope, nspr_state, 0);
|
|
||||||
|
|
||||||
if (_thread == (PRThread *)NULL) {
|
|
||||||
// Oops, we couldn't start the thread. Be sure to decrement the
|
|
||||||
// reference count we incremented above, and return false to
|
|
||||||
// indicate failure.
|
|
||||||
unref_delete(_parent_obj);
|
|
||||||
_mutex.release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Thread was successfully started.
|
|
||||||
_mutex.release();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::interrupt
|
|
||||||
// Access: Public
|
|
||||||
// Description: Sends an interrupt message to the thread. This will
|
|
||||||
// interrupt any blocking-type system calls the thread
|
|
||||||
// may be waiting on, such as I/O, so that the thread
|
|
||||||
// may continue some other processing. The specific
|
|
||||||
// behavior is implementation dependent.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void ThreadNsprImpl::
|
|
||||||
interrupt() {
|
|
||||||
if (_thread != (PRThread *)NULL) {
|
|
||||||
PR_Interrupt(_thread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::join
|
|
||||||
// Access: Public
|
|
||||||
// Description: Blocks the calling process until the thread
|
|
||||||
// terminates. If the thread has already terminated,
|
|
||||||
// this returns immediately.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void ThreadNsprImpl::
|
|
||||||
join() {
|
|
||||||
_mutex.lock();
|
|
||||||
if (_joinable && _thread != (PRThread *)NULL) {
|
|
||||||
PR_JoinThread(_thread);
|
|
||||||
_thread = (PRThread *)NULL;
|
|
||||||
}
|
|
||||||
_mutex.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::root_func
|
|
||||||
// Access: Private, Static
|
|
||||||
// Description: The entry point of each thread.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void ThreadNsprImpl::
|
|
||||||
root_func(void *data) {
|
|
||||||
Thread *parent_obj = (Thread *)data;
|
|
||||||
PRStatus result = PR_SetThreadPrivate(_pt_ptr_index, parent_obj);
|
|
||||||
nassertv(result == PR_SUCCESS);
|
|
||||||
parent_obj->thread_main();
|
|
||||||
|
|
||||||
if (thread_cat.is_debug()) {
|
|
||||||
thread_cat.debug()
|
|
||||||
<< "Terminating thread " << parent_obj->get_name()
|
|
||||||
<< ", count = " << parent_obj->get_ref_count() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now drop the parent object reference that we grabbed in start().
|
|
||||||
// This might delete the parent object, and in turn, delete the
|
|
||||||
// ThreadNsprImpl object.
|
|
||||||
unref_delete(parent_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: ThreadNsprImpl::init_pt_ptr_index
|
|
||||||
// Access: Private, Static
|
|
||||||
// Description: Allocate a new index to store the Thread parent
|
|
||||||
// pointer as a piece of per-thread private data.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void ThreadNsprImpl::
|
|
||||||
init_pt_ptr_index() {
|
|
||||||
nassertv(!_got_pt_ptr_index);
|
|
||||||
|
|
||||||
PRStatus result = PR_NewThreadPrivateIndex(&_pt_ptr_index, NULL);
|
|
||||||
if (result != PR_SUCCESS) {
|
|
||||||
thread_cat.error()
|
|
||||||
<< "Unable to associate Thread pointers with threads.\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_got_pt_ptr_index = true;
|
|
||||||
|
|
||||||
// Assume that we must be in the main thread, since this method must
|
|
||||||
// be called before the first thread is spawned.
|
|
||||||
Thread *main_thread_obj = Thread::get_main_thread();
|
|
||||||
result = PR_SetThreadPrivate(_pt_ptr_index, main_thread_obj);
|
|
||||||
nassertv(result == PR_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // THREAD_NSPR_IMPL
|
|
@ -1,72 +0,0 @@
|
|||||||
// Filename: threadNsprImpl.h
|
|
||||||
// Created by: drose (08Aug02)
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PANDA 3D SOFTWARE
|
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
|
||||||
//
|
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
|
||||||
// Software license. You should have received a copy of this license
|
|
||||||
// along with this source code; you will also find a current copy of
|
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
|
||||||
//
|
|
||||||
// To contact the maintainers of this program write to
|
|
||||||
// panda3d-general@lists.sourceforge.net .
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef THREADNSPRIMPL_H
|
|
||||||
#define THREADNSPRIMPL_H
|
|
||||||
|
|
||||||
#include "pandabase.h"
|
|
||||||
#include "selectThreadImpl.h"
|
|
||||||
|
|
||||||
#ifdef THREAD_NSPR_IMPL
|
|
||||||
|
|
||||||
#include "pnotify.h"
|
|
||||||
#include "threadPriority.h"
|
|
||||||
#include "mutexNsprImpl.h"
|
|
||||||
|
|
||||||
#include <prthread.h>
|
|
||||||
#include <prinit.h>
|
|
||||||
|
|
||||||
class Thread;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Class : ThreadNsprImpl
|
|
||||||
// Description : Uses NSPR to implement a thread.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
class EXPCL_PANDA ThreadNsprImpl {
|
|
||||||
public:
|
|
||||||
INLINE ThreadNsprImpl(Thread *parent_obj);
|
|
||||||
~ThreadNsprImpl();
|
|
||||||
|
|
||||||
bool start(ThreadPriority priority, bool global, bool joinable);
|
|
||||||
void interrupt();
|
|
||||||
void join();
|
|
||||||
|
|
||||||
INLINE static void prepare_for_exit();
|
|
||||||
|
|
||||||
INLINE static Thread *get_current_thread();
|
|
||||||
INLINE static void bind_thread(Thread *thread);
|
|
||||||
INLINE static bool is_threading_supported();
|
|
||||||
INLINE static void sleep(double seconds);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void root_func(void *data);
|
|
||||||
static void init_pt_ptr_index();
|
|
||||||
|
|
||||||
MutexNsprImpl _mutex;
|
|
||||||
Thread *_parent_obj;
|
|
||||||
PRThread *_thread;
|
|
||||||
bool _joinable;
|
|
||||||
static PRUintn _pt_ptr_index;
|
|
||||||
static bool _got_pt_ptr_index;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "threadNsprImpl.I"
|
|
||||||
|
|
||||||
#endif // THREAD_NSPR_IMPL
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user