summaryrefslogtreecommitdiff
path: root/cleanup.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-12-28 23:01:00 +0000
committerrpj <rpj>1998-12-28 23:01:00 +0000
commit0749394433f301cccd22d280cee1dd760b72e876 (patch)
treea5084cfaea800cdc96c25bf71a179562e18c552c /cleanup.c
parent95aa0a376d93ee021a6c085c71418e9f16513e0a (diff)
With this update I'm able to build the library and build and run the
tsd1.c test successfully using buildlib.bat and build.bat scripts. I not convinced that I understand the relationships between "__cplusplus" and "_WIN32" and the MS compiler, particularly in pthread.h where pthread_cleanup_push etc is defined. In particular, I have assumed that the __try/__finally blocks are only available if _WIN32 and __cplusplus are defined. I suspect this is wrong. Tue Dec 29 13:11:16 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * implement.h: Move the following struct definitions to pthread.h: pthread_t_, pthread_attr_t_, pthread_mutex_t_, pthread_mutex_t_, pthread_mutexattr_t_, pthread_key_t_, pthread_cond_t_, pthread_condattr_t_, pthread_once_t_. * pthread.h: Add "_" prefix to pthread_push_cleanup and pthread_pop_cleanup internal routines, and associated struct and typedefs. * buildlib.bat: Add compile command for semaphore.c * pthread.def: Comment out pthread_atfork routine name. Now unimplemented. * tsd.c (pthread_setspecific): Rename tkAssocCreate to _pthread_tkAssocCreate. (pthread_key_delete): Rename tkAssocDestroy to _pthread_tkAssocDestroy. * sync.c (pthread_join): Rename threadDestroy to _pthread_threadDestroy * sched.c (is_attr): attr is now **attr (was *attr), so add extra NULL pointer test. (pthread_attr_setschedparam): Increase redirection for attr which is now a **. (pthread_attr_getschedparam): Ditto. (pthread_setschedparam): Change thread validation and rename "thread" Win32 thread Handle element name to match John Bossom's version. (pthread_getschedparam): Ditto. * private.c (_pthread_threadDestroy): Rename call to callUserDestroyRoutines() as _pthread_callUserDestroyRoutines() * misc.c: Add #include "implement.h". * dll.c: Remove defined(KLUDGE) wrapped code. * fork.c: Remove redefinition of ENOMEM. Remove pthread_atfork() and fork() with #if 0/#endif. * create.c (pthread_create): Rename threadStart and threadDestroy calls to _pthread_threadStart and _pthread_threadDestroy. * implement.h: Rename "detachedstate" to "detachstate". * attr.c: Rename "detachedstate" to "detachstate". Mon Dec 28 09:54:39 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * pthread.h (pthread_attr_t_): Change to *pthread_attr_t. * attr.c (pthread_attr_setstacksize): Merge with John Bossom's version. (pthread_attr_getstacksize): Merge with John Bossom's version. (pthread_attr_setstackaddr): Merge with John Bossom's version. (pthread_attr_getstackaddr): Merge with John Bossom's version. (pthread_attr_init): Merge with John Bossom's version. (pthread_attr_destroy): Merge with John Bossom's version. (pthread_attr_getdetachstate): Merge with John Bossom's version. (pthread_attr_setdetachstate): Merge with John Bossom's version. (is_attr): attr is now **attr (was *attr), so add extra NULL pointer test. * implement.h (pthread_attr_t_): Add and rename elements in JEB's version to correspond to original, so that it can be used with original attr routines. * pthread.h: Add #endif at end which was truncated in merging.
Diffstat (limited to 'cleanup.c')
-rw-r--r--cleanup.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/cleanup.c b/cleanup.c
index 0a5ae3f..b0817d7 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -12,6 +12,139 @@
#include "pthread.h"
#include "implement.h"
+/*
+ * Code contributed by John E. Bossom <JEB>.
+ */
+
+_pthread_cleanup_t *
+_pthread_pop_cleanup (int execute)
+ /*
+ * ------------------------------------------------------
+ * DOCPUBLIC
+ * This function pops the most recently pushed cleanup
+ * handler. If execute is nonzero, then the cleanup handler
+ * is executed if non-null.
+ *
+ * PARAMETERS
+ * execute
+ * if nonzero, execute the cleanup handler
+ *
+ *
+ * DESCRIPTION
+ * This function pops the most recently pushed cleanup
+ * handler. If execute is nonzero, then the cleanup handler
+ * is executed if non-null.
+ * NOTE: specify 'execute' as nonzero to avoid duplication
+ * of common cleanup code.
+ *
+ * RESULTS
+ * N/A
+ *
+ * ------------------------------------------------------
+ */
+{
+ _pthread_cleanup_t *cleanup;
+
+ cleanup = pthread_getspecific (_pthread_cleanupKey);
+
+ if (cleanup != NULL)
+ {
+ if (execute && (cleanup->routine != NULL))
+ {
+
+#ifdef _WIN32
+
+ __try
+ {
+ /*
+ * Run the caller's cleanup routine.
+ */
+ (*cleanup->routine) (cleanup->arg);
+ }
+ __except (EXCEPTION_EXECUTE_HANDLER)
+ {
+ /*
+ * A system unexpected exception had occurred
+ * running the user's cleanup routine.
+ * We get control back within this block.
+ */
+ }
+ }
+
+#else
+
+ /*
+ * Run the caller's cleanup routine.
+ */
+ (*cleanup->routine) (cleanup->arg);
+
+#endif /* _WIN32 */
+
+ pthread_setspecific (_pthread_cleanupKey, cleanup->prev);
+ }
+
+ return (cleanup);
+
+} /* _pthread_pop_cleanup */
+
+
+void
+_pthread_push_cleanup (_pthread_cleanup_t * cleanup,
+ void (*routine) (void *),
+ void *arg)
+ /*
+ * ------------------------------------------------------
+ * DOCPUBLIC
+ * This function pushes a new cleanup handler onto the thread's stack
+ * of cleanup handlers. Each cleanup handler pushed onto the stack is
+ * popped and invoked with the argument 'arg' when
+ * a) the thread exits by calling 'pthread_exit',
+ * b) when the thread acts on a cancellation request,
+ * c) or when the thrad calls pthread_cleanup_pop with a nonzero
+ * 'execute' argument
+ *
+ * PARAMETERS
+ * cleanup
+ * a pointer to an instance of pthread_cleanup_t,
+ *
+ * routine
+ * pointer to a cleanup handler,
+ *
+ * arg
+ * parameter to be passed to the cleanup handler
+ *
+ *
+ * DESCRIPTION
+ * This function pushes a new cleanup handler onto the thread's stack
+ * of cleanup handlers. Each cleanup handler pushed onto the stack is
+ * popped and invoked with the argument 'arg' when
+ * a) the thread exits by calling 'pthread_exit',
+ * b) when the thread acts on a cancellation request,
+ * c) or when the thrad calls pthread_cleanup_pop with a nonzero
+ * 'execute' argument
+ * NOTE: pthread_push_cleanup, pthread_pop_cleanup must be paired
+ * in the same lexical scope.
+ *
+ * RESULTS
+ * pthread_cleanup_t *
+ * pointer to the previous cleanup
+ *
+ * ------------------------------------------------------
+ */
+{
+ cleanup->routine = routine;
+ cleanup->arg = arg;
+ cleanup->prev = pthread_getspecific (_pthread_cleanupKey);
+
+ pthread_setspecific (_pthread_cleanupKey, (void *) cleanup);
+
+} /* _pthread_push_cleanup */
+
+/* </JEB> */
+
+
+#if 0 /* Pre Bossom */
+
int
_pthread_handler_push(int stack,
int poporder,
@@ -214,3 +347,5 @@ _pthread_destructor_run_all()
break;
}
}
+
+#endif /* Pre Bossom */