Skip to content

Commit

Permalink
''
Browse files Browse the repository at this point in the history
  • Loading branch information
rpj committed Apr 25, 2005
1 parent c2c2749 commit bbae92b
Show file tree
Hide file tree
Showing 13 changed files with 1,116 additions and 1,113 deletions.
9 changes: 4 additions & 5 deletions Bmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Currently only the recommended pthreadBC.dll is built by this makefile.
#


DLL_VER = 2

DEVROOT = .

DLLDEST = $(DEVROOT)\DLL
Expand Down Expand Up @@ -139,6 +139,7 @@ PRIVATE_SRCS = \
ptw32_tkAssocDestroy.c \
ptw32_callUserDestroyRoutines.c \
ptw32_timespec.c \
ptw32_relmillisecs.c \
ptw32_throw.c \
ptw32_InterlockedCompareExchange.c \
ptw32_getprocessors.c
Expand Down Expand Up @@ -186,9 +187,7 @@ SEMAPHORE_SRCS = \
sem_getvalue.c \
sem_open.c \
sem_close.c \
sem_unlink.c \
ptw32_increase_semaphore.c \
ptw32_decrease_semaphore.c
sem_unlink.c

SPIN_SRCS = \
ptw32_spinlock_check_need_init.c \
Expand Down
35 changes: 35 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
2005-04-25 Ross Johnson <ross at callisto.canberra.edu.au>

* ptw32_relmillisecs.c: New module; converts future abstime to
milliseconds relative to 'now'.
* pthread_mutex_timedlock.c: Use new ptw32_relmillisecs routine in
place of internal code; remove the NEED_SEM code - this routine is now
implemented for builds that define NEED_SEM (WinCE etc)
* sem_timedwait.c: Likewise; after timeout or cancellation,
re-attempt to acquire the semaphore in case one has been posted since
the timeout/cancel occurred. Thanks to
* Makefile: Add ptw32_relmillisecs.c module; remove
ptw32_{in,de}crease_semaphore.c modules.
* GNUmakefile: Likewise.
* Bmakefile: Likewise.

* sem_init.c: Re-write the NEED_SEM code to be consistent with the
non-NEED_SEM code, but retaining use of an event in place of the w32 sema
for w32 systems that don't include semaphores (WinCE);
the NEED_SEM versions of semaphores has been broken for a long time but is
now fixed and supports all of the same routines as the non-NEED_SEM case.
* sem_destroy.c: Likewise.
* sem_wait.c: Likewise.
* sem_post.c: Likewise.
* sem_post_multple.c: Likewise.
* implement.h: Likewise.
* sem_timedwait.c: Likewise; this routine is now
implemented for builds that define NEED_SEM (WinCE etc).
* sem_trywait.c: Likewise.
* sem_getvalue.c: Likewise.

* pthread_once.c: Yet more changes, reverting closer to Gottlob Frege's
first design, but retaining cancellation, priority boosting, and adding
preservation of W32 error codes to make pthread_once transparent to
GetLastError.

2005-04-11 Ross Johnson <ross at callisto.canberra.edu.au>

* pthread_once.c (pthread_once): Added priority boosting to
Expand Down
8 changes: 3 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ SMALL_STATIC_OBJS = \
ptw32_new.o \
ptw32_reuse.o \
ptw32_semwait.o \
ptw32_relmillisecs.o \
ptw32_rwlock_check_need_init.o \
sched_get_priority_max.o \
sched_get_priority_min.o \
Expand All @@ -236,8 +237,6 @@ SMALL_STATIC_OBJS = \
sem_open.o \
sem_close.o \
sem_unlink.o \
ptw32_increase_semaphore.o \
ptw32_decrease_semaphore.o \
signal.o \
pthread_kill.o \
ptw32_spinlock_check_need_init.o \
Expand Down Expand Up @@ -349,6 +348,7 @@ PRIVATE_SRCS = \
ptw32_tkAssocDestroy.c \
ptw32_callUserDestroyRoutines.c \
ptw32_semwait.c \
ptw32_relmillisecs.c \
ptw32_timespec.c \
ptw32_throw.c \
ptw32_InterlockedCompareExchange.c \
Expand Down Expand Up @@ -397,9 +397,7 @@ SEMAPHORE_SRCS = \
sem_getvalue.c \
sem_open.c \
sem_close.c \
sem_unlink.c \
ptw32_increase_semaphore.c \
ptw32_decrease_semaphore.c
sem_unlink.c

SPIN_SRCS = \
ptw32_spinlock_check_need_init.c \
Expand Down
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ SMALL_STATIC_OBJS = \
ptw32_cond_check_need_init.obj \
ptw32_mutex_check_need_init.obj \
ptw32_semwait.obj \
ptw32_relmillisecs.obj \
sched_get_priority_max.obj \
sched_get_priority_min.obj \
sched_setscheduler.obj \
Expand All @@ -190,8 +191,6 @@ SMALL_STATIC_OBJS = \
sem_open.obj \
sem_close.obj \
sem_unlink.obj \
ptw32_increase_semaphore.obj \
ptw32_decrease_semaphore.obj \
signal.obj \
pthread_kill.obj \
ptw32_spinlock_check_need_init.obj \
Expand Down Expand Up @@ -262,6 +261,7 @@ MISC_SRCS = \
ptw32_calloc.c \
ptw32_new.c \
ptw32_reuse.c \
ptw32_relmillisecs.c \
w32_CancelableWait.c

MUTEX_SRCS = \
Expand Down Expand Up @@ -346,9 +346,7 @@ SEMAPHORE_SRCS = \
sem_getvalue.c \
sem_open.c \
sem_close.c \
sem_unlink.c \
ptw32_increase_semaphore.c \
ptw32_decrease_semaphore.c
sem_unlink.c

SPIN_SRCS = \
ptw32_spinlock_check_need_init.c \
Expand Down
4 changes: 2 additions & 2 deletions pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* See the README file for an explanation of the pthreads-win32 version
* numbering scheme and how the DLL is named etc.
*/
#define PTW32_VERSION 2,3,0,0
#define PTW32_VERSION_STRING "2, 3, 0, 0\0"
#define PTW32_VERSION 2,4,0,0
#define PTW32_VERSION_STRING "2, 4, 0, 0\0"

/* There are three implementations of cancel cleanup.
* Note that pthread.h is included in both application
Expand Down
125 changes: 1 addition & 124 deletions pthread_cond_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,130 +36,7 @@
*
* -------------------------------------------------------------
* Algorithm:
* The algorithm used in this implementation is that developed by
* Alexander Terekhov in colaboration with Louis Thomas. The bulk
* of the discussion is recorded in the file README.CV, which contains
* several generations of both colaborators original algorithms. The final
* algorithm used here is the one referred to as
*
* Algorithm 8a / IMPL_SEM,UNBLOCK_STRATEGY == UNBLOCK_ALL
*
* presented below in pseudo-code as it appeared:
*
*
* given:
* semBlockLock - bin.semaphore
* semBlockQueue - semaphore
* mtxExternal - mutex or CS
* mtxUnblockLock - mutex or CS
* nWaitersGone - int
* nWaitersBlocked - int
* nWaitersToUnblock - int
*
* wait( timeout ) {
*
* [auto: register int result ] // error checking omitted
* [auto: register int nSignalsWasLeft ]
* [auto: register int nWaitersWasGone ]
*
* sem_wait( semBlockLock );
* nWaitersBlocked++;
* sem_post( semBlockLock );
*
* unlock( mtxExternal );
* bTimedOut = sem_wait( semBlockQueue,timeout );
*
* lock( mtxUnblockLock );
* if ( 0 != (nSignalsWasLeft = nWaitersToUnblock) ) {
* if ( bTimeout ) { // timeout (or canceled)
* if ( 0 != nWaitersBlocked ) {
* nWaitersBlocked--;
* }
* else {
* nWaitersGone++; // count spurious wakeups.
* }
* }
* if ( 0 == --nWaitersToUnblock ) {
* if ( 0 != nWaitersBlocked ) {
* sem_post( semBlockLock ); // open the gate.
* nSignalsWasLeft = 0; // do not open the gate
* // below again.
* }
* else if ( 0 != (nWaitersWasGone = nWaitersGone) ) {
* nWaitersGone = 0;
* }
* }
* }
* else if ( INT_MAX/2 == ++nWaitersGone ) { // timeout/canceled or
* // spurious semaphore :-)
* sem_wait( semBlockLock );
* nWaitersBlocked -= nWaitersGone; // something is going on here
* // - test of timeouts? :-)
* sem_post( semBlockLock );
* nWaitersGone = 0;
* }
* unlock( mtxUnblockLock );
*
* if ( 1 == nSignalsWasLeft ) {
* if ( 0 != nWaitersWasGone ) {
* // sem_adjust( semBlockQueue,-nWaitersWasGone );
* while ( nWaitersWasGone-- ) {
* sem_wait( semBlockQueue ); // better now than spurious later
* }
* } sem_post( semBlockLock ); // open the gate
* }
*
* lock( mtxExternal );
*
* return ( bTimedOut ) ? ETIMEOUT : 0;
* }
*
* signal(bAll) {
*
* [auto: register int result ]
* [auto: register int nSignalsToIssue]
*
* lock( mtxUnblockLock );
*
* if ( 0 != nWaitersToUnblock ) { // the gate is closed!!!
* if ( 0 == nWaitersBlocked ) { // NO-OP
* return unlock( mtxUnblockLock );
* }
* if (bAll) {
* nWaitersToUnblock += nSignalsToIssue=nWaitersBlocked;
* nWaitersBlocked = 0;
* }
* else {
* nSignalsToIssue = 1;
* nWaitersToUnblock++;
* nWaitersBlocked--;
* }
* }
* else if ( nWaitersBlocked > nWaitersGone ) { // HARMLESS RACE CONDITION!
* sem_wait( semBlockLock ); // close the gate
* if ( 0 != nWaitersGone ) {
* nWaitersBlocked -= nWaitersGone;
* nWaitersGone = 0;
* }
* if (bAll) {
* nSignalsToIssue = nWaitersToUnblock = nWaitersBlocked;
* nWaitersBlocked = 0;
* }
* else {
* nSignalsToIssue = nWaitersToUnblock = 1;
* nWaitersBlocked--;
* }
* }
* else { // NO-OP
* return unlock( mtxUnblockLock );
* }
*
* unlock( mtxUnblockLock );
* sem_post( semBlockQueue,nSignalsToIssue );
* return result;
* }
* -------------------------------------------------------------
*
* See the comments at the top of pthread_cond_wait.c.
*/

#include "pthread.h"
Expand Down
Loading

0 comments on commit bbae92b

Please sign in to comment.