summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2001-03-30 23:06:39 (GMT)
committerandreas_kupries <akupries@shaw.ca>2001-03-30 23:06:39 (GMT)
commit48f8dee3a1a0e24705f0e328314065e9dc602993 (patch)
tree54aac1cde138798340a664ebb66533625a892063 /generic
parent04bc231d0eaa06994bc6cab2b61b518e200fab0c (diff)
downloadtcl-48f8dee3a1a0e24705f0e328314065e9dc602993.zip
tcl-48f8dee3a1a0e24705f0e328314065e9dc602993.tar.gz
tcl-48f8dee3a1a0e24705f0e328314065e9dc602993.tar.bz2
2001-03-30 Andreas Kupries <andreas_kupries@users.sourceforge.net>
* All of the changes below belong to TIP #10 [Tcl I/O Enhancement: Thread-Aware Channels]. See also [Patch #403358] at SF. * generic/tclIO.h (struct ChannelState, line 236f): Extended the structure with a new field of type 'Tcl_ThreadId' to hold the id of the thread currently managing all channels with this state. Note: This structure is shared by all channels in a stack of transformations. * generic/tclIO.c (Tcl_CreateChannel, lines 1058-1065): Modified to store the Id of the current thread in the 'ChannelState' of the new channel. * generic/tclIO.c (Tcl_SpliceChannel, lines 2265-2270): Modified in the same manner as 'Tcl_CreateChannel' as the channel will be managed by the current thread afterward. * generic/tclIO.c (Tcl_GetChannelThread, lines 1478-1503): * generic/tcl.decls (Tcl_GetChannelThread, lines 1504-1506): New API function to retrieve the Id of the managing thread from a channel. Implementation and declaration. * generic/tclTest.c (TestChannelCmd, lines 4520-4532): Added subcommand 'mthread' to query a channel about its managing thread.
Diffstat (limited to 'generic')
-rw-r--r--generic/tcl.decls5
-rw-r--r--generic/tclDecls.h10
-rw-r--r--generic/tclIO.c44
-rw-r--r--generic/tclIO.h4
-rw-r--r--generic/tclStubInit.c3
-rw-r--r--generic/tclTest.c14
6 files changed, 74 insertions, 6 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 6c1e790..ada4049 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -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: tcl.decls,v 1.43 2001/01/18 19:09:55 andreas_kupries Exp $
+# RCS: @(#) $Id: tcl.decls,v 1.44 2001/03/30 23:06:39 andreas_kupries Exp $
library tcl
@@ -1501,6 +1501,9 @@ declare 431 generic {
declare 432 generic {
int Tcl_AttemptSetObjLength(Tcl_Obj *objPtr, int length)
}
+declare 433 generic {
+ Tcl_ThreadId Tcl_GetChannelThread(Tcl_Channel channel)
+}
##############################################################################
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index 6caae64..06e9b89 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclDecls.h,v 1.45 2001/03/26 22:16:54 dgp Exp $
+ * RCS: @(#) $Id: tclDecls.h,v 1.46 2001/03/30 23:06:39 andreas_kupries Exp $
*/
#ifndef _TCLDECLS
@@ -1350,6 +1350,9 @@ EXTERN char * Tcl_AttemptDbCkrealloc _ANSI_ARGS_((char * ptr,
/* 432 */
EXTERN int Tcl_AttemptSetObjLength _ANSI_ARGS_((
Tcl_Obj * objPtr, int length));
+/* 433 */
+EXTERN Tcl_ThreadId Tcl_GetChannelThread _ANSI_ARGS_((
+ Tcl_Channel channel));
typedef struct TclStubHooks {
struct TclPlatStubs *tclPlatStubs;
@@ -1850,6 +1853,7 @@ typedef struct TclStubs {
char * (*tcl_AttemptRealloc) _ANSI_ARGS_((char * ptr, unsigned int size)); /* 430 */
char * (*tcl_AttemptDbCkrealloc) _ANSI_ARGS_((char * ptr, unsigned int size, char * file, int line)); /* 431 */
int (*tcl_AttemptSetObjLength) _ANSI_ARGS_((Tcl_Obj * objPtr, int length)); /* 432 */
+ Tcl_ThreadId (*tcl_GetChannelThread) _ANSI_ARGS_((Tcl_Channel channel)); /* 433 */
} TclStubs;
#ifdef __cplusplus
@@ -3630,6 +3634,10 @@ extern TclStubs *tclStubsPtr;
#define Tcl_AttemptSetObjLength \
(tclStubsPtr->tcl_AttemptSetObjLength) /* 432 */
#endif
+#ifndef Tcl_GetChannelThread
+#define Tcl_GetChannelThread \
+ (tclStubsPtr->tcl_GetChannelThread) /* 433 */
+#endif
#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 1718d15..2c1bc34 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -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: tclIO.c,v 1.28 2001/01/30 17:32:06 dgp Exp $
+ * RCS: @(#) $Id: tclIO.c,v 1.29 2001/03/30 23:06:39 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -1056,6 +1056,14 @@ Tcl_CreateChannel(typePtr, chanName, instanceData, mask)
tsdPtr->firstCSPtr = statePtr;
/*
+ * TIP #10. Mark the current thread as the one managing the new
+ * channel. Note: 'Tcl_GetCurrentThread' returns sensible
+ * values even for a non-threaded core.
+ */
+
+ statePtr->managingThread = Tcl_GetCurrentThread ();
+
+ /*
* Install this channel in the first empty standard channel slot, if
* the channel was previously closed explicitly.
*/
@@ -1471,6 +1479,32 @@ Tcl_GetChannelInstanceData(chan)
/*
*----------------------------------------------------------------------
*
+ * Tcl_GetChannelThread --
+ *
+ * Given a channel structure, returns the thread managing it.
+ * TIP #10
+ *
+ * Results:
+ * Returns the id of the thread managing the channel.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Tcl_ThreadId
+Tcl_GetChannelThread(chan)
+ Tcl_Channel chan; /* The channel to return managing thread for. */
+{
+ Channel *chanPtr = (Channel *) chan; /* The actual channel. */
+
+ return chanPtr->state->managingThread;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_GetChannelType --
*
* Given a channel structure, returns the channel type structure.
@@ -2254,6 +2288,14 @@ Tcl_SpliceChannel(chan)
statePtr->nextCSPtr = tsdPtr->firstCSPtr;
tsdPtr->firstCSPtr = statePtr;
+
+ /*
+ * TIP #10. Mark the current thread as the new one managing this
+ * channel. Note: 'Tcl_GetCurrentThread' returns sensible
+ * values even for a non-threaded core.
+ */
+
+ statePtr->managingThread = Tcl_GetCurrentThread ();
}
/*
diff --git a/generic/tclIO.h b/generic/tclIO.h
index b232cba..caac702 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -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: tclIO.h,v 1.2 2000/09/28 06:38:21 hobbs Exp $
+ * RCS: @(#) $Id: tclIO.h,v 1.3 2001/03/30 23:06:40 andreas_kupries Exp $
*/
/*
@@ -233,6 +233,8 @@ typedef struct ChannelState {
* long as the channel state. Never NULL. */
struct ChannelState *nextCSPtr;
/* Next in list of channels currently open. */
+ Tcl_ThreadId managingThread; /* TIP #10: Id of the thread managing
+ * this stack of channels. */
} ChannelState;
/*
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index cb42cc0..35fada8 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStubInit.c,v 1.47 2001/01/18 19:09:55 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclStubInit.c,v 1.48 2001/03/30 23:06:40 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -836,6 +836,7 @@ TclStubs tclStubs = {
Tcl_AttemptRealloc, /* 430 */
Tcl_AttemptDbCkrealloc, /* 431 */
Tcl_AttemptSetObjLength, /* 432 */
+ Tcl_GetChannelThread, /* 433 */
};
/* !END!: Do not edit above this line. */
diff --git a/generic/tclTest.c b/generic/tclTest.c
index c27e7e2..1aa28d2 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTest.c,v 1.22 2000/11/24 11:27:37 dkf Exp $
+ * RCS: @(#) $Id: tclTest.c,v 1.23 2001/03/30 23:06:40 andreas_kupries Exp $
*/
#define TCL_TEST
@@ -4517,6 +4517,18 @@ TestChannelCmd(clientData, interp, argc, argv)
return TCL_OK;
}
+ if ((cmdName[0] == 'm') && (strncmp(cmdName, "mthread", len) == 0)) {
+ if (argc != 3) {
+ Tcl_AppendResult(interp, "channel name required",
+ (char *) NULL);
+ return TCL_ERROR;
+ }
+
+ TclFormatInt(buf, Tcl_GetChannelThread (chan));
+ Tcl_AppendResult(interp, buf, (char *) NULL);
+ return TCL_OK;
+ }
+
if ((cmdName[0] == 'n') && (strncmp(cmdName, "name", len) == 0)) {
if (argc != 3) {
Tcl_AppendResult(interp, "channel name required",