diff options
Diffstat (limited to 'generic/tclThreadTest.c')
| -rw-r--r-- | generic/tclThreadTest.c | 37 | 
1 files changed, 22 insertions, 15 deletions
| diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index 71d5a66..02ee038 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -46,7 +46,7 @@ static Tcl_ThreadDataKey dataKey;   * protected by threadMutex.   */ -static ThreadSpecificData *threadList; +static ThreadSpecificData *threadList = NULL;  /*   * The following bit-values are legal for the "flags" field of the @@ -337,7 +337,7 @@ ThreadObjCmd(  	     */  	    if (objc == 2) { -		idObj = Tcl_NewLongObj((long)(size_t)Tcl_GetCurrentThread()); +		idObj = Tcl_NewWideIntObj((Tcl_WideInt)(size_t)Tcl_GetCurrentThread());  	    } else if (objc == 3  		    && strcmp("-main", Tcl_GetString(objv[2])) == 0) {  		Tcl_MutexLock(&threadMutex); @@ -355,14 +355,14 @@ ThreadObjCmd(  	    return TCL_ERROR;  	}      case THREAD_JOIN: { -	long id; +	Tcl_WideInt id;  	int result, status;  	if (objc != 3) {  	    Tcl_WrongNumArgs(interp, 2, objv, "id");  	    return TCL_ERROR;  	} -	if (Tcl_GetLongFromObj(interp, objv[2], &id) != TCL_OK) { +	if (Tcl_GetWideIntFromObj(interp, objv[2], &id) != TCL_OK) {  	    return TCL_ERROR;  	} @@ -372,7 +372,7 @@ ThreadObjCmd(  	} else {  	    char buf[20]; -	    TclFormatInt(buf, id); +	    sprintf(buf, "%" TCL_LL_MODIFIER "d", id);  	    Tcl_AppendResult(interp, "cannot join thread ", buf, NULL);  	}  	return result; @@ -384,7 +384,7 @@ ThreadObjCmd(  	}  	return ThreadList(interp);      case THREAD_SEND: { -	long id; +	Tcl_WideInt id;  	const char *script;  	int wait, arg; @@ -403,7 +403,7 @@ ThreadObjCmd(  	    wait = 1;  	    arg = 2;  	} -	if (Tcl_GetLongFromObj(interp, objv[arg], &id) != TCL_OK) { +	if (Tcl_GetWideIntFromObj(interp, objv[arg], &id) != TCL_OK) {  	    return TCL_ERROR;  	}  	arg++; @@ -513,7 +513,6 @@ ThreadCreate(  	    TCL_THREAD_STACK_DEFAULT, joinable) != TCL_OK) {  	Tcl_MutexUnlock(&threadMutex);  	Tcl_AppendResult(interp, "can't create a new thread", NULL); -	ckfree(ctrl.script);  	return TCL_ERROR;      } @@ -524,7 +523,7 @@ ThreadCreate(      Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);      Tcl_MutexUnlock(&threadMutex);      Tcl_ConditionFinalize(&ctrl.condWait); -    Tcl_SetObjResult(interp, Tcl_NewLongObj((long)(size_t)id)); +    Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt)(size_t)id));      return TCL_OK;  } @@ -623,9 +622,9 @@ NewTestThread(       * Clean up.       */ -    ListRemove(tsdPtr); -    Tcl_Release(tsdPtr->interp);      Tcl_DeleteInterp(tsdPtr->interp); +    Tcl_Release(tsdPtr->interp); +    ListRemove(tsdPtr);      Tcl_ExitThread(result);      TCL_THREAD_CREATE_RETURN; @@ -656,7 +655,7 @@ ThreadErrorProc(      char *script;      char buf[TCL_DOUBLE_SPACE+1]; -    TclFormatInt(buf, (size_t) Tcl_GetCurrentThread()); +    sprintf(buf, "%" TCL_LL_MODIFIER "d", (Tcl_WideInt)(size_t)Tcl_GetCurrentThread());      errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);      if (errorProcString == NULL) { @@ -744,6 +743,7 @@ ListRemove(  	tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr;      }      tsdPtr->nextPtr = tsdPtr->prevPtr = 0; +    tsdPtr->interp = NULL;      Tcl_MutexUnlock(&threadMutex);  } @@ -773,7 +773,7 @@ ThreadList(      Tcl_MutexLock(&threadMutex);      for (tsdPtr = threadList ; tsdPtr ; tsdPtr = tsdPtr->nextPtr) {  	Tcl_ListObjAppendElement(interp, listPtr, -		Tcl_NewLongObj((long)(size_t)tsdPtr->threadId)); +		Tcl_NewWideIntObj((Tcl_WideInt)(size_t)tsdPtr->threadId));      }      Tcl_MutexUnlock(&threadMutex);      Tcl_SetObjResult(interp, listPtr); @@ -926,10 +926,11 @@ ThreadSend(  	    ckfree(resultPtr->errorInfo);  	}      } -    Tcl_SetResult(interp, resultPtr->result, TCL_DYNAMIC); +    Tcl_AppendResult(interp, resultPtr->result, NULL);      Tcl_ConditionFinalize(&resultPtr->done);      code = resultPtr->code; +    ckfree(resultPtr->result);      ckfree(resultPtr);      return code; @@ -987,7 +988,8 @@ ThreadCancel(      Tcl_MutexUnlock(&threadMutex);      Tcl_ResetResult(interp); -    return Tcl_CancelEval(tsdPtr->interp, Tcl_NewStringObj(result, -1), 0, flags); +    return Tcl_CancelEval(tsdPtr->interp, +    	(result != NULL) ? Tcl_NewStringObj(result, -1) : NULL, 0, flags);  }  /* @@ -1148,6 +1150,11 @@ ThreadExitProc(      char *threadEvalScript = clientData;      ThreadEventResult *resultPtr, *nextPtr;      Tcl_ThreadId self = Tcl_GetCurrentThread(); +    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + +    if (tsdPtr->interp != NULL) { +	ListRemove(tsdPtr); +    }      Tcl_MutexLock(&threadMutex); | 
