From 31b544baefc9bf84fded3c7dfb98da9db1032e10 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 15 Aug 2021 21:34:02 +0000 Subject: Make TCL_QUEUE_ALERT_IF_EMPTY a separate flag --- doc/Notifier.3 | 15 +++++---------- generic/tcl.decls | 4 ++-- generic/tcl.h | 22 +++------------------- generic/tclDecls.h | 9 ++++----- generic/tclIORChan.c | 4 ++-- generic/tclIORTrans.c | 2 +- generic/tclNotify.c | 33 +++++++++++++++------------------ generic/tclTest.c | 2 +- generic/tclThreadTest.c | 2 +- 9 files changed, 34 insertions(+), 59 deletions(-) diff --git a/doc/Notifier.3 b/doc/Notifier.3 index 755930f..3fb13a2 100644 --- a/doc/Notifier.3 +++ b/doc/Notifier.3 @@ -90,11 +90,10 @@ necessary. .AP Tcl_Event *evPtr in An event to add to the event queue. The storage for the event must have been allocated by the caller using \fBTcl_Alloc\fR or \fBckalloc\fR. -.AP Tcl_QueuePosition position in +.AP int flags in Where to add the new event in the queue: \fBTCL_QUEUE_TAIL\fR, -\fBTCL_QUEUE_HEAD\fR, \fBTCL_QUEUE_MARK\fR, -\fBTCL_QUEUE_TAIL_ALERT_IF_EMPTY\fR, or -\fBTCL_QUEUE_HEAD_ALERT_IF_EMPTY\fR. +\fBTCL_QUEUE_HEAD\fR, \fBTCL_QUEUE_MARK\fR, and whether to do +an alert if the queue is empty: \fBTCL_QUEUE_ALERT_IF_EMPTY\fR. .AP Tcl_ThreadId threadId in A unique identifier for a thread. .AP Tcl_EventDeleteProc *deleteProc in @@ -357,12 +356,8 @@ This value of \fIposition\fR is used to insert an ordered sequence of events at the front of the queue, such as a series of Enter and Leave events synthesized during a grab or ungrab operation in Tk. -.IP \fBTCL_QUEUE_TAIL_ALERT_IF_EMPTY\fR 32 -Like \fBTCL_QUEUE_TAIL\fR but when used in \fBTcl_ThreadQueueEvent\fR -arranges for an automatic call of \fBTcl_ThreadAlert\fR when the queue was -empty. -.IP \fBTCL_QUEUE_HEAD_ALERT_IF_EMPTY\fR 32 -Like \fBTCL_QUEUE_HEAD\fR but when used in \fBTcl_ThreadQueueEvent\fR +.IP \fBTCL_QUEUE_ALERT_IF_EMPTY\fR 32 +When used in \fBTcl_ThreadQueueEvent\fR arranges for an automatic call of \fBTcl_ThreadAlert\fR when the queue was empty. .PP diff --git a/generic/tcl.decls b/generic/tcl.decls index 3dec972..a1bf91b 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -732,7 +732,7 @@ declare 204 { const char *Tcl_PosixError(Tcl_Interp *interp) } declare 205 { - void Tcl_QueueEvent(Tcl_Event *evPtr, Tcl_QueuePosition position) + void Tcl_QueueEvent(Tcl_Event *evPtr, int flags) } declare 206 { int Tcl_Read(Tcl_Channel chan, char *bufPtr, int toRead) @@ -1142,7 +1142,7 @@ declare 318 { } declare 319 { void Tcl_ThreadQueueEvent(Tcl_ThreadId threadId, Tcl_Event *evPtr, - Tcl_QueuePosition position) + int flags) } declare 320 { int Tcl_UniCharAtIndex(const char *src, int index) diff --git a/generic/tcl.h b/generic/tcl.h index 1ce68b4..4316f50 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -1329,31 +1329,15 @@ struct Tcl_Event { }; /* - * Positions to pass to Tcl_QueueEvent: + * Positions to pass to Tcl_QueueEvent/Tcl_ThreadQueueEvent: */ typedef enum { - TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, TCL_QUEUE_MARK + TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, TCL_QUEUE_MARK, + TCL_QUEUE_ALERT_IF_EMPTY=4 } Tcl_QueuePosition; /* - * Positions for Tcl_ThreadQueueEvent: - */ - -typedef enum { - TCL_QUEUE_TAIL_EX = TCL_QUEUE_TAIL, - TCL_QUEUE_HEAD_EX = TCL_QUEUE_HEAD, - TCL_QUEUE_MARK_EX = TCL_QUEUE_MARK, - TCL_QUEUE_TAIL_EX_ALERT_IF_EMPTY, - TCL_QUEUE_HEAD_EX_ALERT_IF_EMPTY, -} Tcl_QueuePositionEx; - -#define TCL_QUEUE_TAIL_ALERT_IF_EMPTY \ - ((Tcl_QueuePosition) TCL_QUEUE_TAIL_EX_ALERT_IF_EMPTY) -#define TCL_QUEUE_HEAD_ALERT_IF_EMPTY \ - ((Tcl_QueuePosition) TCL_QUEUE_HEAD_EX_ALERT_IF_EMPTY) - -/* * Values to pass to Tcl_SetServiceMode to specify the behavior of notifier * event routines. */ diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 713f3e9..fb22928 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -644,8 +644,7 @@ EXTERN int Tcl_PutEnv(const char *assignment); /* 204 */ EXTERN const char * Tcl_PosixError(Tcl_Interp *interp); /* 205 */ -EXTERN void Tcl_QueueEvent(Tcl_Event *evPtr, - Tcl_QueuePosition position); +EXTERN void Tcl_QueueEvent(Tcl_Event *evPtr, int flags); /* 206 */ EXTERN int Tcl_Read(Tcl_Channel chan, char *bufPtr, int toRead); /* 207 */ @@ -985,7 +984,7 @@ EXTERN Tcl_Obj * Tcl_SetVar2Ex(Tcl_Interp *interp, const char *part1, EXTERN void Tcl_ThreadAlert(Tcl_ThreadId threadId); /* 319 */ EXTERN void Tcl_ThreadQueueEvent(Tcl_ThreadId threadId, - Tcl_Event *evPtr, Tcl_QueuePosition position); + Tcl_Event *evPtr, int flags); /* 320 */ EXTERN int Tcl_UniCharAtIndex(const char *src, int index); /* 321 */ @@ -2179,7 +2178,7 @@ typedef struct TclStubs { void (*tcl_PrintDouble) (Tcl_Interp *interp, double value, char *dst); /* 202 */ int (*tcl_PutEnv) (const char *assignment); /* 203 */ const char * (*tcl_PosixError) (Tcl_Interp *interp); /* 204 */ - void (*tcl_QueueEvent) (Tcl_Event *evPtr, Tcl_QueuePosition position); /* 205 */ + void (*tcl_QueueEvent) (Tcl_Event *evPtr, int flags); /* 205 */ int (*tcl_Read) (Tcl_Channel chan, char *bufPtr, int toRead); /* 206 */ void (*tcl_ReapDetachedProcs) (void); /* 207 */ int (*tcl_RecordAndEval) (Tcl_Interp *interp, const char *cmd, int flags); /* 208 */ @@ -2293,7 +2292,7 @@ typedef struct TclStubs { int (*tcl_SetSystemEncoding) (Tcl_Interp *interp, const char *name); /* 316 */ Tcl_Obj * (*tcl_SetVar2Ex) (Tcl_Interp *interp, const char *part1, const char *part2, Tcl_Obj *newValuePtr, int flags); /* 317 */ void (*tcl_ThreadAlert) (Tcl_ThreadId threadId); /* 318 */ - void (*tcl_ThreadQueueEvent) (Tcl_ThreadId threadId, Tcl_Event *evPtr, Tcl_QueuePosition position); /* 319 */ + void (*tcl_ThreadQueueEvent) (Tcl_ThreadId threadId, Tcl_Event *evPtr, int flags); /* 319 */ int (*tcl_UniCharAtIndex) (const char *src, int index); /* 320 */ int (*tcl_UniCharToLower) (int ch); /* 321 */ int (*tcl_UniCharToTitle) (int ch); /* 322 */ diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c index b473417..3f8a51e 100644 --- a/generic/tclIORChan.c +++ b/generic/tclIORChan.c @@ -995,7 +995,7 @@ TclChanPostEventObjCmd( */ Tcl_ThreadQueueEvent(rcPtr->owner, (Tcl_Event *) ev, - TCL_QUEUE_TAIL_ALERT_IF_EMPTY); + TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); } #endif @@ -2997,7 +2997,7 @@ ForwardOpToHandlerThread( */ Tcl_ThreadQueueEvent(dst, (Tcl_Event *) evPtr, - TCL_QUEUE_TAIL_ALERT_IF_EMPTY); + TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); /* * (*) Block until the handler thread has either processed the transfer or diff --git a/generic/tclIORTrans.c b/generic/tclIORTrans.c index eda72ba..1d66835 100644 --- a/generic/tclIORTrans.c +++ b/generic/tclIORTrans.c @@ -2453,7 +2453,7 @@ ForwardOpToOwnerThread( */ Tcl_ThreadQueueEvent(dst, (Tcl_Event *) evPtr, - TCL_QUEUE_TAIL_ALERT_IF_EMPTY); + TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); /* * (*) Block until the other thread has either processed the transfer or diff --git a/generic/tclNotify.c b/generic/tclNotify.c index 99aceec..fa85f95 100644 --- a/generic/tclNotify.c +++ b/generic/tclNotify.c @@ -96,7 +96,7 @@ TCL_DECLARE_MUTEX(listLock) */ static int QueueEvent(ThreadSpecificData *tsdPtr, - Tcl_Event *evPtr, Tcl_QueuePositionEx position); + Tcl_Event *evPtr, int flags); /* *---------------------------------------------------------------------- @@ -392,12 +392,12 @@ Tcl_QueueEvent( * malloc (ckalloc), and it becomes the * property of the event queue. It will be * freed after the event has been handled. */ - Tcl_QueuePosition position) /* One of TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, - * TCL_QUEUE_MARK. */ + int flags) /* One of TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, + * TCL_QUEUE_MARK, possibly combined with TCL_QUEUE_ALERT_IF_EMPTY. */ { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - (void) QueueEvent(tsdPtr, evPtr, (Tcl_QueuePositionEx) position); + (void) QueueEvent(tsdPtr, evPtr, flags); } /* @@ -424,8 +424,8 @@ Tcl_ThreadQueueEvent( * malloc (ckalloc), and it becomes the * property of the event queue. It will be * freed after the event has been handled. */ - Tcl_QueuePosition position) /* One of TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, - * TCL_QUEUE_MARK. */ + int flags) /* One of TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, + * TCL_QUEUE_MARK, possibly combined with TCL_QUEUE_ALERT_IF_EMPTY. */ { ThreadSpecificData *tsdPtr; @@ -444,7 +444,7 @@ Tcl_ThreadQueueEvent( */ if (tsdPtr) { - if (QueueEvent(tsdPtr, evPtr, (Tcl_QueuePositionEx) position)) { + if (QueueEvent(tsdPtr, evPtr, flags)) { Tcl_AlertNotifier(tsdPtr->clientData); } } else { @@ -466,7 +466,7 @@ Tcl_ThreadQueueEvent( * last-in-first-out order. * * Results: - * For TCL_QUEUE_(HEAD|TAIL)_ALERT_IF_EMPTY the empty state before the + * For TCL_QUEUE_ALERT_IF_EMPTY the empty state before the * operation is returned. * * Side effects: @@ -484,17 +484,15 @@ QueueEvent( * malloc (ckalloc), and it becomes the * property of the event queue. It will be * freed after the event has been handled. */ - Tcl_QueuePositionEx position) + int flags) /* One of TCL_QUEUE_TAIL_EX, * TCL_QUEUE_HEAD_EX, TCL_QUEUE_MARK_EX, - * TCL_QUEUE_TAIL_ALERT_IF_EMPTY, or - * TCL_QUEUE_HEAD_ALERT_IF_EMPTY. */ + * possibly combined with TCL_QUEUE_ALERT_IF_EMPTY */ { int wasEmpty = 0; Tcl_MutexLock(&(tsdPtr->queueMutex)); - if ((position == TCL_QUEUE_TAIL_EX) || - (position == TCL_QUEUE_TAIL_EX_ALERT_IF_EMPTY)) { + if ((flags & 3) == TCL_QUEUE_TAIL) { /* * Append the event on the end of the queue. */ @@ -502,13 +500,12 @@ QueueEvent( evPtr->nextPtr = NULL; if (tsdPtr->firstEventPtr == NULL) { tsdPtr->firstEventPtr = evPtr; - wasEmpty = (position == TCL_QUEUE_TAIL_EX_ALERT_IF_EMPTY) ? 1 : 0; + wasEmpty = (flags & TCL_QUEUE_ALERT_IF_EMPTY) ? 1 : 0; } else { tsdPtr->lastEventPtr->nextPtr = evPtr; } tsdPtr->lastEventPtr = evPtr; - } else if ((position == TCL_QUEUE_HEAD_EX) || - (position == TCL_QUEUE_HEAD_EX_ALERT_IF_EMPTY)) { + } else if ((flags & 3) == TCL_QUEUE_HEAD) { /* * Push the event on the head of the queue. */ @@ -516,10 +513,10 @@ QueueEvent( evPtr->nextPtr = tsdPtr->firstEventPtr; if (tsdPtr->firstEventPtr == NULL) { tsdPtr->lastEventPtr = evPtr; - wasEmpty = (position == TCL_QUEUE_HEAD_EX_ALERT_IF_EMPTY) ? 1 : 0; + wasEmpty = (flags & TCL_QUEUE_ALERT_IF_EMPTY) ? 1 : 0; } tsdPtr->firstEventPtr = evPtr; - } else if (position == TCL_QUEUE_MARK_EX) { + } else if ((flags & 3) == TCL_QUEUE_MARK) { /* * Insert the event after the current marker event and advance the * marker to the new event. diff --git a/generic/tclTest.c b/generic/tclTest.c index 99fe92f..b29bb1c 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2109,7 +2109,7 @@ TesteventObjCmd( "head", "tail", "mark", NULL }; int posIndex; /* Index of the chosen position */ - static const Tcl_QueuePosition posNum[] = { + static const int posNum[] = { /* Interpretation of the chosen position */ TCL_QUEUE_HEAD, TCL_QUEUE_TAIL, diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index 887f645..1e8e013 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -878,7 +878,7 @@ ThreadSend( threadEventPtr->event.proc = ThreadEventProc; Tcl_ThreadQueueEvent(threadId, (Tcl_Event *) threadEventPtr, - TCL_QUEUE_TAIL_ALERT_IF_EMPTY); + TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); if (!wait) { Tcl_MutexUnlock(&threadMutex); -- cgit v0.12