2002-09-21 Robert Collins <rbtcollins@hotmail.com>
* pthread.cc: Use class::call for converted pthread and semaphore
        calls.
        * thread.cc: Convert various __pthread_call and __sem_call to
        pthread::call and sem::call throughout.
        * pthread.h (__pthread_cancel): Convert to pthread::cancel.
        (__pthread_join): Convert to pthread::join.
        (__pthread_detach): Convert to pthread::detach.
        (__pthread_create): Convert to pthread::create.
        (__pthread_once): Convert to pthread::once.
        (__pthread_atfork): Convert to pthread::atfork.
        (__pthread_suspend): Convert to pthread::suspend.
        (__pthread_continue): Convert to pthread::resume.
        (__sem_init): Convert to semaphore::init.
        (__sem_destroy): Convert to semaphore::destroy.
        (__sem_wait): Convert to semaphore::wait.
        (__sem_trywait): Convert to semaphore::trywait.
        (__sem_post): Convert to semaphore::post.
			
			
This commit is contained in:
		| @@ -1,3 +1,23 @@ | |||||||
|  | 2002-09-21  Robert Collins <rbtcollins@hotmail.com> | ||||||
|  |  | ||||||
|  | 	* pthread.cc: Use class::call for converted pthread and semaphore | ||||||
|  | 	calls. | ||||||
|  | 	* thread.cc: Convert various __pthread_call and __sem_call to  | ||||||
|  | 	pthread::call and sem::call throughout. | ||||||
|  | 	* pthread.h (__pthread_cancel): Convert to pthread::cancel. | ||||||
|  | 	(__pthread_join): Convert to pthread::join. | ||||||
|  | 	(__pthread_detach): Convert to pthread::detach. | ||||||
|  | 	(__pthread_create): Convert to pthread::create. | ||||||
|  | 	(__pthread_once): Convert to pthread::once. | ||||||
|  | 	(__pthread_atfork): Convert to pthread::atfork. | ||||||
|  | 	(__pthread_suspend): Convert to pthread::suspend. | ||||||
|  | 	(__pthread_continue): Convert to pthread::resume. | ||||||
|  | 	(__sem_init): Convert to semaphore::init. | ||||||
|  | 	(__sem_destroy): Convert to semaphore::destroy. | ||||||
|  | 	(__sem_wait): Convert to semaphore::wait. | ||||||
|  | 	(__sem_trywait): Convert to semaphore::trywait. | ||||||
|  | 	(__sem_post): Convert to semaphore::post. | ||||||
|  |  | ||||||
| 2002-09-21  Robert Collins <rbtcollins@hotmail.com> | 2002-09-21  Robert Collins <rbtcollins@hotmail.com> | ||||||
|  |  | ||||||
| 	* thread.cc: Finish the removal of the separate pthread_key | 	* thread.cc: Finish the removal of the separate pthread_key | ||||||
|   | |||||||
| @@ -21,19 +21,19 @@ int | |||||||
| pthread_create (pthread_t * thread, const pthread_attr_t * attr, | pthread_create (pthread_t * thread, const pthread_attr_t * attr, | ||||||
| 		void *(*start_routine) (void *), void *arg) | 		void *(*start_routine) (void *), void *arg) | ||||||
| { | { | ||||||
|   return __pthread_create (thread, attr, start_routine, arg); |   return pthread::create (thread, attr, start_routine, arg); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| pthread_once (pthread_once_t * once_control, void (*init_routine) (void)) | pthread_once (pthread_once_t * once_control, void (*init_routine) (void)) | ||||||
| { | { | ||||||
|   return __pthread_once (once_control, init_routine); |   return pthread::once (once_control, init_routine); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) | pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) | ||||||
| { | { | ||||||
|   return __pthread_atfork(prepare, parent, child); |   return pthread::atfork(prepare, parent, child); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -147,13 +147,13 @@ pthread_exit (void *value_ptr) | |||||||
| int | int | ||||||
| pthread_join (pthread_t thread, void **return_val) | pthread_join (pthread_t thread, void **return_val) | ||||||
| { | { | ||||||
|   return __pthread_join (&thread, (void **) return_val); |   return pthread::join (&thread, (void **) return_val); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| pthread_detach (pthread_t thread) | pthread_detach (pthread_t thread) | ||||||
| { | { | ||||||
|   return __pthread_detach (&thread); |   return pthread::detach (&thread); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -161,14 +161,14 @@ pthread_detach (pthread_t thread) | |||||||
| int | int | ||||||
| pthread_suspend (pthread_t thread) | pthread_suspend (pthread_t thread) | ||||||
| { | { | ||||||
|   return __pthread_suspend (&thread); |   return pthread::suspend (&thread); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* same */ | /* same */ | ||||||
| int | int | ||||||
| pthread_continue (pthread_t thread) | pthread_continue (pthread_t thread) | ||||||
| { | { | ||||||
|   return __pthread_continue (&thread); |   return pthread::resume (&thread); | ||||||
| } | } | ||||||
|  |  | ||||||
| unsigned long | unsigned long | ||||||
| @@ -425,7 +425,7 @@ pthread_setschedparam (pthread_t thread, int policy, | |||||||
| int | int | ||||||
| pthread_cancel (pthread_t thread) | pthread_cancel (pthread_t thread) | ||||||
| { | { | ||||||
|   return __pthread_cancel (thread); |   return pthread::cancel (thread); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -462,31 +462,31 @@ _pthread_cleanup_pop (int execute) | |||||||
| int | int | ||||||
| sem_init (sem_t * sem, int pshared, unsigned int value) | sem_init (sem_t * sem, int pshared, unsigned int value) | ||||||
| { | { | ||||||
|   return __sem_init (sem, pshared, value); |   return semaphore::init (sem, pshared, value); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| sem_destroy (sem_t * sem) | sem_destroy (sem_t * sem) | ||||||
| { | { | ||||||
|   return __sem_destroy (sem); |   return semaphore::destroy (sem); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| sem_wait (sem_t * sem) | sem_wait (sem_t * sem) | ||||||
| { | { | ||||||
|   return __sem_wait (sem); |   return semaphore::wait (sem); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| sem_trywait (sem_t * sem) | sem_trywait (sem_t * sem) | ||||||
| { | { | ||||||
|   return __sem_trywait (sem); |   return semaphore::trywait (sem); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| sem_post (sem_t * sem) | sem_post (sem_t * sem) | ||||||
| { | { | ||||||
|   return __sem_post (sem); |   return semaphore::post (sem); | ||||||
| } | } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1398,7 +1398,7 @@ pthread::getsequence_np () | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_create (pthread_t *thread, const pthread_attr_t *attr, | pthread::create (pthread_t *thread, const pthread_attr_t *attr, | ||||||
| 		  void *(*start_routine) (void *), void *arg) | 		  void *(*start_routine) (void *), void *arg) | ||||||
| { | { | ||||||
|   DECLARE_TLS_STORAGE; |   DECLARE_TLS_STORAGE; | ||||||
| @@ -1407,7 +1407,7 @@ __pthread_create (pthread_t *thread, const pthread_attr_t *attr, | |||||||
|  |  | ||||||
|   *thread = new pthread (); |   *thread = new pthread (); | ||||||
|   (*thread)->create (start_routine, attr ? *attr : NULL, arg); |   (*thread)->create (start_routine, attr ? *attr : NULL, arg); | ||||||
|   if (!pthread::isGoodObject (thread)) |   if (!isGoodObject (thread)) | ||||||
|     { |     { | ||||||
|       delete (*thread); |       delete (*thread); | ||||||
|       *thread = NULL; |       *thread = NULL; | ||||||
| @@ -1418,7 +1418,7 @@ __pthread_create (pthread_t *thread, const pthread_attr_t *attr, | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_once (pthread_once_t *once_control, void (*init_routine) (void)) | pthread::once (pthread_once_t *once_control, void (*init_routine) (void)) | ||||||
| { | { | ||||||
|   // already done ? |   // already done ? | ||||||
|   if (once_control->state) |   if (once_control->state) | ||||||
| @@ -1442,9 +1442,9 @@ __pthread_once (pthread_once_t *once_control, void (*init_routine) (void)) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_cancel (pthread_t thread) | pthread::cancel (pthread_t thread) | ||||||
| { | { | ||||||
|   if (!pthread::isGoodObject (&thread)) |   if (!isGoodObject (&thread)) | ||||||
|     return ESRCH; |     return ESRCH; | ||||||
|  |  | ||||||
|   return thread->cancel (); |   return thread->cancel (); | ||||||
| @@ -1510,7 +1510,7 @@ pthread::atforkchild (void) | |||||||
|  *parent and child calls are called in FI-FC order. |  *parent and child calls are called in FI-FC order. | ||||||
|  */ |  */ | ||||||
| int | int | ||||||
| __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void)) | pthread::atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void)) | ||||||
| { | { | ||||||
|   callback *prepcb = NULL, *parentcb = NULL, *childcb = NULL; |   callback *prepcb = NULL, *parentcb = NULL, *childcb = NULL; | ||||||
|   if (prepare) |   if (prepare) | ||||||
| @@ -1726,16 +1726,16 @@ __pthread_attr_destroy (pthread_attr_t *attr) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_join (pthread_t *thread, void **return_val) | pthread::join (pthread_t *thread, void **return_val) | ||||||
| { | { | ||||||
|    pthread_t joiner = pthread::self (); |    pthread_t joiner = self (); | ||||||
|  |  | ||||||
|    // Initialize return val with NULL |    // Initialize return val with NULL | ||||||
|    if (return_val) |    if (return_val) | ||||||
|      *return_val = NULL; |      *return_val = NULL; | ||||||
|  |  | ||||||
|   /*FIXME: wait on the thread cancellation event as well - we are a cancellation point*/ |   /*FIXME: wait on the thread cancellation event as well - we are a cancellation point*/ | ||||||
|   if (!pthread::isGoodObject (thread)) |   if (!isGoodObject (thread)) | ||||||
|     return ESRCH; |     return ESRCH; | ||||||
|  |  | ||||||
|   if (__pthread_equal (thread,&joiner)) |   if (__pthread_equal (thread,&joiner)) | ||||||
| @@ -1766,9 +1766,9 @@ __pthread_join (pthread_t *thread, void **return_val) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_detach (pthread_t *thread) | pthread::detach (pthread_t *thread) | ||||||
| { | { | ||||||
|   if (!pthread::isGoodObject (thread)) |   if (!isGoodObject (thread)) | ||||||
|     return ESRCH; |     return ESRCH; | ||||||
|  |  | ||||||
|   (*thread)->mutex.Lock (); |   (*thread)->mutex.Lock (); | ||||||
| @@ -1797,9 +1797,9 @@ __pthread_detach (pthread_t *thread) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_suspend (pthread_t *thread) | pthread::suspend (pthread_t *thread) | ||||||
| { | { | ||||||
|   if (!pthread::isGoodObject (thread)) |   if (!isGoodObject (thread)) | ||||||
|     return ESRCH; |     return ESRCH; | ||||||
|  |  | ||||||
|   if ((*thread)->suspended == false) |   if ((*thread)->suspended == false) | ||||||
| @@ -1813,9 +1813,9 @@ __pthread_suspend (pthread_t *thread) | |||||||
|  |  | ||||||
|  |  | ||||||
| int | int | ||||||
| __pthread_continue (pthread_t *thread) | pthread::resume (pthread_t *thread) | ||||||
| { | { | ||||||
|   if (!pthread::isGoodObject (thread)) |   if (!isGoodObject (thread)) | ||||||
|     return ESRCH; |     return ESRCH; | ||||||
|  |  | ||||||
|   if ((*thread)->suspended == true) |   if ((*thread)->suspended == true) | ||||||
| @@ -2456,10 +2456,10 @@ semaphore::isGoodObject (sem_t const * sem) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __sem_init (sem_t *sem, int pshared, unsigned int value) | semaphore::init (sem_t *sem, int pshared, unsigned int value) | ||||||
| { | { | ||||||
|   /*opengroup calls this undefined */ |   /*opengroup calls this undefined */ | ||||||
|   if (semaphore::isGoodObject (sem)) |   if (isGoodObject (sem)) | ||||||
|     return EBUSY; |     return EBUSY; | ||||||
|  |  | ||||||
|   if (value > SEM_VALUE_MAX) |   if (value > SEM_VALUE_MAX) | ||||||
| @@ -2467,7 +2467,7 @@ __sem_init (sem_t *sem, int pshared, unsigned int value) | |||||||
|  |  | ||||||
|   *sem = new semaphore (pshared, value); |   *sem = new semaphore (pshared, value); | ||||||
|  |  | ||||||
|   if (!semaphore::isGoodObject (sem)) |   if (!isGoodObject (sem)) | ||||||
|     { |     { | ||||||
|       delete (*sem); |       delete (*sem); | ||||||
|       *sem = NULL; |       *sem = NULL; | ||||||
| @@ -2477,9 +2477,9 @@ __sem_init (sem_t *sem, int pshared, unsigned int value) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __sem_destroy (sem_t *sem) | semaphore::destroy (sem_t *sem) | ||||||
| { | { | ||||||
|   if (!semaphore::isGoodObject (sem)) |   if (!isGoodObject (sem)) | ||||||
|     return EINVAL; |     return EINVAL; | ||||||
|  |  | ||||||
|   /*FIXME - new feature - test for busy against threads... */ |   /*FIXME - new feature - test for busy against threads... */ | ||||||
| @@ -2490,9 +2490,9 @@ __sem_destroy (sem_t *sem) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __sem_wait (sem_t *sem) | semaphore::wait (sem_t *sem) | ||||||
| { | { | ||||||
|   if (!semaphore::isGoodObject (sem)) |   if (!isGoodObject (sem)) | ||||||
|     { |     { | ||||||
|       set_errno (EINVAL); |       set_errno (EINVAL); | ||||||
|       return -1; |       return -1; | ||||||
| @@ -2503,9 +2503,9 @@ __sem_wait (sem_t *sem) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __sem_trywait (sem_t *sem) | semaphore::trywait (sem_t *sem) | ||||||
| { | { | ||||||
|   if (!semaphore::isGoodObject (sem)) |   if (!isGoodObject (sem)) | ||||||
|     { |     { | ||||||
|       set_errno (EINVAL); |       set_errno (EINVAL); | ||||||
|       return -1; |       return -1; | ||||||
| @@ -2515,9 +2515,9 @@ __sem_trywait (sem_t *sem) | |||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| __sem_post (sem_t *sem) | semaphore::post (sem_t *sem) | ||||||
| { | { | ||||||
|   if (!semaphore::isGoodObject (sem)) |   if (!isGoodObject (sem)) | ||||||
|     return EINVAL; |     return EINVAL; | ||||||
|  |  | ||||||
|   (*sem)->Post (); |   (*sem)->Post (); | ||||||
|   | |||||||
| @@ -336,9 +336,21 @@ public: | |||||||
|    static void atforkparent(); |    static void atforkparent(); | ||||||
|    static void atforkchild(); |    static void atforkchild(); | ||||||
|  |  | ||||||
|  |    /* API calls */ | ||||||
|  |    static int cancel (pthread_t); | ||||||
|  |    static int join (pthread_t * thread, void **return_val); | ||||||
|  |    static int detach (pthread_t * thread); | ||||||
|  |    static int create (pthread_t * thread, const pthread_attr_t * attr, | ||||||
|  | 			      void *(*start_routine) (void *), void *arg); | ||||||
|  |    static int once (pthread_once_t *, void (*)(void)); | ||||||
|  |    static int atfork(void (*)(void), void (*)(void), void (*)(void)); | ||||||
|  |    static int suspend (pthread_t * thread); | ||||||
|  |    static int resume (pthread_t * thread); | ||||||
|  |  | ||||||
|    virtual void exit (void *value_ptr); |    virtual void exit (void *value_ptr); | ||||||
|  |  | ||||||
|    virtual int cancel (); |    virtual int cancel (); | ||||||
|  |     | ||||||
|    virtual void testcancel (); |    virtual void testcancel (); | ||||||
|    static void static_cancel_self (); |    static void static_cancel_self (); | ||||||
|  |  | ||||||
| @@ -358,9 +370,6 @@ private: | |||||||
|     __pthread_cleanup_handler *cleanup_stack; |     __pthread_cleanup_handler *cleanup_stack; | ||||||
|     pthread_mutex mutex; |     pthread_mutex mutex; | ||||||
|  |  | ||||||
|     friend int __pthread_join (pthread_t * thread, void **return_val); |  | ||||||
|     friend int __pthread_detach (pthread_t * thread); |  | ||||||
|  |  | ||||||
|     void pop_all_cleanup_handlers (void); |     void pop_all_cleanup_handlers (void); | ||||||
|     void precreate (pthread_attr *); |     void precreate (pthread_attr *); | ||||||
|     void postcreate (); |     void postcreate (); | ||||||
| @@ -439,6 +448,13 @@ class semaphore:public verifyable_object | |||||||
| { | { | ||||||
| public: | public: | ||||||
|   static bool isGoodObject(sem_t const *); |   static bool isGoodObject(sem_t const *); | ||||||
|  |   /* API calls */ | ||||||
|  |   static int init (sem_t * sem, int pshared, unsigned int value); | ||||||
|  |   static int destroy (sem_t * sem); | ||||||
|  |   static int wait (sem_t * sem); | ||||||
|  |   static int trywait (sem_t * sem); | ||||||
|  |   static int post (sem_t * sem); | ||||||
|  |    | ||||||
|   HANDLE win32_obj_id; |   HANDLE win32_obj_id; | ||||||
|   class semaphore * next; |   class semaphore * next; | ||||||
|   int shared; |   int shared; | ||||||
| @@ -496,21 +512,8 @@ public: | |||||||
|     } |     } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /* Cancellation */ |  | ||||||
| int __pthread_cancel (pthread_t thread); |  | ||||||
|  |  | ||||||
| /* Thread Exit */ |  | ||||||
| int __pthread_join (pthread_t * thread, void **return_val); |  | ||||||
| int __pthread_detach (pthread_t * thread); |  | ||||||
|  |  | ||||||
| extern "C" | extern "C" | ||||||
| { | { | ||||||
| /*  ThreadCreation */ |  | ||||||
| int __pthread_create (pthread_t * thread, const pthread_attr_t * attr, |  | ||||||
| 		      void *(*start_routine) (void *), void *arg); |  | ||||||
| int __pthread_once (pthread_once_t *, void (*)(void)); |  | ||||||
| int __pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); |  | ||||||
|  |  | ||||||
| int __pthread_attr_init (pthread_attr_t * attr); | int __pthread_attr_init (pthread_attr_t * attr); | ||||||
| int __pthread_attr_destroy (pthread_attr_t * attr); | int __pthread_attr_destroy (pthread_attr_t * attr); | ||||||
| int __pthread_attr_setdetachstate (pthread_attr_t *, int); | int __pthread_attr_setdetachstate (pthread_attr_t *, int); | ||||||
| @@ -531,10 +534,6 @@ int __pthread_attr_setschedpolicy (pthread_attr_t *, int); | |||||||
| int __pthread_attr_setscope (pthread_attr_t *, int); | int __pthread_attr_setscope (pthread_attr_t *, int); | ||||||
| int __pthread_attr_setstackaddr (pthread_attr_t *, void *); | int __pthread_attr_setstackaddr (pthread_attr_t *, void *); | ||||||
|  |  | ||||||
| /* Thread suspend */ |  | ||||||
| int __pthread_suspend (pthread_t * thread); |  | ||||||
| int __pthread_continue (pthread_t * thread); |  | ||||||
|  |  | ||||||
| /* Thread SpecificData */ | /* Thread SpecificData */ | ||||||
| int __pthread_key_create (pthread_key_t * key, void (*destructor) (void *)); | int __pthread_key_create (pthread_key_t * key, void (*destructor) (void *)); | ||||||
| int __pthread_key_delete (pthread_key_t key); | int __pthread_key_delete (pthread_key_t key); | ||||||
| @@ -593,16 +592,7 @@ int __pthread_getschedparam (pthread_t thread, int *policy, | |||||||
| int __pthread_setschedparam (pthread_t thread, int policy, | int __pthread_setschedparam (pthread_t thread, int policy, | ||||||
| 			     const struct sched_param *param); | 			     const struct sched_param *param); | ||||||
|  |  | ||||||
| /* cancelability states */ |  | ||||||
|  |  | ||||||
| /* Semaphores */ |  | ||||||
| int __sem_init (sem_t * sem, int pshared, unsigned int value); |  | ||||||
| int __sem_destroy (sem_t * sem); |  | ||||||
| int __sem_wait (sem_t * sem); |  | ||||||
| int __sem_trywait (sem_t * sem); |  | ||||||
| int __sem_post (sem_t * sem); |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // MT_SAFE | #endif // MT_SAFE | ||||||
|  |  | ||||||
| #endif // _CYGNUS_THREADS_ | #endif // _CYGNUS_THREADS_ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user