summaryrefslogtreecommitdiff
path: root/create.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-12-22 15:59:24 +0000
committerrpj <rpj>1998-12-22 15:59:24 +0000
commit95aa0a376d93ee021a6c085c71418e9f16513e0a (patch)
treef05f436e30d759df3af5cfe9e2cde62e3efa6f1b /create.c
parent4650bcf1f1efd88a0c8f502c28945bfabd7ef6db (diff)
Sun Dec 20 14:51:58 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* misc.c (pthreadCancelableWait): New function by John Bossom. Non-stand ard but provides a hook that can be used to implement cancellation points in applications that use this library. * pthread.h (pthread_cleanup_pop): C++ (non-WIN32) version uses try/catch to emulate John Bossom's WIN32 __try/__finally behaviour. In the WIN32 version __finally block, add a test for AbnormalTermination otherwise cleanup is only run if the cleanup_pop execute arg is non-zero. Cancella tion should cause the cleanup to run irrespective of the execute arg. * condvar.c (pthread_condattr_init): Replaced by John Bossom's version. (pthread_condattr_destroy): Replaced by John Bossom's version. (pthread_condattr_getpshared): Replaced by John Bossom's version. (pthread_condattr_setpshared): Replaced by John Bossom's version. (pthread_cond_init): Replaced by John Bossom's version. Fix comment (refered to mutex rather than condition variable). (pthread_cond_destroy): Replaced by John Bossom's version. (pthread_cond_wait): Replaced by John Bossom's version. (pthread_cond_timedwait): Replaced by John Bossom's version. (pthread_cond_signal): Replaced by John Bossom's version. (pthread_cond_broadcast): Replaced by John Bossom's version. Thu Dec 17 19:10:46 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * tsd.c (pthread_key_create): Replaced by John Bossom's version. (pthread_key_delete): Replaced by John Bossom's version. (pthread_setspecific): Replaced by John Bossom's version. (pthread_getspecific): Replaced by John Bossom's version. Mon Dec 7 09:44:40 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * cancel.c (pthread_setcancelstate): Replaced by John Bossom's version. (pthread_setcanceltype): Replaced by John Bossom's version. (pthread_testcancel): Replaced by John Bossom's version. (pthread_cancel): Replaced by John Bossom's version. * exit.c (pthread_exit): Replaced by John Bossom's version. * misc.c (pthread_self): Replaced by John Bossom's version. (pthread_equal): Replaced by John Bossom's version. * sync.c (pthread_detach): Replaced by John Bossom's version. (pthread_join): Replaced by John Bossom's version. * create.c (pthread_create): Replaced by John Bossom's version. * private.c (_pthread_processInitialize): New by John Bossom. (_pthread_processTerminate): Non-public function by John Bossom. (_pthread_threadStart): Non-public function by John Bossom. (_pthread_threadDestroy): Non-public function by John Bossom. (_pthread_cleanupStack): Non-public function by John Bossom. (_pthread_tkAssocCreate): Non-public function by John Bossom. (_pthread_tkAssocDestroy): Non-public function by John Bossom. (_pthread_callUserDestroyRoutines): Non-public function by John Bossom. * implement.h: Added John Bossom's non-API structures and declarations. * dll.c (PthreadsEntryPoint): Cast return value of GetProcAddress to resolve compile warning from MSVC. * dll.c (DLLmain): Replaced by John Bossom's version. * dll.c (PthreadsEntryPoint): Re-applied Anders Norlander's patch:- Initialize _pthread_try_enter_critical_section at startup and release kernel32 handle when DLL is being unloaded.
Diffstat (limited to 'create.c')
-rw-r--r--create.c146
1 files changed, 144 insertions, 2 deletions
diff --git a/create.c b/create.c
index 6119198..d5f097e 100644
--- a/create.c
+++ b/create.c
@@ -6,6 +6,149 @@
* thread.
*/
+#include "pthread.h"
+#include "implement.h"
+
+/*
+ * Code contributed by John E. Bossom <JEB>.
+ */
+
+int
+pthread_create (pthread_t * tid,
+ const pthread_attr_t * attr,
+ void *(*start) (void *),
+ void *arg)
+ /*
+ * ------------------------------------------------------
+ * DOCPUBLIC
+ * This function creates a thread running the start function,
+ * passing it the parameter value, 'arg'.
+ *
+ * PARAMETERS
+ * tid
+ * pointer to an instance of pthread_t
+ *
+ * attr
+ * optional pointer to an instance of pthread_attr_t
+ *
+ * start
+ * pointer to the starting routine for the new thread
+ *
+ * arg
+ * optional parameter passed to 'start'
+ *
+ *
+ * DESCRIPTION
+ * This function creates a thread running the start function,
+ * passing it the parameter value, 'arg'. The 'attr'
+ * argument specifies optional creation attributes.
+ * The thread is identity of the new thread is returned
+ * as 'tid'
+ *
+ * RESULTS
+ * 0 successfully created thread,
+ * EINVAL attr invalid,
+ * EAGAIN insufficient resources.
+ *
+ * ------------------------------------------------------
+ */
+{
+ pthread_t thread;
+ int result = EAGAIN;
+ int run = TRUE;
+ ThreadParms *parms;
+ long stackSize;
+
+ if ((thread = (pthread_t) calloc (1, sizeof (*thread))) ==
+ NULL)
+ {
+ goto FAIL0;
+ }
+ thread->cancelEvent =
+ CreateEvent (
+ 0,
+ (int) TRUE, /* manualReset */
+ (int) FALSE, /* setSignaled */
+ NULL);
+
+ if (thread->cancelEvent == NULL)
+ {
+ goto FAIL0;
+ }
+
+ if ((parms = (ThreadParms *) malloc (sizeof (*parms))) ==
+ NULL)
+ {
+ goto FAIL0;
+ }
+
+ parms->tid = thread;
+ parms->start = start;
+ parms->arg = arg;
+
+ if (attr != NULL && *attr != NULL)
+ {
+ stackSize = (*attr)->stacksize;
+ thread->detachState = (*attr)->detachstate;
+
+ }
+ else
+ {
+ /*
+ * Default stackSize
+ */
+ stackSize = 0;
+ }
+
+ thread->state = run
+ ? PThreadStateInitial
+ : PThreadStateSuspended;
+
+ thread->keys = NULL;
+ thread->threadH = (HANDLE)
+ _beginthreadex (
+ (void *) NULL, /* No security info */
+ (unsigned) stackSize, /* default stack size */
+ (unsigned (__stdcall *) (void *)) threadStart,
+ parms,
+ (unsigned) run ? 0 : CREATE_SUSPENDED,
+ (unsigned *) &(thread->thread));
+
+ result = (thread->threadH != 0) ? 0 : EAGAIN;
+
+ /*
+ * Fall Through Intentionally
+ */
+
+ /*
+ * ------------
+ * Failure Code
+ * ------------
+ */
+
+FAIL0:
+ if (result != 0)
+ {
+
+ threadDestroy (thread);
+ thread = NULL;
+
+ if (parms != NULL)
+ {
+ free (parms);
+ }
+ }
+ *tid = thread;
+
+ return (result);
+
+} /* pthread_create */
+
+/* </JEB> */
+
+
+#if 0 /* Pre Bossom */
+
#include <errno.h>
#include <windows.h>
@@ -146,5 +289,4 @@ pthread_create(pthread_t *thread,
return ret;
}
-
-
+#endif /* Pre Bossom */