Attachment "threadCreate.diff" to
ticket [770053ffff]
added by
vasiljevic
2004-06-21 18:46:47.
--- generic/tclEvent.c 2004-06-21 13:17:30.000000000 +0200
+++ generic/tclEvent.c.patch 2004-06-21 13:11:16.000000000 +0200
@@ -104,6 +104,17 @@
*/
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 @@
* 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 @@
#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_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 */
+}
--- generic/tclInt.h 2004-06-21 13:17:31.000000000 +0200
+++ generic/tclInt.h.patch 2004-06-21 11:17:41.000000000 +0200
@@ -1764,6 +1764,11 @@
Tcl_ThreadDataKey *keyPtr));
EXTERN void TclpThreadDataKeySet _ANSI_ARGS_((
Tcl_ThreadDataKey *keyPtr, VOID *data));
+EXTERN int TclpThreadCreate _ANSI_ARGS_((
+ Tcl_ThreadId *idPtr,
+ Tcl_ThreadCreateProc proc,
+ ClientData clientData,
+ int stackSize, int flags));
EXTERN void TclpThreadExit _ANSI_ARGS_((int status));
EXTERN void TclRememberCondition _ANSI_ARGS_((Tcl_Condition *mutex));
EXTERN void TclRememberDataKey _ANSI_ARGS_((Tcl_ThreadDataKey *mutex));
--- unix/tclUnixNotfy.c 2004-06-21 13:17:31.000000000 +0200
+++ unix/tclUnixNotfy.c.patch 2004-06-21 11:09:06.000000000 +0200
@@ -208,7 +208,7 @@
Tcl_MutexLock(¬ifierMutex);
if (notifierCount == 0) {
- if (Tcl_CreateThread(¬ifierThread, NotifierThreadProc, NULL,
+ if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL,
TCL_THREAD_STACK_DEFAULT, TCL_THREAD_NOFLAGS) != TCL_OK) {
panic("Tcl_InitNotifier: unable to start notifier thread");
}
--- unix/tclUnixThrd.c 2004-06-21 13:17:32.000000000 +0200
+++ unix/tclUnixThrd.c.patch 2004-06-21 11:44:12.000000000 +0200
@@ -66,7 +66,7 @@
/*
*----------------------------------------------------------------------
*
- * Tcl_CreateThread --
+ * TclpThreadCreate --
*
* This procedure creates a new thread.
*
@@ -81,7 +81,7 @@
*/
int
-Tcl_CreateThread(idPtr, proc, clientData, stackSize, flags)
+TclpThreadCreate(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() */
--- win/tclWinThrd.c 2004-06-21 13:17:32.000000000 +0200
+++ win/tclWinThrd.c.patch 2004-06-21 13:13:51.000000000 +0200
@@ -115,7 +115,7 @@
/*
*----------------------------------------------------------------------
*
- * Tcl_CreateThread --
+ * TclpThreadCreate --
*
* This procedure creates a new thread.
*
@@ -130,7 +130,7 @@
*/
int
-Tcl_CreateThread(idPtr, proc, clientData, stackSize, flags)
+TclpThreadCreate(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() */