From 11eb4dfd2d42417327fc205c649ea32ee623cf92 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 18 Aug 2000 08:02:29 +0000 Subject: 2000-08-18 Ross Johnson * Several: Fix typos from scripted edit session yesterday. * nonportable.c (pthread_mutexattr_setforcecs_np): Moved this function from mutex.c. (pthread_getw32threadhandle_np): New function to return the win32 thread handle that the POSIX thread is using. * mutex.c (pthread_mutexattr_setforcecs_np): Moved to new file "nonportable.c". * pthread.h (PTW32_BUILD): Only redefine __except and catch compiler keywords if we aren't building the library (ie. PTW32_BUILD is not defined) - this is safer than defining and then undefining if not building the library. * implement.h: Remove __except and catch undefines. * Makefile (CFLAGS): Define PTW32_BUILD. * GNUmakefile (CFLAGS): Define PTW32_BUILD. * All appropriate: Change Pthread_exception* to ptw32_exception* to be consistent with internal identifier naming. * private.c (ptw32_throw): New function to provide a generic exception throw for all internal exceptions and EH schemes. (ptw32_threadStart): pthread_exit() value is now returned via the thread structure exitStatus element. * exit.c (pthread_exit): pthread_exit() value is now returned via the thread structure exitStatus element. * cancel.c (ptw32_cancel_self): Now uses ptw32_throw. (pthread_setcancelstate): Ditto. (pthread_setcanceltype): Ditto. (pthread_testcancel): Ditto. (pthread_cancel): Ditto. * misc.c (CancelableWait): Ditto. * exit.c (pthread_exit): Ditto. * All applicable: Change PTW32_ prefix to PTW32_ prefix to remove leading underscores from private library identifiers. --- private.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 11 deletions(-) (limited to 'private.c') diff --git a/private.c b/private.c index 2cdccac..0f8a175 100644 --- a/private.c +++ b/private.c @@ -62,7 +62,7 @@ ptw32_processInitialize (void) * ------------------------------------------------------ */ { - if (ptw32_rocessInitialized) { + if (ptw32_processInitialized) { /* * ignore if already initialized. this is useful for * programs that uses a non-dll pthread @@ -184,6 +184,7 @@ ptw32_threadStart (ThreadParms * threadParms) pthread_t self; void *(*start) (void *); void *arg; + #ifdef _MSC_VER DWORD ei[] = {0,0,0}; #endif @@ -221,21 +222,21 @@ ptw32_threadStart (ThreadParms * threadParms) /* * Run the caller's routine; */ - status = (*start) (arg); + status = self->exitStatus = (*start) (arg); } __except (ExceptionFilter(GetExceptionInformation(), ei)) { DWORD ec = GetExceptionCode(); - if (ec == EXCEPTION_PTHREAD_SERVICES) + if (ec == EXCEPTION_PTW32_SERVICES) { switch (ei[0]) { - case _PTHREAD_EPS_CANCEL: + case PTW32_EPS_CANCEL: status = PTHREAD_CANCELED; break; - case _PTHREAD_EPS_EXIT: - status = (void *) ei[1]; + case PTW32_EPS_EXIT: + status = self->exitStatus; break; default: status = PTHREAD_CANCELED; @@ -247,7 +248,7 @@ ptw32_threadStart (ThreadParms * threadParms) /* * A system unexpected exception had occurred running the user's * routine. We get control back within this block because - * we can't allow the exception out of thread scope. + * we can't allow the exception to pass out of thread scope. */ status = PTHREAD_CANCELED; } @@ -264,14 +265,14 @@ ptw32_threadStart (ThreadParms * threadParms) */ status = self->exitStatus = (*start) (arg); } - catch (Pthread_exception_cancel) + catch (ptw32_exception_cancel) { /* * Thread was cancelled. */ status = self->exitStatus = PTHREAD_CANCELED; } - catch (Pthread_exception_exit) + catch (ptw32_exception_exit) { /* * Thread was exited via pthread_exit(). @@ -294,7 +295,7 @@ ptw32_threadStart (ThreadParms * threadParms) * Run the caller's routine; no cancelation or other exceptions will * be honoured. */ - status = (*start) (arg); + status = self->exitStatus = (*start) (arg); #endif /* __cplusplus */ @@ -800,7 +801,7 @@ ptw32_get_exception_services_code(void) { #if defined(_MSC_VER) && !defined(__cplusplus) - return EXCEPTION_PTHREAD_SERVICES; + return EXCEPTION_PTW32_SERVICES; #else @@ -808,3 +809,49 @@ ptw32_get_exception_services_code(void) #endif } + + +void +ptw32_throw(DWORD exception) +{ + if (exception != PTW32_EPS_CANCEL || + exception != PTW32_EPS_EXIT) + { + /* Should never enter here */ + exit(1); + } + +#if defined(_MSC_VER) && !defined(__cplusplus) + + DWORD exceptionInformation[3]; + + exceptionInformation[0] = (DWORD) (exception); + exceptionInformation[1] = (DWORD) (0); + exceptionInformation[2] = (DWORD) (0); + + RaiseException ( + EXCEPTION_PTW32_SERVICES, + 0, + 3, + exceptionInformation); + +#else /* _MSC_VER && ! __cplusplus */ + +# ifdef __cplusplus + + switch (exception) + { + case PTW32_EPS_CANCEL: + throw ptw32_exception_cancel(); + break; + case PTW32_EPS_EXIT: + throw ptw32_exception_exit(); + break; + } + +# endif /* __cplusplus */ + +#endif /* _MSC_VER && ! __cplusplus */ + + /* Never reached */ +} -- cgit v1.2.3