summaryrefslogtreecommitdiffstats
path: root/generic/tclEvent.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclEvent.c')
-rw-r--r--generic/tclEvent.c96
1 files changed, 93 insertions, 3 deletions
diff --git a/generic/tclEvent.c b/generic/tclEvent.c
index eacf41b..c6d7d65 100644
--- a/generic/tclEvent.c
+++ b/generic/tclEvent.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEvent.c,v 1.28.2.3 2004/05/06 01:17:41 davygrvy Exp $
+ * RCS: @(#) $Id: tclEvent.c,v 1.28.2.4 2004/06/22 11:55:35 vasiljevic Exp $
*/
#include "tclInt.h"
@@ -104,6 +104,17 @@ static Tcl_ThreadDataKey dataKey;
*/
static char *tclLibraryPathStr = NULL;
+
+#ifdef TCL_THREADS
+
+typedef struct {
+ Tcl_ThreadCreateProc *proc; /* Main() function of the thread */
+ ClientData clientData; /* The one argument to Main() */
+} ThreadClientData;
+static Tcl_ThreadCreateType NewThreadProc _ANSI_ARGS_((
+ ClientData clientData));
+#endif
+
/*
* Prototypes for procedures referenced only in this file:
*/
@@ -720,6 +731,7 @@ TclInitSubsystems(argv0)
* interesting happens so we can use the allocators in the
* implementation of self-initializing locks.
*/
+
#if USE_TCLALLOC
TclInitAlloc(); /* process wide mutex init */
#endif
@@ -728,10 +740,10 @@ TclInitSubsystems(argv0)
#endif
TclpInitPlatform(); /* creates signal handler(s) */
- TclInitObjSubsystem(); /* register obj types, create mutexes */
+ TclInitObjSubsystem(); /* register obj types, create mutexes */
TclInitIOSubsystem(); /* inits a tsd key (noop) */
TclInitEncodingSubsystem(); /* process wide encoding init */
- TclInitNamespaceSubsystem(); /* register ns obj type (mutexed) */
+ TclInitNamespaceSubsystem(); /* register ns obj type (mutexed) */
}
TclpInitUnlock();
}
@@ -1148,3 +1160,81 @@ Tcl_UpdateObjCmd(clientData, interp, objc, objv)
Tcl_ResetResult(interp);
return TCL_OK;
}
+
+#ifdef TCL_THREADS
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * NewThreadProc --
+ *
+ * Bootstrap function of a new Tcl thread.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * Initializes Tcl notifier for the current thread.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static Tcl_ThreadCreateType
+NewThreadProc(ClientData clientData)
+{
+ ThreadClientData *cdPtr;
+ ClientData threadClientData;
+ Tcl_ThreadCreateProc *threadProc;
+
+ TCL_TSD_INIT(&dataKey);
+
+ cdPtr = (ThreadClientData*)clientData;
+ threadProc = cdPtr->proc;
+ threadClientData = cdPtr->clientData;
+ Tcl_Free((char*)clientData); /* Allocated in Tcl_CreateThread() */
+
+ TclInitNotifier();
+
+ (*threadProc)(threadClientData);
+}
+#endif
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_CreateThread --
+ *
+ * This procedure creates a new thread. This actually belongs
+ * to the tclThread.c file but since we use some private
+ * data structures local to this file, it is placed here.
+ *
+ * Results:
+ * TCL_OK if the thread could be created. The thread ID is
+ * returned in a parameter.
+ *
+ * Side effects:
+ * A new thread is created.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_CreateThread(idPtr, proc, clientData, stackSize, flags)
+ Tcl_ThreadId *idPtr; /* Return, the ID of the thread */
+ Tcl_ThreadCreateProc proc; /* Main() function of the thread */
+ ClientData clientData; /* The one argument to Main() */
+ int stackSize; /* Size of stack for the new thread */
+ int flags; /* Flags controlling behaviour of
+ * the new thread */
+{
+#ifdef TCL_THREADS
+ ThreadClientData *cdPtr;
+
+ cdPtr = (ThreadClientData*)Tcl_Alloc(sizeof(ThreadClientData));
+ cdPtr->proc = proc;
+ cdPtr->clientData = clientData;
+
+ return TclpThreadCreate(idPtr, NewThreadProc, (ClientData)cdPtr,
+ stackSize, flags);
+#else
+ return TCL_ERROR;
+#endif /* TCL_THREADS */
+}