Diff
Not logged in

Differences From Artifact [479aec97fd]:

To Artifact [181c9e0003]:


623
624
625
626
627
628
629









630
631
632
633








634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
















649
650
651
652

653
654
655
656
657
658
659
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655


656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688







+
+
+
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+








-
-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




+








	/*
	 * Double check inside mutex to avoid race, then initialize condition
	 * variable if necessary.
	 */

	if (*condPtr == NULL) {
#undef attr_p
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
#define attr_p (&attr)
	    pthread_condattr_t attr;
	    pthread_condattr_init(&attr);
	    pthread_condattr_setclock(&attr,CLOCK_MONOTONIC);
#else
#define attr_p (NULL)
#endif
	    pcondPtr = (pthread_cond_t *) ckalloc(sizeof(pthread_cond_t));
	    pthread_cond_init(pcondPtr, NULL);
	    *condPtr = (Tcl_Condition)pcondPtr;
	    TclRememberCondition(condPtr);
	    pthread_cond_init(pcondPtr, attr_p);

#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
	    pthread_condattr_destroy(&attr);
#endif
#undef attr_p
 	    *condPtr = (Tcl_Condition) pcondPtr;
 	    TclRememberCondition(condPtr);
	}
	MASTER_UNLOCK;
    }
    pmutexPtr = *((pthread_mutex_t **)mutexPtr);
    pcondPtr = *((pthread_cond_t **)condPtr);
    if (timePtr == NULL) {
	pthread_cond_wait(pcondPtr, pmutexPtr);
    } else {
	Tcl_Time now;

	/*
	 * Make sure to take into account the microsecond component of the
	 * current time, including possible overflow situations. [Bug #411603]
	 */

#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
	struct timespec pnow;
	clock_gettime(CLOCK_MONOTONIC, &pnow);
	ptime.tv_sec = timePtr->sec + pnow.tv_sec +
	    (timePtr->usec + pnow.tv_nsec/1000) / 1000000;
	ptime.tv_nsec = 1000 * ((timePtr->usec + pnow.tv_nsec/1000) % 1000000);

#elif defined(_POSIX_TIMERS)
	struct timespec pnow;
	clock_gettime(CLOCK_REALTIME, &pnow);
	ptime.tv_sec = timePtr->sec + pnow.tv_sec +
	    (timePtr->usec + pnow.tv_nsec/1000) / 1000000;
	ptime.tv_nsec = 1000 * ((timePtr->usec + pnow.tv_nsec/1000) % 1000000);

#else
	Tcl_Time now;
	Tcl_GetTime(&now);
	ptime.tv_sec = timePtr->sec + now.sec +
	    (timePtr->usec + now.usec) / 1000000;
	ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000);
#endif
	pthread_cond_timedwait(pcondPtr, pmutexPtr, &ptime);
    }
}

/*
 *----------------------------------------------------------------------
 *