2002-09-11 Robert Collins <rbtcollins@hotmail.com>
* init.cc (dll_entry): On thread detach, if the thread hasn't exit()ed, do so. * pthread.cc (pthread_getsequence_np): Remove the __pthread_getsequence_np wrapper. This requires errno.h. * thread.cc (pthread::self): Instantiate a new pthread object when called and none exists. return a NULL object if instantiation fails. (pthread::precreate): Factor out common code. (pthread::postcreate): Ditto. (pthread::create): Ditto. (pthread::exit): Remove the TLS value when we exit to prevent double exits. (MTinterface::Init): Bugfix - don't mark the TLS index as created if one was not allocated. Apply Extract Method to move pthread specific initialisation into pthread. (pthread::initMainThread): Extracted method from MTinterface::Init. (pthread::setTlsSelfPointer): Extracted method from various pthread calls, to make reading those functions easier. (pthread::setThreadIdtoCurrent): Ditto. (pthread::cancel_self): Bring into the .cc file, it's only used within the class. (pthread::getThreadId): Ditto. (pthread::thread_init_wrapper): Apply Extract Method to the TLS setting logic. (pthread::isGoodObject): Extracted method from various pthread wrapper calls, for clarity of reading. (pthread::getsequence_np): Converted from __pthread_getsquence_np. (__pthread_create): Apply Extract Method to the object validation. (__pthread_cancel): Ditto. (__pthread_join): Ditto. (__pthread_detach): Ditto. (__pthread_suspend): Ditto. (__pthread_continue): Ditto. (__pthread_getschedparam): Ditto. (__pthread_getsequence_np): Remove. (__pthread_setschedparam): Apply Extract Method to the object validation. (pthreadNull::getNullpthread): New method, return the pthreadNull object. (pthreadNull::pthreadNull): Private constructor to prevent accidental use. (pthreadNull::~pthreadNull): Prevent compile warnings. (pthreadNull::create): Override pthread behaviour. (pthreadNull::exit): Ditto. (pthreadNull::cancel): Ditto. (pthreadNull::testcancel): Ditto. (pthreadNull::setcancelstate): Ditto. (pthreadNull::setcanceltype): Ditto. (pthreadNull::push_cleanup_handler): Ditto. (pthreadNull::pop_cleanup_handler): Ditto. (pthreadNull::getsequence_np): Ditto. (pthreadNull::_instance): Ditto. * thread.h (pthread): Declare pre- and post-create. Move GetThreadId to private scope and rename to getThreadId. Move setThreadIdtoCurrent to private scope. Make create virtual. Make ~pthread virtual. Declare initMainThread. Declare isGoodObject. Make exit virtual. Make cancel virtual. Make testcancel virtual. Make setcancelstate virtual. Make setcanceltype virtual. Make push_cleanup_handler virtual. Make pop_cleanup_handler virtual. Declare getsequence_np. Declare setTlsSelfPointer. (pthreadNull): New null object class for pthread. (__pthread_getsequence_np): Remove.
This commit is contained in:
@@ -270,43 +270,35 @@ public:
|
||||
pthread_t joiner;
|
||||
// int joinable;
|
||||
|
||||
DWORD GetThreadId ()
|
||||
{
|
||||
return thread_id;
|
||||
}
|
||||
void setThreadIdtoCurrent ()
|
||||
{
|
||||
thread_id = GetCurrentThreadId ();
|
||||
}
|
||||
|
||||
/* signal handling */
|
||||
struct sigaction *sigs;
|
||||
sigset_t *sigmask;
|
||||
LONG *sigtodo;
|
||||
void create (void *(*)(void *), pthread_attr *, void *);
|
||||
virtual void create (void *(*)(void *), pthread_attr *, void *);
|
||||
|
||||
pthread ();
|
||||
~pthread ();
|
||||
pthread ();
|
||||
virtual ~pthread ();
|
||||
|
||||
void exit (void *value_ptr);
|
||||
static void initMainThread(pthread *, HANDLE);
|
||||
static bool isGoodObject(pthread_t *);
|
||||
|
||||
int cancel ();
|
||||
void testcancel ();
|
||||
void cancel_self ()
|
||||
{
|
||||
exit (PTHREAD_CANCELED);
|
||||
}
|
||||
virtual void exit (void *value_ptr);
|
||||
|
||||
virtual int cancel ();
|
||||
virtual void testcancel ();
|
||||
static void static_cancel_self ();
|
||||
|
||||
int setcancelstate (int state, int *oldstate);
|
||||
int setcanceltype (int type, int *oldtype);
|
||||
virtual int setcancelstate (int state, int *oldstate);
|
||||
virtual int setcanceltype (int type, int *oldtype);
|
||||
|
||||
void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
||||
void pop_cleanup_handler (int const execute);
|
||||
virtual void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
||||
virtual void pop_cleanup_handler (int const execute);
|
||||
|
||||
static pthread* self ();
|
||||
static void *thread_init_wrapper (void *);
|
||||
|
||||
virtual unsigned long getsequence_np();
|
||||
|
||||
private:
|
||||
DWORD thread_id;
|
||||
__pthread_cleanup_handler *cleanup_stack;
|
||||
@@ -316,6 +308,36 @@ private:
|
||||
friend int __pthread_detach (pthread_t * thread);
|
||||
|
||||
void pop_all_cleanup_handlers (void);
|
||||
void precreate (pthread_attr *);
|
||||
void postcreate ();
|
||||
void setThreadIdtoCurrent();
|
||||
static void setTlsSelfPointer(pthread *);
|
||||
void cancel_self ();
|
||||
DWORD getThreadId ();
|
||||
};
|
||||
|
||||
class pthreadNull : public pthread
|
||||
{
|
||||
public:
|
||||
static pthread *getNullpthread();
|
||||
~pthreadNull();
|
||||
|
||||
/* From pthread These should never get called
|
||||
* as the ojbect is not verifyable
|
||||
*/
|
||||
void create (void *(*)(void *), pthread_attr *, void *);
|
||||
void exit (void *value_ptr);
|
||||
int cancel ();
|
||||
void testcancel ();
|
||||
int setcancelstate (int state, int *oldstate);
|
||||
int setcanceltype (int type, int *oldtype);
|
||||
void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
||||
void pop_cleanup_handler (int const execute);
|
||||
unsigned long getsequence_np();
|
||||
|
||||
private:
|
||||
pthreadNull ();
|
||||
static pthreadNull _instance;
|
||||
};
|
||||
|
||||
class pthread_condattr:public verifyable_object
|
||||
@@ -458,8 +480,6 @@ int __pthread_attr_setstackaddr (pthread_attr_t *, void *);
|
||||
int __pthread_suspend (pthread_t * thread);
|
||||
int __pthread_continue (pthread_t * thread);
|
||||
|
||||
unsigned long __pthread_getsequence_np (pthread_t * thread);
|
||||
|
||||
/* Thread SpecificData */
|
||||
int __pthread_key_create (pthread_key_t * key, void (*destructor) (void *));
|
||||
int __pthread_key_delete (pthread_key_t key);
|
||||
|
Reference in New Issue
Block a user