Diff
Not logged in

Differences From Artifact [5ebe45b550]:

To Artifact [78502e9797]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* 
 * tclThreadTest.c --
 *
 *	This file implements the testthread command.  Eventually this
 *	should be tclThreadCmd.c
 *	Some of this code is based on work done by Richard Hipp on behalf of
 *	Conservation Through Innovation, Limited, with their permission.
 *
 * Copyright (c) 1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclThreadTest.c,v 1.4 1999/10/21 02:16:22 hobbs Exp $
 */

#include "tclInt.h"

#ifdef TCL_THREADS
/*
 * Each thread has an single instance of the following structure.  There













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* 
 * tclThreadTest.c --
 *
 *	This file implements the testthread command.  Eventually this
 *	should be tclThreadCmd.c
 *	Some of this code is based on work done by Richard Hipp on behalf of
 *	Conservation Through Innovation, Limited, with their permission.
 *
 * Copyright (c) 1998 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclThreadTest.c,v 1.5 1999/12/21 23:58:04 hobbs Exp $
 */

#include "tclInt.h"

#ifdef TCL_THREADS
/*
 * Each thread has an single instance of the following structure.  There
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
	    }
	    ListRemove(NULL);
	    Tcl_ExitThread(0);
	    return TCL_OK;
	}
	case THREAD_ID:
	    if (objc == 2) {
		Tcl_Obj *idObj = Tcl_NewIntObj((int)Tcl_GetCurrentThread());
		Tcl_SetObjResult(interp, idObj);
		return TCL_OK;
	    } else {
		Tcl_WrongNumArgs(interp, 2, objv, NULL);
		return TCL_ERROR;
	    }
	case THREAD_NAMES: {
	    if (objc > 2) {
		Tcl_WrongNumArgs(interp, 2, objv, NULL);
		return TCL_ERROR;
	    }
	    return TclThreadList(interp);
	}
	case THREAD_SEND: {
	    int id;
	    char *script;
	    int wait, arg;

	    if ((objc != 4) && (objc != 5)) {
		Tcl_WrongNumArgs(interp, 1, objv, "send ?-async? id script");
		return TCL_ERROR;
	    }
	    if (objc == 5) {
		if (strcmp("-async", Tcl_GetString(objv[2])) != 0) {
		    Tcl_WrongNumArgs(interp, 1, objv, "send ?-async? id script");
		    return TCL_ERROR;
		}
		wait = 0;
		arg = 3;
	    } else {
		wait = 1;
		arg = 2;
	    }
	    if (Tcl_GetIntFromObj(interp, objv[arg], &id) != TCL_OK) {
		return TCL_ERROR;
	    }
	    arg++;
	    script = Tcl_GetString(objv[arg]);
	    return TclThreadSend(interp, (Tcl_ThreadId) id, script, wait);
	}
	case THREAD_WAIT: {







|














|


















|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
	    }
	    ListRemove(NULL);
	    Tcl_ExitThread(0);
	    return TCL_OK;
	}
	case THREAD_ID:
	    if (objc == 2) {
		Tcl_Obj *idObj = Tcl_NewLongObj((long)Tcl_GetCurrentThread());
		Tcl_SetObjResult(interp, idObj);
		return TCL_OK;
	    } else {
		Tcl_WrongNumArgs(interp, 2, objv, NULL);
		return TCL_ERROR;
	    }
	case THREAD_NAMES: {
	    if (objc > 2) {
		Tcl_WrongNumArgs(interp, 2, objv, NULL);
		return TCL_ERROR;
	    }
	    return TclThreadList(interp);
	}
	case THREAD_SEND: {
	    long id;
	    char *script;
	    int wait, arg;

	    if ((objc != 4) && (objc != 5)) {
		Tcl_WrongNumArgs(interp, 1, objv, "send ?-async? id script");
		return TCL_ERROR;
	    }
	    if (objc == 5) {
		if (strcmp("-async", Tcl_GetString(objv[2])) != 0) {
		    Tcl_WrongNumArgs(interp, 1, objv, "send ?-async? id script");
		    return TCL_ERROR;
		}
		wait = 0;
		arg = 3;
	    } else {
		wait = 1;
		arg = 2;
	    }
	    if (Tcl_GetLongFromObj(interp, objv[arg], &id) != TCL_OK) {
		return TCL_ERROR;
	    }
	    arg++;
	    script = Tcl_GetString(objv[arg]);
	    return TclThreadSend(interp, (Tcl_ThreadId) id, script, wait);
	}
	case THREAD_WAIT: {
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
    /*
     * Wait for the thread to start because it is using something on our stack!
     */

    Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);
    Tcl_MutexUnlock(&threadMutex);
    TclFinalizeCondition(&ctrl.condWait);
    Tcl_SetObjResult(interp, Tcl_NewIntObj((int)id));
    return TCL_OK;
}

/*
 *------------------------------------------------------------------------
 *
 * NewThread --







|







369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
    /*
     * Wait for the thread to start because it is using something on our stack!
     */

    Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);
    Tcl_MutexUnlock(&threadMutex);
    TclFinalizeCondition(&ctrl.condWait);
    Tcl_SetObjResult(interp, Tcl_NewLongObj((long)id));
    return TCL_OK;
}

/*
 *------------------------------------------------------------------------
 *
 * NewThread --
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
    ThreadSpecificData *tsdPtr;
    Tcl_Obj *listPtr;

    listPtr = Tcl_NewListObj(0, NULL);
    Tcl_MutexLock(&threadMutex);
    for (tsdPtr = threadList ; tsdPtr ; tsdPtr = tsdPtr->nextPtr) {
	Tcl_ListObjAppendElement(interp, listPtr,
		Tcl_NewIntObj((int)tsdPtr->threadId));
    }
    Tcl_MutexUnlock(&threadMutex);
    Tcl_SetObjResult(interp, listPtr);
    return TCL_OK;
}









|







606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
    ThreadSpecificData *tsdPtr;
    Tcl_Obj *listPtr;

    listPtr = Tcl_NewListObj(0, NULL);
    Tcl_MutexLock(&threadMutex);
    for (tsdPtr = threadList ; tsdPtr ; tsdPtr = tsdPtr->nextPtr) {
	Tcl_ListObjAppendElement(interp, listPtr,
		Tcl_NewLongObj((long)tsdPtr->threadId));
    }
    Tcl_MutexUnlock(&threadMutex);
    Tcl_SetObjResult(interp, listPtr);
    return TCL_OK;
}