diff options
author | vasiljevic <zv@archiware.com> | 2004-06-22 13:08:57 (GMT) |
---|---|---|
committer | vasiljevic <zv@archiware.com> | 2004-06-22 13:08:57 (GMT) |
commit | 46b6468bc248717205ebb258ae6af7287fa77d22 (patch) | |
tree | 4a186fef042b244b7baa23990f6ebda5fb241e00 | |
parent | a7d93e405d7c52890ac2b6451680ed32574c2f18 (diff) | |
download | tcl-46b6468bc248717205ebb258ae6af7287fa77d22.zip tcl-46b6468bc248717205ebb258ae6af7287fa77d22.tar.gz tcl-46b6468bc248717205ebb258ae6af7287fa77d22.tar.bz2 |
Integrated fix for Tcl Bug #770053 from core-8-4-branch
-rw-r--r-- | generic/tclEvent.c | 91 | ||||
-rw-r--r-- | generic/tclInt.h | 9 | ||||
-rw-r--r-- | tests/unixNotfy.test | 16 | ||||
-rw-r--r-- | unix/tclUnixNotfy.c | 4 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 4 | ||||
-rw-r--r-- | win/tclWinThrd.c | 6 |
6 files changed, 111 insertions, 19 deletions
diff --git a/generic/tclEvent.c b/generic/tclEvent.c index bc307dc..6148f84 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.37 2004/05/13 12:59:21 dkf Exp $ + * RCS: @(#) $Id: tclEvent.c,v 1.38 2004/06/22 13:08:57 vasiljevic Exp $ */ #include "tclInt.h" @@ -111,6 +111,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: */ @@ -1216,3 +1227,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 */ +} diff --git a/generic/tclInt.h b/generic/tclInt.h index 6723f03..6b16f7b 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -6,13 +6,13 @@ * Copyright (c) 1987-1993 The Regents of the University of California. * Copyright (c) 1993-1997 Lucent Technologies. * Copyright (c) 1994-1998 Sun Microsystems, Inc. - * Copyright (c) 1998-1999 by Scriptics Corporation. + * Copyright (c) 1998-19/99 by Scriptics Corporation. * Copyright (c) 2001, 2002 by Kevin B. Kenny. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.165 2004/06/18 20:38:01 dgp Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.166 2004/06/22 13:08:59 vasiljevic Exp $ */ #ifndef _TCLINT @@ -1820,6 +1820,11 @@ EXTERN void TclpFinalizeCondition _ANSI_ARGS_(( EXTERN void TclpFinalizeMutex _ANSI_ARGS_((Tcl_Mutex *mutexPtr)); EXTERN void TclpFinalizeThreadData _ANSI_ARGS_(( Tcl_ThreadDataKey *keyPtr)); +EXTERN int TclpThreadCreate _ANSI_ARGS_(( + Tcl_ThreadId *idPtr, + Tcl_ThreadCreateProc proc, + ClientData clientData, + int stackSize, int flags)); EXTERN void TclpFinalizeThreadDataKey _ANSI_ARGS_(( Tcl_ThreadDataKey *keyPtr)); EXTERN char * TclpFindExecutable _ANSI_ARGS_(( diff --git a/tests/unixNotfy.test b/tests/unixNotfy.test index 2840813..49dc015 100644 --- a/tests/unixNotfy.test +++ b/tests/unixNotfy.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: unixNotfy.test,v 1.14 2004/05/19 20:15:32 dkf Exp $ +# RCS: @(#) $Id: unixNotfy.test,v 1.15 2004/06/22 13:09:02 vasiljevic Exp $ # The tests should not be run if you have a notifier which is unable to # detect infinite vwaits, as the tests below will hang. The presence of @@ -74,10 +74,9 @@ test unixNotfy-2.1 {Tcl_DeleteFileHandler} \ fileevent $f writable {set x 1} vwait x close $f - testthread create "after 500 - testthread send [testthread id] {set x ok} - testthread exit" + testthread create "testthread send [testthread id] {set x ok}" vwait x + threadReap set x } \ -result {ok} \ @@ -97,11 +96,10 @@ test unixNotfy-2.2 {Tcl_DeleteFileHandler} \ close $f1 vwait y close $f2 - testthread create "after 500 - testthread send [testthread id] {set x ok} - testthread exit" - vwait x - set x + testthread create "testthread send [testthread id] {set x ok}" + vwait x + threadReap + set x } \ -result {ok} \ -cleanup { diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index 679da4d..6c0a6ca 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.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: tclUnixNotfy.c,v 1.15 2004/04/06 22:25:57 dgp Exp $ + * RCS: @(#) $Id: tclUnixNotfy.c,v 1.16 2004/06/22 13:09:00 vasiljevic Exp $ */ #include "tclInt.h" @@ -207,7 +207,7 @@ Tcl_InitNotifier() 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) { Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread"); } diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 56745b0..297fc3b 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -65,7 +65,7 @@ static pthread_mutex_t *allocLockPtr = &allocLock; /* *---------------------------------------------------------------------- * - * Tcl_CreateThread -- + * TclpThreadCreaet -- * * This procedure creates a new thread. * @@ -80,7 +80,7 @@ static pthread_mutex_t *allocLockPtr = &allocLock; */ 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() */ diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c index 88e2cda..1194fcc 100644 --- a/win/tclWinThrd.c +++ b/win/tclWinThrd.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinThrd.c,v 1.30 2004/04/27 17:17:37 davygrvy Exp $ + * RCS: @(#) $Id: tclWinThrd.c,v 1.31 2004/06/22 13:09:01 vasiljevic Exp $ */ #include "tclWinInt.h" @@ -115,7 +115,7 @@ typedef struct WinCondition { /* *---------------------------------------------------------------------- * - * Tcl_CreateThread -- + * TclpThreadCreate -- * * This procedure creates a new thread. * @@ -130,7 +130,7 @@ typedef struct WinCondition { */ 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() */ |