123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "implement.h"
- #if defined(PTE_CLEANUP_CXX)
- # if defined(__GNUC__) && __GNUC__ < 3
- # include <new>
- # else
- # include <new>
- using
- std::terminate_handler;
- using
- std::terminate;
- using
- std::set_terminate;
- # endif
- typedef terminate_handler terminate_function;
- static terminate_function pte_oldTerminate;
- void
- pte_terminate ()
- {
- set_terminate (pte_oldTerminate);
- (void) pte_thread_detach_np();
- }
- #endif
- int pte_threadStart (void *vthreadParms)
- {
- ThreadParms * threadParms = (ThreadParms *) vthreadParms;
- pthread_t self;
- pte_thread_t * sp;
- void *(*start) (void *);
- void * arg;
- #ifdef PTE_CLEANUP_C
- #include <setjmp.h>
- int setjmp_rc;
- #endif
- void * status = (void *) 0;
- self = threadParms->tid;
- sp = (pte_thread_t *) self;
- start = threadParms->start;
- arg = threadParms->arg;
- pthread_setspecific (pte_selfThreadKey, sp);
- sp->state = PThreadStateRunning;
- #ifdef PTE_CLEANUP_C
- setjmp_rc = setjmp (sp->start_mark);
- if (0 == setjmp_rc)
- {
-
- sp->exitStatus = status = (*start) (arg);
- }
- else
- {
- switch (setjmp_rc)
- {
- case PTE_EPS_CANCEL:
- status = sp->exitStatus = PTHREAD_CANCELED;
- break;
- case PTE_EPS_EXIT:
- status = sp->exitStatus;
- break;
- default:
- status = sp->exitStatus = PTHREAD_CANCELED;
- break;
- }
- }
- #else
- #ifdef PTE_CLEANUP_CXX
- pte_oldTerminate = set_terminate (&pte_terminate);
- try
- {
-
- try
- {
- status = sp->exitStatus = (*start) (arg);
- }
- catch (pte_exception &)
- {
-
- throw;
- }
- catch (...)
- {
-
- terminate_function
- term_func = set_terminate (0);
- set_terminate (term_func);
- if (term_func != 0)
- {
- term_func ();
- }
- throw;
- }
- }
- catch (pte_exception_cancel &)
- {
-
- status = sp->exitStatus = PTHREAD_CANCELED;
- }
- catch (pte_exception_exit &)
- {
-
- status = sp->exitStatus;
- }
- catch (...)
- {
-
- status = sp->exitStatus = PTHREAD_CANCELED;
- (void) pthread_mutex_lock (&sp->cancelLock);
- sp->state = PThreadStateException;
- (void) pthread_mutex_unlock (&sp->cancelLock);
- (void) pte_thread_detach_np();
- (void) set_terminate (pte_oldTerminate);
- throw;
-
- }
- (void) set_terminate (pte_oldTerminate);
- #else
- #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
- #endif
- #endif
-
- (void) pte_thread_detach_and_exit_np ();
-
-
- return (unsigned) status;
- }
|