Diff
Not logged in

Differences From Artifact [c3850db966]:

To Artifact [c2820da48a]:


716
717
718
719
720
721
722
723

724
725

726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746

747
748
749
750
751
752
753
716
717
718
719
720
721
722

723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745

746
747
748
749
750
751
752
753







-
+

-
+




















-
+







    Tcl_Condition *condPtr,	/* Really (WinCondition **) */
    Tcl_Mutex *mutexPtr,	/* Really (CRITICAL_SECTION **) */
    const Tcl_Time *timePtr)	/* Timeout on waiting period */
{
    WinCondition *winCondPtr;	/* Per-condition queue head */
    WMutex *wmPtr;		/* Caller's Mutex, after casting */
    DWORD wtime;		/* Windows time value */
    int timeout;		/* True if we got a timeout */
    bool timeout;		/* True if we got a timeout */
    int counter;		/* Caller's Mutex counter */
    int doExit = 0;		/* True if we need to do exit setup */
    bool doExit = false;	/* True if we need to do exit setup */
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    /*
     * Self initialize the two parts of the condition. The per-condition and
     * per-thread parts need to be handled independently.
     */

    if (tsdPtr->flags == WIN_THREAD_UNINIT) {
	TclpGlobalLock();

	/*
	 * Create the per-thread event and queue pointers.
	 */

	if (tsdPtr->flags == WIN_THREAD_UNINIT) {
	    tsdPtr->condEvent = CreateEventW(NULL, TRUE /* manual reset */,
		    FALSE /* non signaled */, NULL);
	    tsdPtr->nextPtr = NULL;
	    tsdPtr->prevPtr = NULL;
	    tsdPtr->flags = WIN_THREAD_RUNNING;
	    doExit = 1;
	    doExit = true;
	}
	TclpGlobalUnlock();

	if (doExit) {
	    /*
	     * Create a per-thread exit handler to clean up the condEvent. We
	     * must be careful to do this outside the Global Lock because
813
814
815
816
817
818
819
820

821
822
823
824
825
826

827
828
829
830
831
832
833
834
835
836
837
838

839
840
841
842
843
844
845
813
814
815
816
817
818
819

820
821
822
823
824
825

826
827
828
829
830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845







-
+





-
+











-
+








    counter = wmPtr->counter;
    wmPtr->counter = 0;
    LONG mythread = GetCurrentThreadId();
    assert(wmPtr->thread == mythread);
    wmPtr->thread = 0;
    LeaveCriticalSection(&wmPtr->crit);
    timeout = 0;
    timeout = false;
    while (!timeout && (tsdPtr->flags & WIN_THREAD_BLOCKED)) {
	ResetEvent(tsdPtr->condEvent);
	LeaveCriticalSection(&winCondPtr->condLock);
	if (WaitForSingleObjectEx(tsdPtr->condEvent, wtime,
		TRUE) == WAIT_TIMEOUT) {
	    timeout = 1;
	    timeout = true;
	}
	EnterCriticalSection(&winCondPtr->condLock);
    }

    /*
     * Be careful on timeouts because the signal might arrive right around the
     * time limit and someone else could have taken us off the queue.
     */

    if (timeout) {
	if (tsdPtr->flags & WIN_THREAD_RUNNING) {
	    timeout = 0;
	    timeout = false;
	} else {
	    /*
	     * When dequeueing, we can leave the tsdPtr->nextPtr and
	     * tsdPtr->prevPtr with dangling pointers because they are
	     * reinitialized w/out reading them when the thread is enqueued
	     * later.
	     */