summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ANNOUNCE8
-rw-r--r--CONTRIBUTORS3
-rw-r--r--ChangeLog170
-rw-r--r--FAQ3
-rw-r--r--GNUmakefile2
-rw-r--r--Makefile16
-rw-r--r--NEWS36
-rw-r--r--Nmakefile.tests25
-rw-r--r--README21
-rw-r--r--attr.c1
-rw-r--r--barrier.c1
-rw-r--r--cancel.c1
-rw-r--r--cleanup.c13
-rw-r--r--config.h16
-rw-r--r--create.c95
-rw-r--r--dll.c21
-rw-r--r--errno.c16
-rw-r--r--fork.c1
-rw-r--r--global.c21
-rw-r--r--implement.h312
-rw-r--r--misc.c1
-rw-r--r--mutex.c3
-rw-r--r--nonportable.c1
-rw-r--r--private.c1
-rw-r--r--pthread.c4
-rw-r--r--pthread.h21
-rw-r--r--pthread_attr_destroy.c5
-rw-r--r--pthread_attr_getdetachstate.c6
-rw-r--r--pthread_attr_getinheritsched.c5
-rw-r--r--pthread_attr_getschedparam.c12
-rw-r--r--pthread_attr_getschedpolicy.c5
-rw-r--r--pthread_attr_getscope.c3
-rw-r--r--pthread_attr_getstackaddr.c6
-rw-r--r--pthread_attr_getstacksize.c6
-rw-r--r--pthread_attr_init.c5
-rw-r--r--pthread_attr_setdetachstate.c6
-rw-r--r--pthread_attr_setinheritsched.c5
-rw-r--r--pthread_attr_setschedparam.c12
-rw-r--r--pthread_attr_setschedpolicy.c5
-rw-r--r--pthread_attr_setscope.c22
-rw-r--r--pthread_attr_setstackaddr.c6
-rw-r--r--pthread_attr_setstacksize.c6
-rw-r--r--pthread_barrier_destroy.c21
-rw-r--r--pthread_barrier_init.c31
-rw-r--r--pthread_barrier_wait.c39
-rw-r--r--pthread_barrierattr_destroy.c3
-rw-r--r--pthread_barrierattr_getpshared.c8
-rw-r--r--pthread_barrierattr_init.c3
-rw-r--r--pthread_barrierattr_setpshared.c21
-rw-r--r--pthread_cancel.c108
-rw-r--r--pthread_cond_destroy.c163
-rw-r--r--pthread_cond_init.c36
-rw-r--r--pthread_cond_signal.c96
-rw-r--r--pthread_cond_wait.c4
-rw-r--r--pthread_condattr_destroy.c2
-rw-r--r--pthread_condattr_getpshared.c2
-rw-r--r--pthread_condattr_init.c2
-rw-r--r--pthread_condattr_setpshared.c20
-rw-r--r--pthread_delay_np.c63
-rw-r--r--pthread_detach.c2
-rw-r--r--pthread_equal.c6
-rw-r--r--pthread_exit.c8
-rw-r--r--pthread_getconcurrency.c4
-rw-r--r--pthread_getschedparam.c6
-rw-r--r--pthread_getspecific.c8
-rw-r--r--pthread_getw32threadhandle_np.c2
-rw-r--r--pthread_join.c8
-rw-r--r--pthread_key_create.c2
-rw-r--r--pthread_key_delete.c72
-rw-r--r--pthread_kill.c12
-rw-r--r--pthread_mutex_destroy.c25
-rw-r--r--pthread_mutex_init.c19
-rw-r--r--pthread_mutex_lock.c103
-rw-r--r--pthread_mutex_timedlock.c136
-rw-r--r--pthread_mutex_trylock.c34
-rw-r--r--pthread_mutex_unlock.c18
-rw-r--r--pthread_mutexattr_destroy.c10
-rw-r--r--pthread_mutexattr_getkind_np.c4
-rw-r--r--pthread_mutexattr_getpshared.c32
-rw-r--r--pthread_mutexattr_gettype.c3
-rw-r--r--pthread_mutexattr_init.c10
-rw-r--r--pthread_mutexattr_setkind_np.c5
-rw-r--r--pthread_mutexattr_setpshared.c31
-rw-r--r--pthread_mutexattr_settype.c79
-rw-r--r--pthread_num_processors_np.c4
-rw-r--r--pthread_once.c39
-rw-r--r--pthread_rwlock_destroy.c169
-rw-r--r--pthread_rwlock_init.c111
-rw-r--r--pthread_rwlock_rdlock.c94
-rw-r--r--pthread_rwlock_timedrdlock.c105
-rw-r--r--pthread_rwlock_timedwrlock.c167
-rw-r--r--pthread_rwlock_tryrdlock.c94
-rw-r--r--pthread_rwlock_trywrlock.c131
-rw-r--r--pthread_rwlock_unlock.c79
-rw-r--r--pthread_rwlock_wrlock.c156
-rw-r--r--pthread_rwlockattr_destroy.c10
-rw-r--r--pthread_rwlockattr_getpshared.c29
-rw-r--r--pthread_rwlockattr_init.c8
-rw-r--r--pthread_rwlockattr_setpshared.c31
-rw-r--r--pthread_self.c35
-rw-r--r--pthread_setcancelstate.c20
-rw-r--r--pthread_setcanceltype.c19
-rw-r--r--pthread_setconcurrency.c2
-rw-r--r--pthread_setschedparam.c47
-rw-r--r--pthread_setspecific.c88
-rw-r--r--pthread_spin_destroy.c65
-rw-r--r--pthread_spin_init.c50
-rw-r--r--pthread_spin_lock.c28
-rw-r--r--pthread_spin_trylock.c31
-rw-r--r--pthread_spin_unlock.c23
-rw-r--r--pthread_testcancel.c16
-rw-r--r--pthread_timechange_handler_np.c15
-rw-r--r--pthread_win32_attach_detach_np.c146
-rw-r--r--ptw32_InterlockedCompareExchange.c56
-rw-r--r--ptw32_callUserDestroyRoutines.c35
-rw-r--r--ptw32_calloc.c20
-rw-r--r--ptw32_cond_check_need_init.c8
-rw-r--r--ptw32_decrease_semaphore.c12
-rw-r--r--ptw32_getprocessors.c17
-rw-r--r--ptw32_increase_semaphore.c14
-rw-r--r--ptw32_is_attr.c6
-rw-r--r--ptw32_mutex_check_need_init.c10
-rw-r--r--ptw32_new.c22
-rw-r--r--ptw32_processInitialize.c37
-rw-r--r--ptw32_processTerminate.c31
-rw-r--r--ptw32_reuse.c11
-rw-r--r--ptw32_rwlock_cancelwrwait.c12
-rw-r--r--ptw32_rwlock_check_need_init.c8
-rw-r--r--ptw32_spinlock_check_need_init.c10
-rw-r--r--ptw32_threadDestroy.c13
-rw-r--r--ptw32_threadStart.c284
-rw-r--r--ptw32_throw.c33
-rw-r--r--ptw32_timespec.c16
-rw-r--r--ptw32_tkAssocCreate.c35
-rw-r--r--ptw32_tkAssocDestroy.c7
-rw-r--r--sched_get_priority_max.c6
-rw-r--r--sched_get_priority_min.c6
-rw-r--r--sched_getscheduler.c23
-rw-r--r--sched_setscheduler.c23
-rw-r--r--sched_yield.c4
-rw-r--r--sem_destroy.c22
-rw-r--r--sem_getvalue.c56
-rw-r--r--sem_init.c102
-rw-r--r--sem_open.c2
-rw-r--r--sem_post.c18
-rw-r--r--sem_post_multiple.c18
-rw-r--r--sem_trywait.c16
-rw-r--r--sem_unlink.c2
-rw-r--r--sem_wait.c20
-rw-r--r--semaphore.c4
-rw-r--r--signal.c29
-rw-r--r--spin.c1
-rw-r--r--tests/ChangeLog40
-rw-r--r--tests/GNUmakefile46
-rw-r--r--tests/Makefile34
-rw-r--r--tests/cancel3.c71
-rw-r--r--tests/cancel4.c12
-rw-r--r--tests/cancel5.c62
-rw-r--r--tests/cancel6a.c12
-rw-r--r--tests/cancel6d.c12
-rw-r--r--tsd.c2
-rw-r--r--w32_CancelableWait.c138
162 files changed, 2862 insertions, 2617 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index a05d6ea..144455e 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,8 +1,8 @@
- PTHREADS-WIN32 SNAPSHOT 2003-09-18
+ PTHREADS-WIN32 SNAPSHOT 2004-05-16
----------------------------------
Web Site: http://sources.redhat.com/pthreads-win32/
FTP Site: ftp://sources.redhat.com/pub/pthreads-win32
- Maintainer: Ross Johnson <rpj@ise.canberra.edu.au>
+ Maintainer: Ross Johnson <rpj@callisto.canberra.edu.au>
We are pleased to announce the availability of a new snapshot of
@@ -414,9 +414,9 @@ Documentation
-------------
For the authoritative reference, see the online POSIX
-standard reference:
+standard reference at:
- http://www.UNIX-systems.org/version3/ieee_std.html
+ http://www.OpenGroup.org
For POSIX Thread API programming, several reference books are
available:
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 4b7e531..752d57a 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -108,3 +108,6 @@ Piet van Bruggen pietvb at newbridges dot nl
Bug fix.
Makoto Kato raven at oldskool dot jp
AMD64 port.
+Panagiotis E. Hadjidoukas peh at hpclab dot ceid dotupatras dot gr
+ Contributed the QueueUserAPCEx package which
+ makes preemptive async cancelation possible.
diff --git a/ChangeLog b/ChangeLog
index 4798e9b..16b96b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,55 +1,123 @@
-2004-05-06 Makoto Kato <raven at oldskool.jp>
-
- * pthread.h (DWORD_PTR): Define typedef for older MSVC.
- * pthread_cancel.c (AMD64): Add architecture specific Context register.
- * ptw32_getprocessors.c: Use correct types (DWORD_PTR) for mask
- variables.
-
-2004-04-06 P. van Bruggen <pietvb at newbridges.nl>
-
- * ptw32_threadDestroy.c: Destroy threadLock mutex to
- close a memory leak.
-
-2004-02-13 Gustav Hallberg <gustav at virtutech.com>
-
- * pthread_equal.c: Remove redundant equality logic.
-
-2003-12-10 Philippe Di Cristo <philipped at voicebox.com>
-
- * sem_timedwait.c (sem_timedwait): Fix timeout calculations.
-
+2004-05-16 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * pthread_cancel.c (pthread_cancel): Adapted to use auto-detected
+ QueueUserAPCEx features at run-time.
+ (ptw32_RegisterCancelation): Drop in replacement for QueueUserAPCEx()
+ if it can't be used. Provides older style non-preemptive async
+ cancelation.
+ * pthread_win32_attach_detach_np.c (pthread_win32_attach_np):
+ Auto-detect quserex.dll and the availability of alertdrv.sys;
+ initialise and close on process attach/detach.
+ * global.c (ptw32_register_cancelation): Pointer to either
+ QueueUserAPCEx() or ptw32_RegisterCancelation() depending on
+ availability. QueueUserAPCEx makes pre-emptive async cancelation
+ possible.
+ * implement.h: Add definitions and prototypes related to QueueUserAPC.
+
+2004-05-16 Panagiotis E. Hadjidoukas <peh at hpclab.ceid.upatras.gr>
+
+ * QueueUserAPCEx (separate contributed package): Provides preemptive
+ APC feature.
+ * pthread_cancel.c (pthread_cancel): Initial integration of
+ QueueUserAPCEx into pthreads-win32 to provide true pre-emptive
+ async cancelation of threads, including blocked threads.
+
+2004-05-06 Makoto Kato <raven at oldskool.jp>
+
+ * pthread.h (DWORD_PTR): Define typedef for older MSVC.
+ * pthread_cancel.c (AMD64): Add architecture specific Context register.
+ * ptw32_getprocessors.c: Use correct types (DWORD_PTR) for mask
+ variables.
+
+2004-04-06 P. van Bruggen <pietvb at newbridges.nl>
+
+ * ptw32_threadDestroy.c: Destroy threadLock mutex to
+ close a memory leak.
+
+2004-02-13 Gustav Hallberg <gustav at virtutech.com>
+
+ * pthread_equal.c: Remove redundant equality logic.
+
+2003-12-10 Philippe Di Cristo <philipped at voicebox.com>
+
+ * sem_timedwait.c (sem_timedwait): Fix timeout calculations.
+
+2003-10-20 Alexander Terekhov <TEREKHOV at de.ibm.com>
+
+ * pthread_mutex_timedlock.c (ptw32_semwait): Move to individual module.
+ * ptw32_semwait.c: New module.
+ * pthread_cond_wait.c (ptw32_cond_wait_cleanup): Replace cancelable
+ sem_wait() call with non-cancelable ptw32_semwait() call.
+ * pthread.c (private.c): Re-order for inlining. GNU C warned that
+ function ptw32_semwait() was defined 'inline' after it was called.
+ * pthread_cond_signal.c (ptw32_cond_unblock): Likewise.
+ * pthread_delay_np.c: Disable Watcom warning with comment.
+ * *.c (process.h): Remove include from .c files. This is conditionally
+ included by the common project include files.
+
+2003-10-20 James Ewing <james.ewing at sveasoft.com>
+
+ * ptw32_getprocessors.c: Some Win32 environments don't have
+ GetProcessAffinityMask(), so always return CPU count = 1 for them.
+ * config.h (NEED_PROCESSOR_AFFINITY_MASK): Define for WinCE.
+
+2003-10-15 Ross Johnson <ross at callisto.canberra.edu.au>
+
+ * Re-indented all .c files using default GNU style to remove assorted
+ editor ugliness (used GNU indent utility in default style).
+
+2003-10-15 Alex Blanco <Alex.Blanco at motorola.com>
+
+ * sem_init.c (sem_init): Would call CreateSemaphore even if the sema
+ struct calloc failed; was not freeing calloced memory if either
+ CreateSemaphore or CreateEvent failed.
+
+2003-10-14 Ross Johnson <ross at callisto.canberra.edu.au>
+
+ * pthread.h: Add Watcom compiler compatibility. Esssentially just add
+ the cdecl attribute to all exposed function prototypes so that Watcom
+ generates function call code compatible with non-Watcom built libraries.
+ By default, Watcom uses registers to pass function args if possible rather
+ than pushing to stack.
+ * semaphore.h: Likewise.
+ * sched.h: Likewise.
+ * pthread_cond_wait.c (ptw32_cond_wait_cleanup): Define with cdecl attribute
+ for Watcom compatibility. This routine is called via pthread_cleanup_push so
+ it had to match function arg definition.
+ * Wmakefile: New makefile for Watcom builds.
+
2003-09-14 Ross Johnson <rpj at callisto.canberra.edu.au>
-
- * pthread_setschedparam.c (pthread_setschedparam): Attempt to map
- all priority levels between max and min (as returned by
- sched_get_priority_min/max) to reasonable Win32 priority levels - i.e.
- levels between THREAD_PRIORITY_LOWEST/IDLE to THREAD_PRIORITY_LOWEST and
- between THREAD_PRIORITY_HIGHEST/TIME_CRITICAL to THREAD_PRIORITY_HIGHEST
- while others remain unchanged; record specified thread priority level
- for return by pthread_getschedparam.
-
- Note that, previously, specified levels not matching Win32 priority levels
- would silently leave the current thread priority unaltered.
-
- * pthread_getschedparam.c (pthread_getschedparam): Return the priority
- level specified by the latest pthread_setschedparam or pthread_create rather
- than the actual running thread priority as returned by GetThreadPriority - as
- required by POSIX. I.e. temporary or adjusted actual priority levels are not
- returned by this routine.
-
- * pthread_create.c (pthread_create): For priority levels specified via
- pthread attributes, attempt to map all priority levels between max and
- min (as returned by sched_get_priority_min/max) to reasonable Win32
- priority levels; record priority level given via attributes, or
- inherited from parent thread, for later return by pthread_getschedparam.
-
- * ptw32_new.c (ptw32_new): Initialise pthread_t_ sched_priority element.
-
- * pthread_self.c (pthread_self): Set newly created implicit POSIX thread
- sched_priority to Win32 thread's current actual priority. Temporarily
- altered priorities can't be avoided in this case.
-
- * implement.h (struct pthread_t_): Add new sched_priority element.
+
+ * pthread_setschedparam.c (pthread_setschedparam): Attempt to map
+ all priority levels between max and min (as returned by
+ sched_get_priority_min/max) to reasonable Win32 priority levels - i.e.
+ levels between THREAD_PRIORITY_LOWEST/IDLE to THREAD_PRIORITY_LOWEST and
+ between THREAD_PRIORITY_HIGHEST/TIME_CRITICAL to THREAD_PRIORITY_HIGHEST
+ while others remain unchanged; record specified thread priority level
+ for return by pthread_getschedparam.
+
+ Note that, previously, specified levels not matching Win32 priority levels
+ would silently leave the current thread priority unaltered.
+
+ * pthread_getschedparam.c (pthread_getschedparam): Return the priority
+ level specified by the latest pthread_setschedparam or pthread_create rather
+ than the actual running thread priority as returned by GetThreadPriority - as
+ required by POSIX. I.e. temporary or adjusted actual priority levels are not
+ returned by this routine.
+
+ * pthread_create.c (pthread_create): For priority levels specified via
+ pthread attributes, attempt to map all priority levels between max and
+ min (as returned by sched_get_priority_min/max) to reasonable Win32
+ priority levels; record priority level given via attributes, or
+ inherited from parent thread, for later return by pthread_getschedparam.
+
+ * ptw32_new.c (ptw32_new): Initialise pthread_t_ sched_priority element.
+
+ * pthread_self.c (pthread_self): Set newly created implicit POSIX thread
+ sched_priority to Win32 thread's current actual priority. Temporarily
+ altered priorities can't be avoided in this case.
+
+ * implement.h (struct pthread_t_): Add new sched_priority element.
2003-09-12 Ross Johnson <rpj at callisto.canberra.edu.au>
diff --git a/FAQ b/FAQ
index c08bcbc..34ef8b8 100644
--- a/FAQ
+++ b/FAQ
@@ -385,8 +385,7 @@ Ross
Q 10 How do I create thread-safe applications using
---- pthreadGCE.dll, libpthreadw32.a and Mingw32?
-If you must use a MinGW32 gcc version 2.95 or earlier then
-see Thomas Pfaff's email at:
+See Thomas Pfaff's email at:
http://sources.redhat.com/ml/pthreads-win32/2002/msg00000.html
Later versions should thread-safe.
diff --git a/GNUmakefile b/GNUmakefile
index ccc0046..f4ef715 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -188,6 +188,7 @@ SMALL_STATIC_OBJS = \
ptw32_calloc.o \
ptw32_new.o \
ptw32_reuse.o \
+ ptw32_semwait.o \
ptw32_rwlock_check_need_init.o \
sched_get_priority_max.o \
sched_get_priority_min.o \
@@ -316,6 +317,7 @@ PRIVATE_SRCS = \
ptw32_tkAssocCreate.c \
ptw32_tkAssocDestroy.c \
ptw32_callUserDestroyRoutines.c \
+ ptw32_semwait.c \
ptw32_timespec.c \
ptw32_throw.c \
ptw32_InterlockedCompareExchange.c \
diff --git a/Makefile b/Makefile
index 5d7a9e5..f8650b2 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ VCFLAGS = /D__CLEANUP_C $(CFLAGS)
DLL_INLINED_OBJS = \
pthread.obj
-# Agregate modules for inlinability
+# Aggregate modules for inlinability
DLL_OBJS = \
attr.obj \
barrier.obj \
@@ -148,10 +148,11 @@ SMALL_STATIC_OBJS = \
ptw32_getprocessors.obj \
ptw32_calloc.obj \
ptw32_new.obj \
- ptw32_reuse.obj \
+ ptw32_reuse.obj \
ptw32_rwlock_check_need_init.obj \
ptw32_cond_check_need_init.obj \
ptw32_mutex_check_need_init.obj \
+ ptw32_semwait.obj \
sched_get_priority_max.obj \
sched_get_priority_min.obj \
sched_setscheduler.obj \
@@ -171,7 +172,7 @@ SMALL_STATIC_OBJS = \
ptw32_increase_semaphore.obj \
ptw32_decrease_semaphore.obj \
signal.obj \
- pthread_kill.obj \
+ pthread_kill.obj \
ptw32_spinlock_check_need_init.obj \
pthread_spin_init.obj \
pthread_spin_destroy.obj \
@@ -232,13 +233,13 @@ EXIT_SRCS = \
MISC_SRCS = \
pthread_equal.c \
pthread_getconcurrency.c \
- pthread_kill.c \
+ pthread_kill.c \
pthread_once.c \
pthread_self.c \
pthread_setconcurrency.c \
ptw32_calloc.c \
ptw32_new.c \
- ptw32_reuse.c \
+ ptw32_reuse.c \
w32_CancelableWait.c
MUTEX_SRCS = \
@@ -274,6 +275,7 @@ PRIVATE_SRCS = \
ptw32_tkAssocCreate.c \
ptw32_tkAssocDestroy.c \
ptw32_callUserDestroyRoutines.c \
+ ptw32_semwait.c \
ptw32_timespec.c \
ptw32_throw.c \
ptw32_InterlockedCompareExchange.c \
@@ -400,12 +402,12 @@ install: $(DLLS)
copy pthread*.lib $(LIBDEST)
$(DLLS): $(DLL_OBJS)
- cl /LD /Zi /nologo $(DLL_OBJS) \
+ cl /LDd /Zi /nologo $(DLL_OBJS) \
/link /nodefaultlib:libcmt /implib:$*.lib \
msvcrt.lib wsock32.lib /out:$@
$(INLINED_STAMPS): $(DLL_INLINED_OBJS)
- cl /LD /Zi /nologo $(DLL_INLINED_OBJS) \
+ cl /LDd /Zi /nologo $(DLL_INLINED_OBJS) \
/link /nodefaultlib:libcmt /implib:$*.lib \
msvcrt.lib wsock32.lib /out:$*.dll
diff --git a/NEWS b/NEWS
index 008f8f2..83d983f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,39 @@
+SNAPSHOT 2004-05-16
+-------------------
+
+Attempt to add Watcom to the list of compilers that can build the library.
+This failed in the end due to it's non-thread-aware errno. The library
+builds but the test suite fails. See README.Watcom for more details.
+
+Bug fixes
+---------
+* Bug and memory leak in sem_init()
+- Alex Blanco <Alex.Blanco at motorola.com>
+
+* ptw32_getprocessors() now returns CPU count of 1 for WinCE.
+- James Ewing <james.ewing at sveasoft.com>
+
+* pthread_cond_wait() could be canceled at a point where it should not
+be cancelable. Fixed.
+- Alexander Terekhov <TEREKHOV at de.ibm.com>
+
+* sem_timedwait() had an incorrect timeout calculation.
+- Philippe Di Cristo <philipped at voicebox.com>
+
+* Fix a memory leak left behind after threads are destroyed.
+- P. van Bruggen <pietvb at newbridges.nl>
+
+New features
+------------
+* Ported to AMD64.
+- Makoto Kato <raven at oldskool.jp>
+
+* True pre-emptive asynchronous cancelation of threads. Requires that
+Panagiotis E. Hadjidoukas's QueueUserAPCEx package be installed. This
+package is included in the pthreads-win32 self-unpacking Zip archive
+starting from this snapshot.
+
+
SNAPSHOT 2003-09-18
-------------------
diff --git a/Nmakefile.tests b/Nmakefile.tests
index 8353197..a0f7dc7 100644
--- a/Nmakefile.tests
+++ b/Nmakefile.tests
@@ -18,7 +18,7 @@ set keepgoing
$(I:D:B:S=.pass) : .VIRTUAL .FORCE $(I)
$(>)
end
-sizes:: sizes.c
+sizes:: sizes.c
loadfree:: loadfree.c
mutex1:: mutex1.c
mutex1e:: mutex1e.c
@@ -58,11 +58,11 @@ equal1:: equal1.c
exit2:: exit2.c
exit3:: exit3.c
exit4:: exit4.c
-exit5:: exit5.c
+exit5:: exit5.c
join0:: join0.c
join1:: join1.c
join2:: join2.c
-kill1:: kill1.c
+kill1:: kill1.c
count1:: count1.c
once1:: once1.c
tsd1:: tsd1.c
@@ -99,7 +99,7 @@ cancel4:: cancel4.c
cancel5:: cancel5.c
cancel6a:: cancel6a.c
cancel6d:: cancel6d.c
-cancel7:: cancel7.c
+cancel7:: cancel7.c
cleanup0:: cleanup0.c
cleanup1:: cleanup1.c
cleanup2:: cleanup2.c
@@ -124,10 +124,11 @@ benchtest2:: benchtest2.c
benchtest3:: benchtest3.c
benchtest4:: benchtest4.c
benchtest5:: benchtest5.c
-valid1:: valid1.c
-valid2:: valid2.c
+valid1:: valid1.c
+valid2:: valid2.c
+cancel9:: cancel9.c
-sizes: :test: sizes
+sizes: :test: sizes
loadfree: :test:
semaphore1 :test: loadfree
semaphore2 :test: loadfree
@@ -136,7 +137,7 @@ mutex1 :test: loadfree
mutex2 :test: loadfree
exit1 :test: loadfree
condvar1 :test: loadfree
-kill1 :test: loadfree
+kill1 :test: loadfree
condvar1_1 :test: condvar1
condvar1_2 :test: join2
self1 :test: loadfree
@@ -204,7 +205,7 @@ cancel4 :test: cancel3
cancel5 :test: cancel3
cancel6a :test: cancel3
cancel6d :test: cancel3
-cancel7 :test: kill1
+cancel7 :test: kill1
cleanup0 :test: cancel5
cleanup1 :test: cleanup0
cleanup2 :test: cleanup1
@@ -230,6 +231,6 @@ exception1 :test: cancel4
exception2 :test: exception1
exception3 :test: exception2
exit4 :test: exit3
-valid1 :test: join1
-valid2 :test: valid1
-
+valid1 :test: join1
+valid2 :test: valid1
+cancel9 :test: cancel8
diff --git a/README b/README
index fc7c2f6..4f30a46 100644
--- a/README
+++ b/README
@@ -25,6 +25,27 @@ conformance details and the list of supported and unsupported
routines.
+Prerequisites
+-------------
+MSVC or GNU C (MSys - MinGW32)
+ To build from source.
+
+QueueUserAPCEx by Panagiotis E. Hadjidoukas
+ For true async cancelation of threads (including blocked threads).
+ This is a DLL and Windows driver that provides pre-emptive APC
+ by forcing threads into an alertable state when the APC is queued.
+ Both the DLL and driver are provided with the pthreads-win32.exe
+ self-unpacking ZIP, and on the pthreads-win32 FTP site (in source
+ and pre-built forms). Currently this is a separate LGPL package to
+ pthreads-win32. See the README in the QueueUserAPCEx folder for
+ installation instructions.
+
+ Pthreads-win32 will automatically detect if the QueueUserAPCEx DLL
+ QuserEx.DLL is available and whether the driver AlertDrv.sys is
+ loaded. If it is not available, pthreads-win32 will simulate async
+ cancelation, which means that it cannot pre-empt blocked threads.
+
+
Library naming
--------------
diff --git a/attr.c b/attr.c
index 685b2cc..e4ef674 100644
--- a/attr.c
+++ b/attr.c
@@ -51,4 +51,3 @@
#include "pthread_attr_setstacksize.c"
#include "pthread_attr_getscope.c"
#include "pthread_attr_setscope.c"
-
diff --git a/barrier.c b/barrier.c
index 28242c9..b715bca 100644
--- a/barrier.c
+++ b/barrier.c
@@ -45,4 +45,3 @@
#include "pthread_barrierattr_destroy.c"
#include "pthread_barrierattr_getpshared.c"
#include "pthread_barrierattr_setpshared.c"
-
diff --git a/cancel.c b/cancel.c
index d12f4e1..969bcc6 100644
--- a/cancel.c
+++ b/cancel.c
@@ -42,4 +42,3 @@
#include "pthread_setcanceltype.c"
#include "pthread_testcancel.c"
#include "pthread_cancel.c"
-
diff --git a/cleanup.c b/cleanup.c
index ed86f10..39f8404 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -74,17 +74,17 @@ ptw32_pop_cleanup (int execute)
*/
{
ptw32_cleanup_t *cleanup = NULL;
-
+
cleanup = (ptw32_cleanup_t *) pthread_getspecific (ptw32_cleanupKey);
if (cleanup != NULL)
{
if (execute && (cleanup->routine != NULL))
- {
+ {
(*cleanup->routine) (cleanup->arg);
- }
+ }
pthread_setspecific (ptw32_cleanupKey, (void *) cleanup->prev);
@@ -92,13 +92,12 @@ ptw32_pop_cleanup (int execute)
return (cleanup);
-} /* ptw32_pop_cleanup */
+} /* ptw32_pop_cleanup */
void
ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
- ptw32_cleanup_callback_t routine,
- void *arg)
+ ptw32_cleanup_callback_t routine, void *arg)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -146,4 +145,4 @@ ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
pthread_setspecific (ptw32_cleanupKey, (void *) cleanup);
-} /* ptw32_push_cleanup */
+} /* ptw32_push_cleanup */
diff --git a/config.h b/config.h
index b20fa6f..4759662 100644
--- a/config.h
+++ b/config.h
@@ -3,6 +3,10 @@
#ifndef PTW32_CONFIG_H
#define PTW32_CONFIG_H
+/*********************************************************************
+ * Defaults: see target specific redefinitions below.
+ *********************************************************************/
+
/* We're building the pthreads-win32 library */
#define PTW32_BUILD
@@ -42,9 +46,13 @@
/* Define if you have the timespec struct */
#undef HAVE_STRUCT_TIMESPEC
-/*
+/* Define if you don't have the GetProcessAffinityMask() */
+#undef NEED_PROCESS_AFFINITY_MASK
+
+
+/*********************************************************************
* Target specific groups
- */
+ *********************************************************************/
#ifdef WINCE
#define NEED_DUPLICATEHANDLE
#define NEED_CREATETHREAD
@@ -53,6 +61,7 @@
#define NEED_FTIME
#define NEED_SEM
#define NEED_UNICODE_CONSTS
+#define NEED_PROCESS_AFFINITY_MASK
#endif
#ifdef _UWIN
@@ -68,4 +77,7 @@
#define HAVE_MODE_T
#endif
+#ifdef __WATCOMC__
+#endif
+
#endif
diff --git a/create.c b/create.c
index cc4629b..d6988b7 100644
--- a/create.c
+++ b/create.c
@@ -44,8 +44,7 @@
int
pthread_create (pthread_t * tid,
const pthread_attr_t * attr,
- void *(*start) (void *),
- void *arg)
+ void *(*start) (void *), void *arg)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -54,16 +53,16 @@ pthread_create (pthread_t * tid,
*
* PARAMETERS
* tid
- * pointer to an instance of pthread_t
+ * pointer to an instance of pthread_t
*
* attr
- * optional pointer to an instance of pthread_attr_t
+ * optional pointer to an instance of pthread_attr_t
*
* start
- * pointer to the starting routine for the new thread
+ * pointer to the starting routine for the new thread
*
* arg
- * optional parameter passed to 'start'
+ * optional parameter passed to 'start'
*
*
* DESCRIPTION
@@ -74,9 +73,9 @@ pthread_create (pthread_t * tid,
* as 'tid'
*
* RESULTS
- * 0 successfully created thread,
- * EINVAL attr invalid,
- * EAGAIN insufficient resources.
+ * 0 successfully created thread,
+ * EINVAL attr invalid,
+ * EAGAIN insufficient resources.
*
* ------------------------------------------------------
*/
@@ -89,7 +88,7 @@ pthread_create (pthread_t * tid,
long stackSize;
int priority;
- if ((thread = ptw32_new()) == NULL)
+ if ((thread = ptw32_new ()) == NULL)
{
goto FAIL0;
}
@@ -117,9 +116,9 @@ pthread_create (pthread_t * tid,
#endif /* HAVE_SIGSET_T */
-#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
+#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
/* WinCE */
-#else
+#else
/* Everything else */
/*
@@ -135,18 +134,18 @@ pthread_create (pthread_t * tid,
* PTHREAD_EXPLICIT_SCHED and priority THREAD_PRIORITY_NORMAL.
*/
if (PTHREAD_INHERIT_SCHED == (*attr)->inheritsched)
- {
- /*
- * If the thread that called pthread_create() is a Win32 thread
- * then the inherited priority could be the result of a temporary
- * system adjustment. This is not the case for POSIX threads.
- */
- pthread_t self = pthread_self();
- priority = self->sched_priority;
- }
-
-#endif
-
+ {
+ /*
+ * If the thread that called pthread_create() is a Win32 thread
+ * then the inherited priority could be the result of a temporary
+ * system adjustment. This is not the case for POSIX threads.
+ */
+ pthread_t self = pthread_self ();
+ priority = self->sched_priority;
+ }
+
+#endif
+
}
else
{
@@ -156,9 +155,7 @@ pthread_create (pthread_t * tid,
stackSize = PTHREAD_STACK_MIN;
}
- thread->state = run
- ? PThreadStateInitial
- : PThreadStateSuspended;
+ thread->state = run ? PThreadStateInitial : PThreadStateSuspended;
thread->keys = NULL;
@@ -173,25 +170,25 @@ pthread_create (pthread_t * tid,
#if ! defined (__MINGW32__) || defined (__MSVCRT__)
- thread->threadH = threadH = (HANDLE)
- _beginthreadex (
- (void *) NULL, /* No security info */
- (unsigned) stackSize, /* default stack size */
- ptw32_threadStart,
- parms,
- (unsigned) CREATE_SUSPENDED,
- (unsigned *) &(thread->thread));
+ thread->threadH = threadH = (HANDLE) _beginthreadex ((void *) NULL, /* No security info */
+ (unsigned) stackSize, /* default stack size */
+ ptw32_threadStart,
+ parms,
+ (unsigned)
+ CREATE_SUSPENDED,
+ (unsigned *) &(thread->
+ thread));
if (threadH != 0)
{
if (attr != NULL && *attr != NULL)
{
- (void) ptw32_setthreadpriority(thread, SCHED_OTHER, priority);
+ (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority);
}
if (run)
{
- ResumeThread(threadH);
+ ResumeThread (threadH);
}
}
@@ -201,24 +198,21 @@ pthread_create (pthread_t * tid,
* This lock will force pthread_threadStart() to wait until we have
* the thread handle and have set the priority.
*/
- (void) pthread_mutex_lock(&thread->cancelLock);
+ (void) pthread_mutex_lock (&thread->cancelLock);
- thread->threadH = threadH = (HANDLE)
- _beginthread (
- ptw32_threadStart,
- (unsigned) stackSize, /* default stack size */
- parms);
+ thread->threadH = threadH = (HANDLE) _beginthread (ptw32_threadStart, (unsigned) stackSize, /* default stack size */
+ parms);
/*
* Make the return code match _beginthreadex's.
*/
- if (threadH == (HANDLE) -1L)
+ if (threadH == (HANDLE) - 1L)
{
thread->threadH = threadH = 0;
}
else
{
- if (! run)
+ if (!run)
{
/*
* beginthread does not allow for create flags, so we do it now.
@@ -227,14 +221,14 @@ pthread_create (pthread_t * tid,
*/
SuspendThread (threadH);
}
-
+
if (attr != NULL && *attr != NULL)
{
- (void) ptw32_setthreadpriority(thread, SCHED_OTHER, priority);
+ (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority);
}
}
- (void) pthread_mutex_unlock(&thread->cancelLock);
+ (void) pthread_mutex_unlock (&thread->cancelLock);
#endif /* __MINGW32__ && ! __MSVCRT__ */
@@ -265,10 +259,9 @@ FAIL0:
*tid = thread;
#ifdef _UWIN
- if (result == 0)
- pthread_count++;
+ if (result == 0)
+ pthread_count++;
#endif
return (result);
} /* pthread_create */
-
diff --git a/dll.c b/dll.c
index 9c8d69d..d9c3176 100644
--- a/dll.c
+++ b/dll.c
@@ -54,14 +54,9 @@
* Dear c++: Please don't mangle this name. -thanks
*/
extern "C"
-#endif /* __cplusplus */
-
-BOOL WINAPI
-DllMain (
- HINSTANCE hinstDll,
- DWORD fdwReason,
- LPVOID lpvReserved
-)
+#endif /* __cplusplus */
+ BOOL WINAPI
+DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
BOOL result = PTW32_TRUE;
@@ -69,26 +64,26 @@ DllMain (
{
case DLL_PROCESS_ATTACH:
- result = pthread_win32_process_attach_np();
+ result = pthread_win32_process_attach_np ();
break;
case DLL_THREAD_ATTACH:
/*
* A thread is being created
*/
- result = pthread_win32_thread_attach_np();
+ result = pthread_win32_thread_attach_np ();
break;
case DLL_THREAD_DETACH:
/*
* A thread is exiting cleanly
*/
- result = pthread_win32_thread_detach_np();
+ result = pthread_win32_thread_detach_np ();
break;
case DLL_PROCESS_DETACH:
- (void) pthread_win32_thread_detach_np();
- result = pthread_win32_process_detach_np();
+ (void) pthread_win32_thread_detach_np ();
+ result = pthread_win32_process_detach_np ();
break;
}
return (result);
diff --git a/errno.c b/errno.c
index 7f3cf4e..99fe106 100644
--- a/errno.c
+++ b/errno.c
@@ -40,7 +40,7 @@
#include "pthread.h"
#include "implement.h"
-static int reallyBad = ENOMEM;
+static int reallyBad = ENOMEM;
/*
* Re-entrant errno.
@@ -68,12 +68,13 @@ static int reallyBad = ENOMEM;
*
*/
-int * _errno( void )
+int *
+_errno (void)
{
- pthread_t self;
- int *result;
+ pthread_t self;
+ int *result;
- if( ( self = pthread_self() ) == NULL )
+ if ((self = pthread_self ()) == NULL)
{
/*
* Yikes! unable to allocate a thread!
@@ -86,9 +87,8 @@ int * _errno( void )
result = &(self->ptErrno);
}
- return( result );
+ return (result);
-} /* _errno */
+} /* _errno */
#endif /* (NEED_ERRNO) */
-
diff --git a/fork.c b/fork.c
index 01e766f..40b00b6 100644
--- a/fork.c
+++ b/fork.c
@@ -37,4 +37,3 @@
#include "pthread.h"
#include "implement.h"
-
diff --git a/global.c b/global.c
index 59ebc45..0f7622b 100644
--- a/global.c
+++ b/global.c
@@ -48,13 +48,26 @@ pthread_cond_t ptw32_cond_list_tail = NULL;
int ptw32_concurrency = 0;
+/* What features have been auto-detaected */
+int ptw32_features = 0;
+
/*
- * Function pointer to InterlockedCompareExchange if it exists; otherwise NULL
+ * Function pointer to InterlockedCompareExchange if it exists, otherwise
+ * it will be set at runtime to a substitute local version with the same
+ * functionality but may be architecture specific.
*/
PTW32_INTERLOCKED_LONG
-(WINAPI *ptw32_interlocked_compare_exchange)(PTW32_INTERLOCKED_LPLONG,
- PTW32_INTERLOCKED_LONG,
- PTW32_INTERLOCKED_LONG) = NULL;
+ (WINAPI * ptw32_interlocked_compare_exchange) (PTW32_INTERLOCKED_LPLONG,
+ PTW32_INTERLOCKED_LONG,
+ PTW32_INTERLOCKED_LONG) =
+ NULL;
+
+/*
+ * Function pointer to QueueUserAPCEx if it exists, otherwise
+ * it will be set at runtime to a substitute routine which cannot unblock
+ * blocked threads.
+ */
+DWORD (*ptw32_register_cancelation) (PAPCFUNC, HANDLE, DWORD) = NULL;
/*
* Global lock for managing pthread_t struct reuse.
diff --git a/implement.h b/implement.h
index ae8f32e..b15f26e 100644
--- a/implement.h
+++ b/implement.h
@@ -38,17 +38,17 @@
#ifndef _IMPLEMENT_H
#define _IMPLEMENT_H
+#include <windows.h>
/*
* note: ETIMEDOUT is correctly defined in winsock.h
*/
-#include <windows.h>
#include <winsock.h>
/*
* In case ETIMEDOUT hasn't been defined above somehow.
*/
#ifndef ETIMEDOUT
-# define ETIMEDOUT 10060 /* This is the value in winsock.h. */
+# define ETIMEDOUT 10060 /* This is the value in winsock.h. */
#endif
#if !defined(malloc)
@@ -77,63 +77,66 @@
#define PTW32_INTERLOCKED_LPLONG PVOID*
#endif
-typedef enum {
+typedef enum
+{
/*
* This enumeration represents the state of the thread;
* The thread is still "alive" if the numeric value of the
* state is greater or equal "PThreadStateRunning".
*/
- PThreadStateInitial = 0, /* Thread not running */
- PThreadStateRunning, /* Thread alive & kicking */
- PThreadStateSuspended, /* Thread alive but suspended */
- PThreadStateCanceling, /* Thread alive but is */
- /* in the process of terminating */
- /* due to a cancellation request */
- PThreadStateException, /* Thread alive but exiting */
- /* due to an exception */
+ PThreadStateInitial = 0, /* Thread not running */
+ PThreadStateRunning, /* Thread alive & kicking */
+ PThreadStateSuspended, /* Thread alive but suspended */
+ PThreadStateCanceling, /* Thread alive but is */
+ /* in the process of terminating */
+ /* due to a cancellation request */
+ PThreadStateException, /* Thread alive but exiting */
+ /* due to an exception */
PThreadStateLast
}
PThreadState;
-typedef enum {
+typedef enum
+{
/*
* This enumeration represents the reason why a thread has
* terminated/is terminating.
*/
- PThreadDemisePeaceful = 0, /* Death due natural causes */
- PThreadDemiseCancelled, /* Death due to user cancel */
- PThreadDemiseException, /* Death due to unhandled */
- /* exception */
- PThreadDemiseNotDead /* I'm not dead! */
+ PThreadDemisePeaceful = 0, /* Death due natural causes */
+ PThreadDemiseCancelled, /* Death due to user cancel */
+ PThreadDemiseException, /* Death due to unhandled */
+ /* exception */
+ PThreadDemiseNotDead /* I'm not dead! */
}
PThreadDemise;
-struct pthread_t_ {
+struct pthread_t_
+{
#ifdef _UWIN
DWORD dummy[5];
#endif
DWORD thread;
- HANDLE threadH; /* POSIX thread is invalid if threadH == 0 */
- pthread_t prevReuse; /* Links threads on reuse stack */
+ HANDLE threadH; /* POSIX thread is invalid if threadH == 0 */
+ pthread_t prevReuse; /* Links threads on reuse stack */
PThreadState state;
PThreadDemise demise;
void *exitStatus;
void *parms;
int ptErrno;
int detachState;
- pthread_mutex_t threadLock; /* Used for serialised access to public thread state */
- int sched_priority; /* As set, not as currently is */
- pthread_mutex_t cancelLock; /* Used for async-cancel safety */
+ pthread_mutex_t threadLock; /* Used for serialised access to public thread state */
+ int sched_priority; /* As set, not as currently is */
+ pthread_mutex_t cancelLock; /* Used for async-cancel safety */
int cancelState;
int cancelType;
HANDLE cancelEvent;
#ifdef __CLEANUP_C
jmp_buf start_mark;
-#endif /* __CLEANUP_C */
+#endif /* __CLEANUP_C */
#if HAVE_SIGSET_T
sigset_t sigmask;
-#endif /* HAVE_SIGSET_T */
+#endif /* HAVE_SIGSET_T */
int implicit:1;
void *keys;
};
@@ -144,7 +147,8 @@ struct pthread_t_ {
*/
#define PTW32_ATTR_VALID ((unsigned long) 0xC4C0FFEE)
-struct pthread_attr_t_ {
+struct pthread_attr_t_
+{
unsigned long valid;
void *stackaddr;
size_t stacksize;
@@ -154,7 +158,7 @@ struct pthread_attr_t_ {
int contentionscope;
#if HAVE_SIGSET_T
sigset_t sigmask;
-#endif /* HAVE_SIGSET_T */
+#endif /* HAVE_SIGSET_T */
};
@@ -166,36 +170,39 @@ struct pthread_attr_t_ {
* ====================
*/
-struct sem_t_ {
+struct sem_t_
+{
#ifdef NEED_SEM
- unsigned int value;
+ unsigned int value;
CRITICAL_SECTION sem_lock_cs;
- HANDLE event;
-#else /* NEED_SEM */
+ HANDLE event;
+#else /* NEED_SEM */
HANDLE sem;
-#endif /* NEED_SEM */
+#endif /* NEED_SEM */
};
#define PTW32_OBJECT_AUTO_INIT ((void *) -1)
#define PTW32_OBJECT_INVALID NULL
-struct pthread_mutex_t_ {
- LONG lock_idx; /* Provides exclusive access to mutex state
- via the Interlocked* mechanism, as well
- as a count of the number of threads
- waiting on the mutex. */
- int recursive_count; /* Number of unlocks a thread needs to perform
- before the lock is released (recursive
- mutexes only). */
- int kind; /* Mutex type. */
+struct pthread_mutex_t_
+{
+ LONG lock_idx; /* Provides exclusive access to mutex state
+ via the Interlocked* mechanism, as well
+ as a count of the number of threads
+ waiting on the mutex. */
+ int recursive_count; /* Number of unlocks a thread needs to perform
+ before the lock is released (recursive
+ mutexes only). */
+ int kind; /* Mutex type. */
pthread_t ownerThread;
- sem_t wait_sema; /* Mutex release notification to waiting
- threads. */
- CRITICAL_SECTION wait_cs; /* Serialise lock_idx decrement after mutex
- timeout. */
+ sem_t wait_sema; /* Mutex release notification to waiting
+ threads. */
+ CRITICAL_SECTION wait_cs; /* Serialise lock_idx decrement after mutex
+ timeout. */
};
-struct pthread_mutexattr_t_ {
+struct pthread_mutexattr_t_
+{
int pshared;
int kind;
};
@@ -221,15 +228,18 @@ struct pthread_mutexattr_t_ {
#define PTW32_SPIN_LOCKED (2)
#define PTW32_SPIN_USE_MUTEX (3)
-struct pthread_spinlock_t_ {
- long interlock; /* Locking element for multi-cpus. */
- union {
- int cpus; /* No. of cpus if multi cpus, or */
- pthread_mutex_t mutex; /* mutex if single cpu. */
+struct pthread_spinlock_t_
+{
+ long interlock; /* Locking element for multi-cpus. */
+ union
+ {
+ int cpus; /* No. of cpus if multi cpus, or */
+ pthread_mutex_t mutex; /* mutex if single cpu. */
} u;
};
-struct pthread_barrier_t_ {
+struct pthread_barrier_t_
+{
unsigned int nCurrentBarrierHeight;
unsigned int nInitialBarrierHeight;
int iStep;
@@ -237,11 +247,13 @@ struct pthread_barrier_t_ {
sem_t semBarrierBreeched[2];
};
-struct pthread_barrierattr_t_ {
+struct pthread_barrierattr_t_
+{
int pshared;
};
-struct pthread_key_t_ {
+struct pthread_key_t_
+{
DWORD key;
void (*destructor) (void *);
pthread_mutex_t threadsLock;
@@ -252,52 +264,58 @@ struct pthread_key_t_ {
typedef struct ThreadParms ThreadParms;
typedef struct ThreadKeyAssoc ThreadKeyAssoc;
-struct ThreadParms {
+struct ThreadParms
+{
pthread_t tid;
void *(*start) (void *);
void *arg;
};
-struct pthread_cond_t_ {
- long nWaitersBlocked; /* Number of threads blocked */
- long nWaitersGone; /* Number of threads timed out */
- long nWaitersToUnblock; /* Number of threads to unblock */
- sem_t semBlockQueue; /* Queue up threads waiting for the */
- /* condition to become signalled */
- sem_t semBlockLock; /* Semaphore that guards access to */
- /* | waiters blocked count/block queue */
- /* +-> Mandatory Sync.LEVEL-1 */
- pthread_mutex_t mtxUnblockLock; /* Mutex that guards access to */
- /* | waiters (to)unblock(ed) counts */
- /* +-> Optional* Sync.LEVEL-2 */
- pthread_cond_t next; /* Doubly linked list */
+struct pthread_cond_t_
+{
+ long nWaitersBlocked; /* Number of threads blocked */
+ long nWaitersGone; /* Number of threads timed out */
+ long nWaitersToUnblock; /* Number of threads to unblock */
+ sem_t semBlockQueue; /* Queue up threads waiting for the */
+ /* condition to become signalled */
+ sem_t semBlockLock; /* Semaphore that guards access to */
+ /* | waiters blocked count/block queue */
+ /* +-> Mandatory Sync.LEVEL-1 */
+ pthread_mutex_t mtxUnblockLock; /* Mutex that guards access to */
+ /* | waiters (to)unblock(ed) counts */
+ /* +-> Optional* Sync.LEVEL-2 */
+ pthread_cond_t next; /* Doubly linked list */
pthread_cond_t prev;
};
-struct pthread_condattr_t_ {
+struct pthread_condattr_t_
+{
int pshared;
};
#define PTW32_RWLOCK_MAGIC 0xfacade2
-struct pthread_rwlock_t_ {
- pthread_mutex_t mtxExclusiveAccess;
- pthread_mutex_t mtxSharedAccessCompleted;
- pthread_cond_t cndSharedAccessCompleted;
- int nSharedAccessCount;
- int nExclusiveAccessCount;
- int nCompletedSharedAccessCount;
- int nMagic;
+struct pthread_rwlock_t_
+{
+ pthread_mutex_t mtxExclusiveAccess;
+ pthread_mutex_t mtxSharedAccessCompleted;
+ pthread_cond_t cndSharedAccessCompleted;
+ int nSharedAccessCount;
+ int nExclusiveAccessCount;
+ int nCompletedSharedAccessCount;
+ int nMagic;
};
-struct pthread_rwlockattr_t_ {
- int pshared;
+struct pthread_rwlockattr_t_
+{
+ int pshared;
};
-struct ThreadKeyAssoc {
+struct ThreadKeyAssoc
+{
/*
* Purpose:
* This structure creates an association between a
@@ -411,8 +429,9 @@ struct ThreadKeyAssoc {
#define PTW32_EPS_CANCEL (2)
/* Mutex constants */
-enum {
- PTW32_MUTEX_LOCK_IDX_INIT = -1,
+enum
+{
+ PTW32_MUTEX_LOCK_IDX_INIT = -1,
PTW32_MUTEX_OWNER_ANONYMOUS = 1
};
@@ -423,9 +442,12 @@ enum {
/* Declared in global.c */
-extern PTW32_INTERLOCKED_LONG (WINAPI *ptw32_interlocked_compare_exchange)(PTW32_INTERLOCKED_LPLONG,
- PTW32_INTERLOCKED_LONG,
- PTW32_INTERLOCKED_LONG);
+extern PTW32_INTERLOCKED_LONG (WINAPI *
+ ptw32_interlocked_compare_exchange)
+ (PTW32_INTERLOCKED_LPLONG, PTW32_INTERLOCKED_LONG, PTW32_INTERLOCKED_LONG);
+
+/* Declared in pthread_cancel.c */
+extern DWORD (*ptw32_register_cancelation) (PAPCFUNC, HANDLE, DWORD);
/* Thread Reuse stack bottom marker. Must not be NULL or any valid pointer to memory. */
#define PTW32_THREAD_REUSE_BOTTOM ((pthread_t) 1)
@@ -441,6 +463,8 @@ extern int ptw32_mutex_default_kind;
extern int ptw32_concurrency;
+extern int ptw32_features;
+
extern CRITICAL_SECTION ptw32_thread_reuse_lock;
extern CRITICAL_SECTION ptw32_mutex_test_init_lock;
extern CRITICAL_SECTION ptw32_cond_list_lock;
@@ -452,18 +476,10 @@ extern CRITICAL_SECTION ptw32_spinlock_test_init_lock;
extern int pthread_count;
#endif
-/* Declared in misc.c */
-#ifdef NEED_CALLOC
-#define calloc(n, s) ptw32_calloc(n, s)
-void *ptw32_calloc(size_t n, size_t s);
-#endif
-
-/* Declared in private.c */
-void ptw32_throw(DWORD exception);
-
#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+extern "C"
+{
+#endif /* __cplusplus */
/*
* =====================
@@ -473,84 +489,97 @@ extern "C" {
* =====================
*/
-int ptw32_is_attr (const pthread_attr_t *attr);
+ int ptw32_is_attr (const pthread_attr_t * attr);
+
+ int ptw32_cond_check_need_init (pthread_cond_t * cond);
+ int ptw32_mutex_check_need_init (pthread_mutex_t * mutex);
+ int ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock);
-int ptw32_cond_check_need_init(pthread_cond_t *cond);
-int ptw32_mutex_check_need_init(pthread_mutex_t *mutex);
-int ptw32_rwlock_check_need_init(pthread_rwlock_t *rwlock);
+ PTW32_INTERLOCKED_LONG WINAPI
+ ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_LPLONG location,
+ PTW32_INTERLOCKED_LONG value,
+ PTW32_INTERLOCKED_LONG comparand);
-PTW32_INTERLOCKED_LONG WINAPI
-ptw32_InterlockedCompareExchange(PTW32_INTERLOCKED_LPLONG location,
- PTW32_INTERLOCKED_LONG value,
- PTW32_INTERLOCKED_LONG comparand);
+ DWORD
+ ptw32_RegisterCancelation (PAPCFUNC callback,
+ HANDLE threadH, DWORD callback_arg);
-int ptw32_processInitialize (void);
+ int ptw32_processInitialize (void);
-void ptw32_processTerminate (void);
+ void ptw32_processTerminate (void);
-void ptw32_threadDestroy (pthread_t tid);
+ void ptw32_threadDestroy (pthread_t tid);
-void ptw32_pop_cleanup_all (int execute);
+ void ptw32_pop_cleanup_all (int execute);
-pthread_t ptw32_new (void);
+ pthread_t ptw32_new (void);
-pthread_t ptw32_threadReusePop (void);
+ pthread_t ptw32_threadReusePop (void);
-void ptw32_threadReusePush (pthread_t thread);
+ void ptw32_threadReusePush (pthread_t thread);
-int ptw32_getprocessors (int * count);
+ int ptw32_getprocessors (int *count);
-int ptw32_setthreadpriority (pthread_t thread,
- int policy,
- int priority);
+ int ptw32_setthreadpriority (pthread_t thread, int policy, int priority);
-void ptw32_rwlock_cancelwrwait(void * arg);
+ void ptw32_rwlock_cancelwrwait (void *arg);
#if ! defined (__MINGW32__) || defined (__MSVCRT__)
-unsigned __stdcall
+ unsigned __stdcall
#else
-void
+ void
#endif
-ptw32_threadStart (void * vthreadParms);
+ ptw32_threadStart (void *vthreadParms);
-void ptw32_callUserDestroyRoutines (pthread_t thread);
+ void ptw32_callUserDestroyRoutines (pthread_t thread);
-int ptw32_tkAssocCreate (ThreadKeyAssoc ** assocP,
- pthread_t thread,
- pthread_key_t key);
+ int ptw32_tkAssocCreate (ThreadKeyAssoc ** assocP,
+ pthread_t thread, pthread_key_t key);
-void ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc);
+ void ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc);
+ int ptw32_semwait (sem_t * sem);
#ifdef NEED_SEM
-void ptw32_decrease_semaphore(sem_t * sem);
-BOOL ptw32_increase_semaphore(sem_t * sem,
- unsigned int n);
-#endif /* NEED_SEM */
+ void ptw32_decrease_semaphore (sem_t * sem);
+ BOOL ptw32_increase_semaphore (sem_t * sem, unsigned int n);
+#endif /* NEED_SEM */
#ifdef NEED_FTIME
-void ptw32_timespec_to_filetime(const struct timespec *ts, FILETIME *ft);
-void ptw32_filetime_to_timespec(const FILETIME *ft, struct timespec *ts);
+ void ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft);
+ void ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts);
#endif
+/* Declared in misc.c */
+#ifdef NEED_CALLOC
+#define calloc(n, s) ptw32_calloc(n, s)
+ void *ptw32_calloc (size_t n, size_t s);
+#endif
+
+/* Declared in private.c */
+ void ptw32_throw (DWORD exception);
+
#ifdef __cplusplus
}
-#endif /* __cplusplus */
+#endif /* __cplusplus */
#ifdef _UWIN_
# ifdef _MT
# ifdef __cplusplus
- extern "C" {
+extern "C"
+{
# endif
- _CRTIMP unsigned long __cdecl _beginthread (void (__cdecl *) (void *),
- unsigned, void *);
- _CRTIMP void __cdecl _endthread(void);
- _CRTIMP unsigned long __cdecl _beginthreadex(void *, unsigned,
- unsigned (__stdcall *) (void *), void *, unsigned, unsigned *);
- _CRTIMP void __cdecl _endthreadex(unsigned);
+ _CRTIMP unsigned long __cdecl _beginthread (void (__cdecl *) (void *),
+ unsigned, void *);
+ _CRTIMP void __cdecl _endthread (void);
+ _CRTIMP unsigned long __cdecl _beginthreadex (void *, unsigned,
+ unsigned (__stdcall *) (void
+ *),
+ void *, unsigned, unsigned *);
+ _CRTIMP void __cdecl _endthreadex (unsigned);
# ifdef __cplusplus
- }
+}
# endif
# endif
#else
@@ -586,8 +615,7 @@ void ptw32_filetime_to_timespec(const FILETIME *ft, struct timespec *ts);
#define _endthreadex ExitThread
-#endif /* __CYGWIN32__ || __CYGWIN__ || NEED_CREATETHREAD*/
-
+#endif /* __CYGWIN32__ || __CYGWIN__ || NEED_CREATETHREAD */
-#endif /* _IMPLEMENT_H */
+#endif /* _IMPLEMENT_H */
diff --git a/misc.c b/misc.c
index ad47077..697a861 100644
--- a/misc.c
+++ b/misc.c
@@ -48,4 +48,3 @@
#include "ptw32_calloc.c"
#include "ptw32_reuse.c"
#include "w32_CancelableWait.c"
-
diff --git a/mutex.c b/mutex.c
index 6416e1b..d2a311a 100644
--- a/mutex.c
+++ b/mutex.c
@@ -57,6 +57,3 @@
#include "pthread_mutex_timedlock.c"
#include "pthread_mutex_unlock.c"
#include "pthread_mutex_trylock.c"
-
-
-
diff --git a/nonportable.c b/nonportable.c
index ef0256c..bf7855b 100644
--- a/nonportable.c
+++ b/nonportable.c
@@ -44,4 +44,3 @@
#include "pthread_num_processors_np.c"
#include "pthread_win32_attach_detach_np.c"
#include "pthread_timechange_handler_np.c"
-
diff --git a/private.c b/private.c
index 6f0dcc6..6f59e5c 100644
--- a/private.c
+++ b/private.c
@@ -47,6 +47,7 @@
#include "ptw32_tkAssocCreate.c"
#include "ptw32_tkAssocDestroy.c"
#include "ptw32_callUserDestroyRoutines.c"
+#include "ptw32_semwait.c"
#include "ptw32_timespec.c"
#include "ptw32_throw.c"
#include "ptw32_InterlockedCompareExchange.c"
diff --git a/pthread.c b/pthread.c
index 03fd7bd..8be21cd 100644
--- a/pthread.c
+++ b/pthread.c
@@ -39,6 +39,9 @@
#include "pthread.h"
#include "implement.h"
+/* The following are ordered for inlining */
+
+#include "private.c"
#include "attr.c"
#include "barrier.c"
#include "cancel.c"
@@ -53,7 +56,6 @@
#include "misc.c"
#include "mutex.c"
#include "nonportable.c"
-#include "private.c"
#include "rwlock.c"
#include "sched.c"
#include "semaphore.c"
diff --git a/pthread.h b/pthread.h
index 56759b5..0c42fc6 100644
--- a/pthread.h
+++ b/pthread.h
@@ -155,15 +155,14 @@
#ifdef PTW32_INCLUDE_WINDOWS_H
#include <windows.h>
+#endif
-#if _MSC_VER < 1300
+#if defined(_MSC_VER) && _MSC_VER < 1300
/*
* VC++6.0 or early compiler's header has no DWORD_PTR type.
*/
typedef unsigned long DWORD_PTR;
#endif
-#endif
-
/*
* -----------------
* autoconf switches
@@ -507,11 +506,12 @@ extern "C"
/*
* The Open Watcom C/C++ compiler uses a non-standard calling convention
* that passes function args in registers unless __cdecl is explicitly specified
- * in function prototypes.
+ * in exposed function prototypes.
*
- * We force all calls to cdecl even though this will slow Watcom code down
+ * We force all calls to cdecl even though this could slow Watcom code down
* slightly. If you know that the Watcom compiler will be used to build both
- * the DLL and application, then you could probably define this as a null string.
+ * the DLL and application, then you can probably define this as a null string.
+ * Remember that pthread.h (this file) is used for both the DLL and application builds.
*/
#define PTW32_CDECL __cdecl
@@ -1137,6 +1137,15 @@ PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
/*
+ * Features that are auto-detected at load/run time.
+ */
+PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
+enum ptw32_features {
+ PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
+ PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */
+};
+
+/*
* Register a system time change with the library.
* Causes the library to perform various functions
* in response to the change. Should be called whenever
diff --git a/pthread_attr_destroy.c b/pthread_attr_destroy.c
index 0fccdd6..e1d8a0c 100644
--- a/pthread_attr_destroy.c
+++ b/pthread_attr_destroy.c
@@ -39,7 +39,7 @@
int
-pthread_attr_destroy(pthread_attr_t *attr)
+pthread_attr_destroy (pthread_attr_t * attr)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -63,7 +63,7 @@ pthread_attr_destroy(pthread_attr_t *attr)
* ------------------------------------------------------
*/
{
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -77,4 +77,3 @@ pthread_attr_destroy(pthread_attr_t *attr)
return 0;
}
-
diff --git a/pthread_attr_getdetachstate.c b/pthread_attr_getdetachstate.c
index 8ae6c8a..3c0265b 100644
--- a/pthread_attr_getdetachstate.c
+++ b/pthread_attr_getdetachstate.c
@@ -39,8 +39,7 @@
int
-pthread_attr_getdetachstate(const pthread_attr_t *attr,
- int *detachstate)
+pthread_attr_getdetachstate (const pthread_attr_t * attr, int *detachstate)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -77,7 +76,7 @@ pthread_attr_getdetachstate(const pthread_attr_t *attr,
* ------------------------------------------------------
*/
{
- if (ptw32_is_attr(attr) != 0 || detachstate == NULL)
+ if (ptw32_is_attr (attr) != 0 || detachstate == NULL)
{
*detachstate = PTHREAD_CREATE_DETACHED;
return EINVAL;
@@ -86,4 +85,3 @@ pthread_attr_getdetachstate(const pthread_attr_t *attr,
*detachstate = (*attr)->detachstate;
return 0;
}
-
diff --git a/pthread_attr_getinheritsched.c b/pthread_attr_getinheritsched.c
index e99583a..21a85a4 100644
--- a/pthread_attr_getinheritsched.c
+++ b/pthread_attr_getinheritsched.c
@@ -39,10 +39,9 @@
#include "sched.h"
int
-pthread_attr_getinheritsched(pthread_attr_t * attr,
- int * inheritsched)
+pthread_attr_getinheritsched (pthread_attr_t * attr, int *inheritsched)
{
- if (ptw32_is_attr(attr) != 0 || inheritsched == NULL)
+ if (ptw32_is_attr (attr) != 0 || inheritsched == NULL)
{
return EINVAL;
}
diff --git a/pthread_attr_getschedparam.c b/pthread_attr_getschedparam.c
index 015ec0c..48b4779 100644
--- a/pthread_attr_getschedparam.c
+++ b/pthread_attr_getschedparam.c
@@ -38,15 +38,15 @@
#include "implement.h"
#include "sched.h"
-int
-pthread_attr_getschedparam(const pthread_attr_t *attr,
- struct sched_param *param)
+int
+pthread_attr_getschedparam (const pthread_attr_t * attr,
+ struct sched_param *param)
{
- if (ptw32_is_attr(attr) != 0 || param == NULL)
+ if (ptw32_is_attr (attr) != 0 || param == NULL)
{
return EINVAL;
}
-
- memcpy(param, &(*attr)->param, sizeof(*param));
+
+ memcpy (param, &(*attr)->param, sizeof (*param));
return 0;
}
diff --git a/pthread_attr_getschedpolicy.c b/pthread_attr_getschedpolicy.c
index 76c9be3..cd84ffd 100644
--- a/pthread_attr_getschedpolicy.c
+++ b/pthread_attr_getschedpolicy.c
@@ -39,10 +39,9 @@
#include "sched.h"
int
-pthread_attr_getschedpolicy(pthread_attr_t *attr,
- int * policy)
+pthread_attr_getschedpolicy (pthread_attr_t * attr, int *policy)
{
- if (ptw32_is_attr(attr) != 0 || policy == NULL)
+ if (ptw32_is_attr (attr) != 0 || policy == NULL)
{
return EINVAL;
}
diff --git a/pthread_attr_getscope.c b/pthread_attr_getscope.c
index 81f1f3d..6ae422e 100644
--- a/pthread_attr_getscope.c
+++ b/pthread_attr_getscope.c
@@ -43,7 +43,7 @@
#endif
int
-pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
+pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope)
{
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
*contentionscope = (*attr)->contentionscope;
@@ -52,4 +52,3 @@ pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)
return ENOSYS;
#endif
}
-
diff --git a/pthread_attr_getstackaddr.c b/pthread_attr_getstackaddr.c
index 54c0f22..3ddfb28 100644
--- a/pthread_attr_getstackaddr.c
+++ b/pthread_attr_getstackaddr.c
@@ -43,8 +43,7 @@
#endif
int
-pthread_attr_getstackaddr(const pthread_attr_t *attr,
- void **stackaddr)
+pthread_attr_getstackaddr (const pthread_attr_t * attr, void **stackaddr)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -82,7 +81,7 @@ pthread_attr_getstackaddr(const pthread_attr_t *attr,
{
#if defined( _POSIX_THREAD_ATTR_STACKADDR )
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -96,4 +95,3 @@ pthread_attr_getstackaddr(const pthread_attr_t *attr,
#endif /* _POSIX_THREAD_ATTR_STACKADDR */
}
-
diff --git a/pthread_attr_getstacksize.c b/pthread_attr_getstacksize.c
index 69fa8f6..25ac873 100644
--- a/pthread_attr_getstacksize.c
+++ b/pthread_attr_getstacksize.c
@@ -43,8 +43,7 @@
#endif
int
-pthread_attr_getstacksize(const pthread_attr_t *attr,
- size_t *stacksize)
+pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * stacksize)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -83,7 +82,7 @@ pthread_attr_getstacksize(const pthread_attr_t *attr,
{
#ifdef _POSIX_THREAD_ATTR_STACKSIZE
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -99,4 +98,3 @@ pthread_attr_getstacksize(const pthread_attr_t *attr,
#endif /* _POSIX_THREAD_ATTR_STACKSIZE */
}
-
diff --git a/pthread_attr_init.c b/pthread_attr_init.c
index 08f9a41..6eab32a 100644
--- a/pthread_attr_init.c
+++ b/pthread_attr_init.c
@@ -39,7 +39,7 @@
int
-pthread_attr_init(pthread_attr_t *attr)
+pthread_attr_init (pthread_attr_t * attr)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -97,7 +97,7 @@ pthread_attr_init(pthread_attr_t *attr)
attr_result->detachstate = PTHREAD_CREATE_JOINABLE;
#if HAVE_SIGSET_T
- memset(&(attr_result->sigmask), 0, sizeof(sigset_t));
+ memset (&(attr_result->sigmask), 0, sizeof (sigset_t));
#endif /* HAVE_SIGSET_T */
/*
@@ -115,4 +115,3 @@ pthread_attr_init(pthread_attr_t *attr)
return 0;
}
-
diff --git a/pthread_attr_setdetachstate.c b/pthread_attr_setdetachstate.c
index 7a6ba1c..cc8953f 100644
--- a/pthread_attr_setdetachstate.c
+++ b/pthread_attr_setdetachstate.c
@@ -39,8 +39,7 @@
int
-pthread_attr_setdetachstate(pthread_attr_t *attr,
- int detachstate)
+pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -76,7 +75,7 @@ pthread_attr_setdetachstate(pthread_attr_t *attr,
* ------------------------------------------------------
*/
{
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -90,4 +89,3 @@ pthread_attr_setdetachstate(pthread_attr_t *attr,
(*attr)->detachstate = detachstate;
return 0;
}
-
diff --git a/pthread_attr_setinheritsched.c b/pthread_attr_setinheritsched.c
index 84285b3..23d3582 100644
--- a/pthread_attr_setinheritsched.c
+++ b/pthread_attr_setinheritsched.c
@@ -39,10 +39,9 @@
#include "sched.h"
int
-pthread_attr_setinheritsched(pthread_attr_t * attr,
- int inheritsched)
+pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched)
{
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
diff --git a/pthread_attr_setschedparam.c b/pthread_attr_setschedparam.c
index d7a0e70..d8b58bd 100644
--- a/pthread_attr_setschedparam.c
+++ b/pthread_attr_setschedparam.c
@@ -39,12 +39,12 @@
#include "sched.h"
int
-pthread_attr_setschedparam(pthread_attr_t *attr,
- const struct sched_param *param)
+pthread_attr_setschedparam (pthread_attr_t * attr,
+ const struct sched_param *param)
{
int priority;
- if (ptw32_is_attr(attr) != 0 || param == NULL)
+ if (ptw32_is_attr (attr) != 0 || param == NULL)
{
return EINVAL;
}
@@ -52,12 +52,12 @@ pthread_attr_setschedparam(pthread_attr_t *attr,
priority = param->sched_priority;
/* Validate priority level. */
- if (priority < sched_get_priority_min(SCHED_OTHER) ||
- priority > sched_get_priority_max(SCHED_OTHER))
+ if (priority < sched_get_priority_min (SCHED_OTHER) ||
+ priority > sched_get_priority_max (SCHED_OTHER))
{
return EINVAL;
}
- memcpy(&(*attr)->param, param, sizeof(*param));
+ memcpy (&(*attr)->param, param, sizeof (*param));
return 0;
}
diff --git a/pthread_attr_setschedpolicy.c b/pthread_attr_setschedpolicy.c
index f8c4685..bb1c8b9 100644
--- a/pthread_attr_setschedpolicy.c
+++ b/pthread_attr_setschedpolicy.c
@@ -39,10 +39,9 @@
#include "sched.h"
int
-pthread_attr_setschedpolicy (pthread_attr_t *attr,
- int policy)
+pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy)
{
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
diff --git a/pthread_attr_setscope.c b/pthread_attr_setscope.c
index 7cf6a12..b8d9fc5 100644
--- a/pthread_attr_setscope.c
+++ b/pthread_attr_setscope.c
@@ -43,20 +43,20 @@
#endif
int
-pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
+pthread_attr_setscope (pthread_attr_t * attr, int contentionscope)
{
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
- switch (contentionscope) {
- case PTHREAD_SCOPE_SYSTEM:
- (*attr)->contentionscope = contentionscope;
- return 0;
- case PTHREAD_SCOPE_PROCESS:
- return ENOTSUP;
- default:
- return EINVAL;
- }
+ switch (contentionscope)
+ {
+ case PTHREAD_SCOPE_SYSTEM:
+ (*attr)->contentionscope = contentionscope;
+ return 0;
+ case PTHREAD_SCOPE_PROCESS:
+ return ENOTSUP;
+ default:
+ return EINVAL;
+ }
#else
return ENOSYS;
#endif
}
-
diff --git a/pthread_attr_setstackaddr.c b/pthread_attr_setstackaddr.c
index fe1fd9a..dfd1879 100644
--- a/pthread_attr_setstackaddr.c
+++ b/pthread_attr_setstackaddr.c
@@ -39,8 +39,7 @@
int
-pthread_attr_setstackaddr(pthread_attr_t *attr,
- void *stackaddr)
+pthread_attr_setstackaddr (pthread_attr_t * attr, void *stackaddr)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -82,7 +81,7 @@ pthread_attr_setstackaddr(pthread_attr_t *attr,
{
#if defined( _POSIX_THREAD_ATTR_STACKADDR )
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -96,4 +95,3 @@ pthread_attr_setstackaddr(pthread_attr_t *attr,
#endif /* _POSIX_THREAD_ATTR_STACKADDR */
}
-
diff --git a/pthread_attr_setstacksize.c b/pthread_attr_setstacksize.c
index 6eb037b..5b6737f 100644
--- a/pthread_attr_setstacksize.c
+++ b/pthread_attr_setstacksize.c
@@ -39,8 +39,7 @@
int
-pthread_attr_setstacksize(pthread_attr_t *attr,
- size_t stacksize)
+pthread_attr_setstacksize (pthread_attr_t * attr, size_t stacksize)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -93,7 +92,7 @@ pthread_attr_setstacksize(pthread_attr_t *attr,
#endif
- if (ptw32_is_attr(attr) != 0)
+ if (ptw32_is_attr (attr) != 0)
{
return EINVAL;
}
@@ -109,4 +108,3 @@ pthread_attr_setstacksize(pthread_attr_t *attr,
#endif /* _POSIX_THREAD_ATTR_STACKSIZE */
}
-
diff --git a/pthread_barrier_destroy.c b/pthread_barrier_destroy.c
index 5bcce8d..0c58e1b 100644
--- a/pthread_barrier_destroy.c
+++ b/pthread_barrier_destroy.c
@@ -39,7 +39,7 @@
int
-pthread_barrier_destroy(pthread_barrier_t *barrier)
+pthread_barrier_destroy (pthread_barrier_t * barrier)
{
int result = 0;
pthread_barrier_t b;
@@ -52,19 +52,16 @@ pthread_barrier_destroy(pthread_barrier_t *barrier)
b = *barrier;
*barrier = NULL;
- if (0 == (result = sem_destroy(&(b->semBarrierBreeched[0]))))
+ if (0 == (result = sem_destroy (&(b->semBarrierBreeched[0]))))
{
- if (0 == (result = sem_destroy(&(b->semBarrierBreeched[1]))))
- {
- (void) free(b);
- return 0;
- }
- (void) sem_init(&(b->semBarrierBreeched[0]),
- b->pshared,
- 0);
+ if (0 == (result = sem_destroy (&(b->semBarrierBreeched[1]))))
+ {
+ (void) free (b);
+ return 0;
+ }
+ (void) sem_init (&(b->semBarrierBreeched[0]), b->pshared, 0);
}
*barrier = b;
- return(result);
+ return (result);
}
-
diff --git a/pthread_barrier_init.c b/pthread_barrier_init.c
index d8d7877..3603ac3 100644
--- a/pthread_barrier_init.c
+++ b/pthread_barrier_init.c
@@ -39,9 +39,8 @@
int
-pthread_barrier_init(pthread_barrier_t * barrier,
- const pthread_barrierattr_t * attr,
- unsigned int count)
+pthread_barrier_init (pthread_barrier_t * barrier,
+ const pthread_barrierattr_t * attr, unsigned int count)
{
pthread_barrier_t b;
@@ -50,11 +49,10 @@ pthread_barrier_init(pthread_barrier_t * barrier,
return EINVAL;
}
- if (NULL != (b = (pthread_barrier_t) calloc(1, sizeof(*b))))
+ if (NULL != (b = (pthread_barrier_t) calloc (1, sizeof (*b))))
{
b->pshared = (attr != NULL && *attr != NULL
- ? (*attr)->pshared
- : PTHREAD_PROCESS_PRIVATE);
+ ? (*attr)->pshared : PTHREAD_PROCESS_PRIVATE);
b->nCurrentBarrierHeight = b->nInitialBarrierHeight = count;
b->iStep = 0;
@@ -67,18 +65,17 @@ pthread_barrier_init(pthread_barrier_t * barrier,
* If some threads decide to eat their lunch before moving
* then the other threads have to wait.
*/
- if (0 == sem_init(&(b->semBarrierBreeched[0]), b->pshared, 0))
- {
- if (0 == sem_init(&(b->semBarrierBreeched[1]), b->pshared, 0))
- {
- *barrier = b;
- return 0;
- }
- (void) sem_destroy(&(b->semBarrierBreeched[0]));
- }
- (void) free(b);
+ if (0 == sem_init (&(b->semBarrierBreeched[0]), b->pshared, 0))
+ {
+ if (0 == sem_init (&(b->semBarrierBreeched[1]), b->pshared, 0))
+ {
+ *barrier = b;
+ return 0;
+ }
+ (void) sem_destroy (&(b->semBarrierBreeched[0]));
+ }
+ (void) free (b);
}
return ENOMEM;
}
-
diff --git a/pthread_barrier_wait.c b/pthread_barrier_wait.c
index 0de08ca..b067d66 100644
--- a/pthread_barrier_wait.c
+++ b/pthread_barrier_wait.c
@@ -39,7 +39,7 @@
int
-pthread_barrier_wait(pthread_barrier_t *barrier)
+pthread_barrier_wait (pthread_barrier_t * barrier)
{
int result;
int step;
@@ -53,7 +53,7 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
b = *barrier;
step = b->iStep;
- if (0 == InterlockedDecrement((long *) &(b->nCurrentBarrierHeight)))
+ if (0 == InterlockedDecrement ((long *) &(b->nCurrentBarrierHeight)))
{
/* Must be done before posting the semaphore. */
b->nCurrentBarrierHeight = b->nInitialBarrierHeight;
@@ -68,15 +68,14 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
* and will not be left stranded.
*/
result = (b->nInitialBarrierHeight > 1
- ? sem_post_multiple(&(b->semBarrierBreeched[step]),
- b->nInitialBarrierHeight - 1)
- : 0);
+ ? sem_post_multiple (&(b->semBarrierBreeched[step]),
+ b->nInitialBarrierHeight - 1) : 0);
}
else
{
BOOL switchCancelState;
int oldCancelState;
- pthread_t self = pthread_self();
+ pthread_t self = pthread_self ();
/*
* This routine is not a cancelation point, so temporarily
@@ -84,15 +83,16 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
* PTHREAD_CANCEL_ASYNCHRONOUS threads can still be canceled.
*/
switchCancelState = (self->cancelType == PTHREAD_CANCEL_DEFERRED &&
- 0 == pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
- &oldCancelState));
+ 0 ==
+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE,
+ &oldCancelState));
- result = sem_wait(&(b->semBarrierBreeched[step]));
+ result = sem_wait (&(b->semBarrierBreeched[step]));
if (switchCancelState)
- {
- (void) pthread_setcancelstate(oldCancelState, NULL);
- }
+ {
+ (void) pthread_setcancelstate (oldCancelState, NULL);
+ }
}
/*
@@ -102,13 +102,14 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
if (0 == result)
{
result = ((PTW32_INTERLOCKED_LONG) step ==
- ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(b->iStep),
- (PTW32_INTERLOCKED_LONG) (1L - step),
- (PTW32_INTERLOCKED_LONG) step)
- ? PTHREAD_BARRIER_SERIAL_THREAD
- : 0);
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG)
+ & (b->iStep),
+ (PTW32_INTERLOCKED_LONG)
+ (1L - step),
+ (PTW32_INTERLOCKED_LONG)
+ step) ?
+ PTHREAD_BARRIER_SERIAL_THREAD : 0);
}
- return(result);
+ return (result);
}
-
diff --git a/pthread_barrierattr_destroy.c b/pthread_barrierattr_destroy.c
index d9a77ad..d8d7e31 100644
--- a/pthread_barrierattr_destroy.c
+++ b/pthread_barrierattr_destroy.c
@@ -80,5 +80,4 @@ pthread_barrierattr_destroy (pthread_barrierattr_t * attr)
}
return (result);
-} /* pthread_barrierattr_destroy */
-
+} /* pthread_barrierattr_destroy */
diff --git a/pthread_barrierattr_getpshared.c b/pthread_barrierattr_getpshared.c
index f14485e..e36abbb 100644
--- a/pthread_barrierattr_getpshared.c
+++ b/pthread_barrierattr_getpshared.c
@@ -40,7 +40,7 @@
int
pthread_barrierattr_getpshared (const pthread_barrierattr_t * attr,
- int *pshared)
+ int *pshared)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -81,8 +81,7 @@ pthread_barrierattr_getpshared (const pthread_barrierattr_t * attr,
{
int result;
- if ((attr != NULL && *attr != NULL) &&
- (pshared != NULL))
+ if ((attr != NULL && *attr != NULL) && (pshared != NULL))
{
*pshared = (*attr)->pshared;
result = 0;
@@ -93,5 +92,4 @@ pthread_barrierattr_getpshared (const pthread_barrierattr_t * attr,
}
return (result);
-} /* pthread_barrierattr_getpshared */
-
+} /* pthread_barrierattr_getpshared */
diff --git a/pthread_barrierattr_init.c b/pthread_barrierattr_init.c
index 8130985..584abca 100644
--- a/pthread_barrierattr_init.c
+++ b/pthread_barrierattr_init.c
@@ -82,5 +82,4 @@ pthread_barrierattr_init (pthread_barrierattr_t * attr)
*attr = ba;
return (result);
-} /* pthread_barrierattr_init */
-
+} /* pthread_barrierattr_init */
diff --git a/pthread_barrierattr_setpshared.c b/pthread_barrierattr_setpshared.c
index c76f59c..90d7ef2 100644
--- a/pthread_barrierattr_setpshared.c
+++ b/pthread_barrierattr_setpshared.c
@@ -39,8 +39,7 @@
int
-pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
- int pshared)
+pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, int pshared)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -89,24 +88,24 @@ pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
(pshared == PTHREAD_PROCESS_PRIVATE)))
{
if (pshared == PTHREAD_PROCESS_SHARED)
- {
+ {
#if !defined( _POSIX_THREAD_PROCESS_SHARED )
- result = ENOSYS;
- pshared = PTHREAD_PROCESS_PRIVATE;
+ result = ENOSYS;
+ pshared = PTHREAD_PROCESS_PRIVATE;
#else
- result = 0;
+ result = 0;
#endif /* _POSIX_THREAD_PROCESS_SHARED */
- }
+ }
else
- {
- result = 0;
- }
+ {
+ result = 0;
+ }
(*attr)->pshared = pshared;
}
@@ -117,4 +116,4 @@ pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
return (result);
-} /* pthread_barrierattr_setpshared */
+} /* pthread_barrierattr_setpshared */
diff --git a/pthread_cancel.c b/pthread_cancel.c
index 6af159f..69cec3b 100644
--- a/pthread_cancel.c
+++ b/pthread_cancel.c
@@ -37,7 +37,6 @@
#include "pthread.h"
#include "implement.h"
-
#if defined(_M_IX86) || defined(_X86_)
#define PTW32_PROGCTR(Context) ((Context).Eip)
#endif
@@ -62,14 +61,39 @@
#error Module contains CPU-specific code; modify and recompile.
#endif
-static INLINE void
-ptw32_cancel_self(void)
+static void
+ptw32_cancel_self (void)
{
- ptw32_throw(PTW32_EPS_CANCEL);
+ ptw32_throw (PTW32_EPS_CANCEL);
/* Never reached */
}
+static void CALLBACK
+ptw32_cancel_callback (DWORD unused)
+{
+ ptw32_throw (PTW32_EPS_CANCEL);
+
+ /* Never reached */
+}
+
+/*
+ * ptw32_RegisterCancelation() -
+ * Must have args of same type as QueueUserAPCEx because this function
+ * is a substitute for QueueUserAPCEx if it's not available.
+ */
+DWORD
+ptw32_RegisterCancelation (PAPCFUNC unused1, HANDLE threadH, DWORD unused2)
+{
+ CONTEXT context;
+
+ context.ContextFlags = CONTEXT_CONTROL;
+ GetThreadContext (threadH, &context);
+ PTW32_PROGCTR (context) = (DWORD_PTR) ptw32_cancel_self;
+ SetThreadContext (threadH, &context);
+ return 0;
+}
+
int
pthread_cancel (pthread_t thread)
/*
@@ -99,13 +123,13 @@ pthread_cancel (pthread_t thread)
pthread_t self;
/* This is the proper way to test thread validity. */
- result = pthread_kill(thread, 0);
+ result = pthread_kill (thread, 0);
if (0 != result)
{
return result;
}
- if ((self = pthread_self()) == NULL)
+ if ((self = pthread_self ()) == NULL)
{
return ENOMEM;
};
@@ -124,62 +148,62 @@ pthread_cancel (pthread_t thread)
* (pthread_cancel is required to be an async-cancel
* safe function).
*/
- cancel_self = pthread_equal(thread, self);
+ cancel_self = pthread_equal (thread, self);
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&thread->cancelLock);
+ (void) pthread_mutex_lock (&thread->cancelLock);
if (thread->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
&& thread->cancelState == PTHREAD_CANCEL_ENABLE
- && thread->state < PThreadStateCanceling )
+ && thread->state < PThreadStateCanceling)
{
if (cancel_self)
- {
- thread->state = PThreadStateCanceling;
- thread->cancelState = PTHREAD_CANCEL_DISABLE;
+ {
+ thread->state = PThreadStateCanceling;
+ thread->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock(&thread->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
+ (void) pthread_mutex_unlock (&thread->cancelLock);
+ ptw32_throw (PTW32_EPS_CANCEL);
- /* Never reached */
- }
+ /* Never reached */
+ }
else
- {
- HANDLE threadH = thread->threadH;
-
- SuspendThread(threadH);
-
- if (WaitForSingleObject(threadH, 0) == WAIT_TIMEOUT )
- {
- CONTEXT context;
-
- thread->state = PThreadStateCanceling;
- thread->cancelState = PTHREAD_CANCEL_DISABLE;
- context.ContextFlags = CONTEXT_CONTROL;
- GetThreadContext(threadH, &context);
- PTW32_PROGCTR(context) = (DWORD_PTR) ptw32_cancel_self;
- SetThreadContext(threadH, &context);
- (void) pthread_mutex_unlock(&thread->cancelLock);
- ResumeThread(threadH);
- }
- }
+ {
+ HANDLE threadH = thread->threadH;
+
+ SuspendThread (threadH);
+
+ if (WaitForSingleObject (threadH, 0) == WAIT_TIMEOUT)
+ {
+ thread->state = PThreadStateCanceling;
+ thread->cancelState = PTHREAD_CANCEL_DISABLE;
+ /*
+ * If alertdrv and QueueUserAPCEx is available then the following
+ * will result in a call to QueueUserAPCEx with the args given, otherwise
+ * this will result in a call to ptw32_RegisterCancelation and only
+ * the threadH arg will be used.
+ */
+ ptw32_register_cancelation (ptw32_cancel_callback, threadH, 0);
+ (void) pthread_mutex_unlock (&thread->cancelLock);
+ ResumeThread (threadH);
+ }
+ }
}
else
{
/*
* Set for deferred cancellation.
*/
- if ( thread->state >= PThreadStateCanceling
- || !SetEvent (thread->cancelEvent))
- {
- result = ESRCH;
- }
+ if (thread->state >= PThreadStateCanceling
+ || !SetEvent (thread->cancelEvent))
+ {
+ result = ESRCH;
+ }
- (void) pthread_mutex_unlock(&thread->cancelLock);
+ (void) pthread_mutex_unlock (&thread->cancelLock);
}
return (result);
}
-
diff --git a/pthread_cond_destroy.c b/pthread_cond_destroy.c
index 0030269..7a34068 100644
--- a/pthread_cond_destroy.c
+++ b/pthread_cond_destroy.c
@@ -120,15 +120,14 @@ pthread_cond_destroy (pthread_cond_t * cond)
/*
* Assuming any race condition here is harmless.
*/
- if (cond == NULL
- || *cond == NULL)
+ if (cond == NULL || *cond == NULL)
{
return EINVAL;
}
if (*cond != PTHREAD_COND_INITIALIZER)
{
- EnterCriticalSection(&ptw32_cond_list_lock);
+ EnterCriticalSection (&ptw32_cond_list_lock);
cv = *cond;
@@ -137,109 +136,109 @@ pthread_cond_destroy (pthread_cond_t * cond)
* all already signaled waiters to let them retract their
* waiter status - SEE NOTE 1 ABOVE!!!
*/
- if (sem_wait(&(cv->semBlockLock)) != 0)
- {
- return errno;
- }
+ if (sem_wait (&(cv->semBlockLock)) != 0)
+ {
+ return errno;
+ }
/*
* !TRY! lock mtxUnblockLock; try will detect busy condition
* and will not cause a deadlock with respect to concurrent
* signal/broadcast.
*/
- if ((result = pthread_mutex_trylock(&(cv->mtxUnblockLock))) != 0)
- {
- (void) sem_post(&(cv->semBlockLock));
- return result;
- }
+ if ((result = pthread_mutex_trylock (&(cv->mtxUnblockLock))) != 0)
+ {
+ (void) sem_post (&(cv->semBlockLock));
+ return result;
+ }
/*
* Check whether cv is still busy (still has waiters)
*/
if (cv->nWaitersBlocked > cv->nWaitersGone)
- {
- if (sem_post(&(cv->semBlockLock)) != 0)
- {
- result = errno;
- }
- result1 = pthread_mutex_unlock(&(cv->mtxUnblockLock));
- result2 = EBUSY;
- }
+ {
+ if (sem_post (&(cv->semBlockLock)) != 0)
+ {
+ result = errno;
+ }
+ result1 = pthread_mutex_unlock (&(cv->mtxUnblockLock));
+ result2 = EBUSY;
+ }
else
- {
- /*
- * Now it is safe to destroy
- */
- *cond = NULL;
-
- if (sem_destroy(&(cv->semBlockLock)) != 0)
- {
- result = errno;
- }
- if (sem_destroy(&(cv->semBlockQueue)) != 0)
- {
- result1 = errno;
- }
- if ((result2 = pthread_mutex_unlock(&(cv->mtxUnblockLock))) == 0)
- {
- result2 = pthread_mutex_destroy(&(cv->mtxUnblockLock));
- }
-
- /* Unlink the CV from the list */
-
- if (ptw32_cond_list_head == cv)
- {
- ptw32_cond_list_head = cv->next;
- }
- else
- {
- cv->prev->next = cv->next;
- }
-
- if (ptw32_cond_list_tail == cv)
- {
- ptw32_cond_list_tail = cv->prev;
- }
- else
- {
- cv->next->prev = cv->prev;
- }
-
- (void) free(cv);
- }
-
- LeaveCriticalSection(&ptw32_cond_list_lock);
+ {
+ /*
+ * Now it is safe to destroy
+ */
+ *cond = NULL;
+
+ if (sem_destroy (&(cv->semBlockLock)) != 0)
+ {
+ result = errno;
+ }
+ if (sem_destroy (&(cv->semBlockQueue)) != 0)
+ {
+ result1 = errno;
+ }
+ if ((result2 = pthread_mutex_unlock (&(cv->mtxUnblockLock))) == 0)
+ {
+ result2 = pthread_mutex_destroy (&(cv->mtxUnblockLock));
+ }
+
+ /* Unlink the CV from the list */
+
+ if (ptw32_cond_list_head == cv)
+ {
+ ptw32_cond_list_head = cv->next;
+ }
+ else
+ {
+ cv->prev->next = cv->next;
+ }
+
+ if (ptw32_cond_list_tail == cv)
+ {
+ ptw32_cond_list_tail = cv->prev;
+ }
+ else
+ {
+ cv->next->prev = cv->prev;
+ }
+
+ (void) free (cv);
+ }
+
+ LeaveCriticalSection (&ptw32_cond_list_lock);
}
else
{
/*
* See notes in ptw32_cond_check_need_init() above also.
*/
- EnterCriticalSection(&ptw32_cond_test_init_lock);
+ EnterCriticalSection (&ptw32_cond_test_init_lock);
/*
* Check again.
*/
if (*cond == PTHREAD_COND_INITIALIZER)
- {
- /*
- * This is all we need to do to destroy a statically
- * initialised cond that has not yet been used (initialised).
- * If we get to here, another thread waiting to initialise
- * this cond will get an EINVAL. That's OK.
- */
- *cond = NULL;
- }
+ {
+ /*
+ * This is all we need to do to destroy a statically
+ * initialised cond that has not yet been used (initialised).
+ * If we get to here, another thread waiting to initialise
+ * this cond will get an EINVAL. That's OK.
+ */
+ *cond = NULL;
+ }
else
- {
- /*
- * The cv has been initialised while we were waiting
- * so assume it's in use.
- */
- result = EBUSY;
- }
-
- LeaveCriticalSection(&ptw32_cond_test_init_lock);
+ {
+ /*
+ * The cv has been initialised while we were waiting
+ * so assume it's in use.
+ */
+ result = EBUSY;
+ }
+
+ LeaveCriticalSection (&ptw32_cond_test_init_lock);
}
return ((result != 0) ? result : ((result1 != 0) ? result1 : result2));
diff --git a/pthread_cond_init.c b/pthread_cond_init.c
index c3b5fb1..23813ef 100644
--- a/pthread_cond_init.c
+++ b/pthread_cond_init.c
@@ -87,7 +87,7 @@ pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
goto DONE;
}
- cv = (pthread_cond_t) calloc(1, sizeof (*cv));
+ cv = (pthread_cond_t) calloc (1, sizeof (*cv));
if (cv == NULL)
{
@@ -95,23 +95,23 @@ pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
goto DONE;
}
- cv->nWaitersBlocked = 0;
+ cv->nWaitersBlocked = 0;
cv->nWaitersToUnblock = 0;
- cv->nWaitersGone = 0;
+ cv->nWaitersGone = 0;
- if (sem_init(&(cv->semBlockLock), 0, 1) != 0)
+ if (sem_init (&(cv->semBlockLock), 0, 1) != 0)
{
result = errno;
goto FAIL0;
}
- if (sem_init(&(cv->semBlockQueue), 0, 0) != 0)
+ if (sem_init (&(cv->semBlockQueue), 0, 0) != 0)
{
result = errno;
goto FAIL1;
}
- if ((result = pthread_mutex_init(&(cv->mtxUnblockLock), 0)) != 0)
+ if ((result = pthread_mutex_init (&(cv->mtxUnblockLock), 0)) != 0)
{
goto FAIL2;
}
@@ -126,40 +126,40 @@ pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
* -------------
*/
FAIL2:
- (void) sem_destroy(&(cv->semBlockQueue));
+ (void) sem_destroy (&(cv->semBlockQueue));
FAIL1:
- (void) sem_destroy(&(cv->semBlockLock));
+ (void) sem_destroy (&(cv->semBlockLock));
FAIL0:
- (void) free(cv);
+ (void) free (cv);
cv = NULL;
DONE:
if (0 == result)
{
- EnterCriticalSection(&ptw32_cond_list_lock);
+ EnterCriticalSection (&ptw32_cond_list_lock);
cv->next = NULL;
cv->prev = ptw32_cond_list_tail;
if (ptw32_cond_list_tail != NULL)
- {
- ptw32_cond_list_tail->next = cv;
- }
+ {
+ ptw32_cond_list_tail->next = cv;
+ }
ptw32_cond_list_tail = cv;
if (ptw32_cond_list_head == NULL)
- {
- ptw32_cond_list_head = cv;
- }
+ {
+ ptw32_cond_list_head = cv;
+ }
- LeaveCriticalSection(&ptw32_cond_list_lock);
+ LeaveCriticalSection (&ptw32_cond_list_lock);
}
*cond = cv;
return result;
-} /* pthread_cond_init */
+} /* pthread_cond_init */
diff --git a/pthread_cond_signal.c b/pthread_cond_signal.c
index 156c0d0..84ace67 100644
--- a/pthread_cond_signal.c
+++ b/pthread_cond_signal.c
@@ -167,8 +167,7 @@
static INLINE int
-ptw32_cond_unblock (pthread_cond_t * cond,
- int unblockAll)
+ptw32_cond_unblock (pthread_cond_t * cond, int unblockAll)
/*
* Notes.
*
@@ -209,69 +208,70 @@ ptw32_cond_unblock (pthread_cond_t * cond,
return 0;
}
- if ((result = pthread_mutex_lock(&(cv->mtxUnblockLock))) != 0)
+ if ((result = pthread_mutex_lock (&(cv->mtxUnblockLock))) != 0)
{
return result;
}
- if ( 0 != cv->nWaitersToUnblock )
+ if (0 != cv->nWaitersToUnblock)
{
- if ( 0 == cv->nWaitersBlocked )
- {
- return pthread_mutex_unlock( &(cv->mtxUnblockLock) );
- }
+ if (0 == cv->nWaitersBlocked)
+ {
+ return pthread_mutex_unlock (&(cv->mtxUnblockLock));
+ }
if (unblockAll)
- {
- cv->nWaitersToUnblock += (nSignalsToIssue = cv->nWaitersBlocked);
- cv->nWaitersBlocked = 0;
- }
+ {
+ cv->nWaitersToUnblock += (nSignalsToIssue = cv->nWaitersBlocked);
+ cv->nWaitersBlocked = 0;
+ }
else
- {
- nSignalsToIssue = 1;
- cv->nWaitersToUnblock++;
- cv->nWaitersBlocked--;
- }
+ {
+ nSignalsToIssue = 1;
+ cv->nWaitersToUnblock++;
+ cv->nWaitersBlocked--;
+ }
}
- else if ( cv->nWaitersBlocked > cv->nWaitersGone )
+ else if (cv->nWaitersBlocked > cv->nWaitersGone)
{
- if (sem_wait( &(cv->semBlockLock) ) != 0)
- {
- result = errno;
- (void) pthread_mutex_unlock( &(cv->mtxUnblockLock) );
- return result;
- }
- if ( 0 != cv->nWaitersGone )
- {
- cv->nWaitersBlocked -= cv->nWaitersGone;
- cv->nWaitersGone = 0;
- }
+ /* Use the non-cancellable version of sem_wait() */
+ if (ptw32_semwait (&(cv->semBlockLock)) != 0)
+ {
+ result = errno;
+ (void) pthread_mutex_unlock (&(cv->mtxUnblockLock));
+ return result;
+ }
+ if (0 != cv->nWaitersGone)
+ {
+ cv->nWaitersBlocked -= cv->nWaitersGone;
+ cv->nWaitersGone = 0;
+ }
if (unblockAll)
- {
- nSignalsToIssue = cv->nWaitersToUnblock = cv->nWaitersBlocked;
- cv->nWaitersBlocked = 0;
- }
+ {
+ nSignalsToIssue = cv->nWaitersToUnblock = cv->nWaitersBlocked;
+ cv->nWaitersBlocked = 0;
+ }
else
- {
- nSignalsToIssue = cv->nWaitersToUnblock = 1;
- cv->nWaitersBlocked--;
- }
+ {
+ nSignalsToIssue = cv->nWaitersToUnblock = 1;
+ cv->nWaitersBlocked--;
+ }
}
else
{
- return pthread_mutex_unlock( &(cv->mtxUnblockLock) );
+ return pthread_mutex_unlock (&(cv->mtxUnblockLock));
}
- if ((result = pthread_mutex_unlock( &(cv->mtxUnblockLock) )) == 0)
+ if ((result = pthread_mutex_unlock (&(cv->mtxUnblockLock))) == 0)
{
- if (sem_post_multiple( &(cv->semBlockQueue), nSignalsToIssue ) != 0)
- {
- result = errno;
- }
+ if (sem_post_multiple (&(cv->semBlockQueue), nSignalsToIssue) != 0)
+ {
+ result = errno;
+ }
}
return result;
-} /* ptw32_cond_unblock */
+} /* ptw32_cond_unblock */
int
pthread_cond_signal (pthread_cond_t * cond)
@@ -311,9 +311,9 @@ pthread_cond_signal (pthread_cond_t * cond)
/*
* The '0'(FALSE) unblockAll arg means unblock ONE waiter.
*/
- return (ptw32_cond_unblock(cond, 0));
+ return (ptw32_cond_unblock (cond, 0));
-} /* pthread_cond_signal */
+} /* pthread_cond_signal */
int
pthread_cond_broadcast (pthread_cond_t * cond)
@@ -350,6 +350,6 @@ pthread_cond_broadcast (pthread_cond_t * cond)
/*
* The TRUE unblockAll arg means unblock ALL waiters.
*/
- return (ptw32_cond_unblock(cond, PTW32_TRUE));
+ return (ptw32_cond_unblock (cond, PTW32_TRUE));
-} /* pthread_cond_broadcast */
+} /* pthread_cond_broadcast */
diff --git a/pthread_cond_wait.c b/pthread_cond_wait.c
index 57fc978..6db2a48 100644
--- a/pthread_cond_wait.c
+++ b/pthread_cond_wait.c
@@ -301,7 +301,8 @@ ptw32_cond_wait_cleanup (void *args)
}
else if (INT_MAX / 2 == ++(cv->nWaitersGone))
{
- if (sem_wait (&(cv->semBlockLock)) != 0)
+ /* Use the non-cancellable version of sem_wait() */
+ if (ptw32_semwait (&(cv->semBlockLock)) != 0)
{
*resultPtr = errno;
/*
@@ -382,6 +383,7 @@ ptw32_cond_timedwait (pthread_cond_t * cond,
cv = *cond;
+ /* Thread can be cancelled in sem_wait() but this is OK */
if (sem_wait (&(cv->semBlockLock)) != 0)
{
return errno;
diff --git a/pthread_condattr_destroy.c b/pthread_condattr_destroy.c
index 24cb4d8..fa42c1d 100644
--- a/pthread_condattr_destroy.c
+++ b/pthread_condattr_destroy.c
@@ -83,4 +83,4 @@ pthread_condattr_destroy (pthread_condattr_t * attr)
return result;
-} /* pthread_condattr_destroy */
+} /* pthread_condattr_destroy */
diff --git a/pthread_condattr_getpshared.c b/pthread_condattr_getpshared.c
index 756dfac..c995cd3 100644
--- a/pthread_condattr_getpshared.c
+++ b/pthread_condattr_getpshared.c
@@ -94,4 +94,4 @@ pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared)
return result;
-} /* pthread_condattr_getpshared */
+} /* pthread_condattr_getpshared */
diff --git a/pthread_condattr_init.c b/pthread_condattr_init.c
index ae3bf85..eb651fd 100644
--- a/pthread_condattr_init.c
+++ b/pthread_condattr_init.c
@@ -84,4 +84,4 @@ pthread_condattr_init (pthread_condattr_t * attr)
return result;
-} /* pthread_condattr_init */
+} /* pthread_condattr_init */
diff --git a/pthread_condattr_setpshared.c b/pthread_condattr_setpshared.c
index 1f03a03..23db834 100644
--- a/pthread_condattr_setpshared.c
+++ b/pthread_condattr_setpshared.c
@@ -86,24 +86,24 @@ pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared)
if ((attr != NULL && *attr != NULL)
&& ((pshared == PTHREAD_PROCESS_SHARED)
- || (pshared == PTHREAD_PROCESS_PRIVATE)))
+ || (pshared == PTHREAD_PROCESS_PRIVATE)))
{
if (pshared == PTHREAD_PROCESS_SHARED)
- {
+ {
#if !defined( _POSIX_THREAD_PROCESS_SHARED )
- result = ENOSYS;
- pshared = PTHREAD_PROCESS_PRIVATE;
+ result = ENOSYS;
+ pshared = PTHREAD_PROCESS_PRIVATE;
#else
- result = 0;
+ result = 0;
#endif /* _POSIX_THREAD_PROCESS_SHARED */
- }
+ }
else
- {
- result = 0;
- }
+ {
+ result = 0;
+ }
(*attr)->pshared = pshared;
}
@@ -114,4 +114,4 @@ pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared)
return result;
-} /* pthread_condattr_setpshared */
+} /* pthread_condattr_setpshared */
diff --git a/pthread_delay_np.c b/pthread_delay_np.c
index 76a5773..ee9b2d9 100644
--- a/pthread_delay_np.c
+++ b/pthread_delay_np.c
@@ -79,7 +79,7 @@
* intRC = pthread_delay_np(&tsWait);
*/
int
-pthread_delay_np (struct timespec * interval)
+pthread_delay_np (struct timespec *interval)
{
DWORD wait_time;
DWORD secs_in_millisecs;
@@ -94,9 +94,9 @@ pthread_delay_np (struct timespec * interval)
if (interval->tv_sec == 0L && interval->tv_nsec == 0L)
{
- pthread_testcancel();
- Sleep(0);
- pthread_testcancel();
+ pthread_testcancel ();
+ Sleep (0);
+ pthread_testcancel ();
return (0);
}
@@ -106,12 +106,25 @@ pthread_delay_np (struct timespec * interval)
/* convert nanosecs to millisecs (rounding up) */
millisecs = (interval->tv_nsec + 999999L) / 1000000L;
+#if defined(__WATCOMC__)
+#pragma disable_message (124)
+#endif
+
+ /*
+ * Most compilers will issue a warning 'comparison always 0'
+ * because the variable type is unsigned, but we need to keep this
+ * for some reason I can't recall now.
+ */
if (0 > (wait_time = secs_in_millisecs + millisecs))
{
return EINVAL;
}
- if (NULL == (self = pthread_self()))
+#if defined(__WATCOMC__)
+#pragma enable_message (124)
+#endif
+
+ if (NULL == (self = pthread_self ()))
{
return ENOMEM;
}
@@ -123,32 +136,32 @@ pthread_delay_np (struct timespec * interval)
* Deferred cancelation will cancel us immediately.
*/
if (WAIT_OBJECT_0 ==
- (status = WaitForSingleObject(self->cancelEvent, wait_time)) )
- {
- /*
- * Canceling!
- */
- (void) pthread_mutex_lock(&self->cancelLock);
- if (self->state < PThreadStateCanceling)
- {
- self->state = PThreadStateCanceling;
- self->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock(&self->cancelLock);
+ (status = WaitForSingleObject (self->cancelEvent, wait_time)))
+ {
+ /*
+ * Canceling!
+ */
+ (void) pthread_mutex_lock (&self->cancelLock);
+ if (self->state < PThreadStateCanceling)
+ {
+ self->state = PThreadStateCanceling;
+ self->cancelState = PTHREAD_CANCEL_DISABLE;
+ (void) pthread_mutex_unlock (&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
- }
+ ptw32_throw (PTW32_EPS_CANCEL);
+ }
- (void) pthread_mutex_unlock(&self->cancelLock);
- return ESRCH;
- }
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ return ESRCH;
+ }
else if (status != WAIT_TIMEOUT)
- {
- return EINVAL;
- }
+ {
+ return EINVAL;
+ }
}
else
{
- Sleep( wait_time );
+ Sleep (wait_time);
}
return (0);
diff --git a/pthread_detach.c b/pthread_detach.c
index 1c8965f..a376cf2 100644
--- a/pthread_detach.c
+++ b/pthread_detach.c
@@ -77,7 +77,7 @@ pthread_detach (pthread_t thread)
int result;
/* This is the proper way to test for a valid thread. */
- result = pthread_kill(thread, 0);
+ result = pthread_kill (thread, 0);
if (0 != result)
{
return result;
diff --git a/pthread_equal.c b/pthread_equal.c
index ce9372e..f7965e4 100644
--- a/pthread_equal.c
+++ b/pthread_equal.c
@@ -49,7 +49,7 @@ pthread_equal (pthread_t t1, pthread_t t2)
* PARAMETERS
* t1,
* t2
- * thread IDs
+ * thread IDs
*
*
* DESCRIPTION
@@ -57,8 +57,8 @@ pthread_equal (pthread_t t1, pthread_t t2)
* returns zero.
*
* RESULTS
- * non-zero if t1 and t2 refer to the same thread,
- * 0 t1 and t2 do not refer to the same thread
+ * non-zero if t1 and t2 refer to the same thread,
+ * 0 t1 and t2 do not refer to the same thread
*
* ------------------------------------------------------
*/
diff --git a/pthread_exit.c b/pthread_exit.c
index da19063..302135b 100644
--- a/pthread_exit.c
+++ b/pthread_exit.c
@@ -38,7 +38,7 @@
#include "pthread.h"
#include "implement.h"
#ifndef _UWIN
-# include <process.h>
+//# include <process.h>
#endif
void
@@ -74,8 +74,8 @@ pthread_exit (void *value_ptr)
self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
#ifdef _UWIN
- if(--pthread_count <= 0)
- exit((int)value_ptr);
+ if (--pthread_count <= 0)
+ exit ((int) value_ptr);
#endif
if (NULL == self)
@@ -99,7 +99,7 @@ pthread_exit (void *value_ptr)
self->exitStatus = value_ptr;
- ptw32_throw(PTW32_EPS_EXIT);
+ ptw32_throw (PTW32_EPS_EXIT);
/* Never reached. */
diff --git a/pthread_getconcurrency.c b/pthread_getconcurrency.c
index b5b7b08..1eefe4b 100644
--- a/pthread_getconcurrency.c
+++ b/pthread_getconcurrency.c
@@ -39,7 +39,7 @@
int
-pthread_getconcurrency(void)
+pthread_getconcurrency (void)
{
return ptw32_concurrency;
-}
+}
diff --git a/pthread_getschedparam.c b/pthread_getschedparam.c
index ac02775..d968aa5 100644
--- a/pthread_getschedparam.c
+++ b/pthread_getschedparam.c
@@ -39,13 +39,13 @@
#include "sched.h"
int
-pthread_getschedparam(pthread_t thread, int *policy,
- struct sched_param *param)
+pthread_getschedparam (pthread_t thread, int *policy,
+ struct sched_param *param)
{
int result;
/* Validate the thread id. */
- result = pthread_kill(thread, 0);
+ result = pthread_kill (thread, 0);
if (0 != result)
{
return result;
diff --git a/pthread_getspecific.c b/pthread_getspecific.c
index c0fc95e..e48fa47 100644
--- a/pthread_getspecific.c
+++ b/pthread_getspecific.c
@@ -63,13 +63,13 @@ pthread_getspecific (pthread_key_t key)
* ------------------------------------------------------
*/
{
- int lasterror = GetLastError();
- int lastWSAerror = WSAGetLastError();
+ int lasterror = GetLastError ();
+ int lastWSAerror = WSAGetLastError ();
void *ptr = TlsGetValue (key->key);
- SetLastError( lasterror );
- WSASetLastError( lastWSAerror );
+ SetLastError (lasterror);
+ WSASetLastError (lastWSAerror);
return ptr;
}
diff --git a/pthread_getw32threadhandle_np.c b/pthread_getw32threadhandle_np.c
index b7f039a..fcf1288 100644
--- a/pthread_getw32threadhandle_np.c
+++ b/pthread_getw32threadhandle_np.c
@@ -47,7 +47,7 @@
* win32 specific attributes of the thread.
*/
HANDLE
-pthread_getw32threadhandle_np(pthread_t thread)
+pthread_getw32threadhandle_np (pthread_t thread)
{
return (thread != NULL) ? (thread->threadH) : 0;
}
diff --git a/pthread_join.c b/pthread_join.c
index 93be247..fa9c168 100644
--- a/pthread_join.c
+++ b/pthread_join.c
@@ -84,7 +84,7 @@ pthread_join (pthread_t thread, void **value_ptr)
pthread_t self;
/* This is the proper way to test for a valid thread ID */
- result = pthread_kill(thread, 0);
+ result = pthread_kill (thread, 0);
if (0 != result)
{
return result;
@@ -93,7 +93,7 @@ pthread_join (pthread_t thread, void **value_ptr)
self = pthread_self ();
if (NULL == self)
{
- return ENOENT;
+ return ENOENT;
}
if (0 != pthread_equal (self, thread))
@@ -113,7 +113,7 @@ pthread_join (pthread_t thread, void **value_ptr)
* pthreadCancelableWait will not return if we
* are canceled.
*/
- result = pthreadCancelableWait(thread->threadH);
+ result = pthreadCancelableWait (thread->threadH);
if (result == 0)
{
@@ -144,7 +144,7 @@ pthread_join (pthread_t thread, void **value_ptr)
{
*value_ptr = thread->exitStatus;
}
-
+
/*
* The result of making multiple simultaneous calls to
* pthread_join() specifying the same target is undefined.
diff --git a/pthread_key_create.c b/pthread_key_create.c
index 92a3409..bfb865b 100644
--- a/pthread_key_create.c
+++ b/pthread_key_create.c
@@ -82,7 +82,7 @@ pthread_key_create (pthread_key_t * key, void (*destructor) (void *))
{
result = ENOMEM;
}
- else if ((newkey->key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+ else if ((newkey->key = TlsAlloc ()) == TLS_OUT_OF_INDEXES)
{
result = EAGAIN;
diff --git a/pthread_key_delete.c b/pthread_key_delete.c
index 4f5064e..2bb2209 100644
--- a/pthread_key_delete.c
+++ b/pthread_key_delete.c
@@ -71,51 +71,51 @@ pthread_key_delete (pthread_key_t key)
if (key != NULL)
{
if (key->threads != NULL &&
- key->destructor != NULL &&
- pthread_mutex_lock (&(key->threadsLock)) == 0)
- {
- /*
- * Run through all Thread<-->Key associations
- * for this key.
- * If the pthread_t still exists (ie the assoc->thread
- * is not NULL) then leave the assoc for the thread to
- * destroy.
- * Notes:
- * If assoc->thread is NULL, then the associated thread
- * is no longer referencing this assoc.
- * The association is only referenced
- * by this key and must be released; otherwise
- * the assoc will be destroyed when the thread is destroyed.
- */
- ThreadKeyAssoc *assoc;
+ key->destructor != NULL &&
+ pthread_mutex_lock (&(key->threadsLock)) == 0)
+ {
+ /*
+ * Run through all Thread<-->Key associations
+ * for this key.
+ * If the pthread_t still exists (ie the assoc->thread
+ * is not NULL) then leave the assoc for the thread to
+ * destroy.
+ * Notes:
+ * If assoc->thread is NULL, then the associated thread
+ * is no longer referencing this assoc.
+ * The association is only referenced
+ * by this key and must be released; otherwise
+ * the assoc will be destroyed when the thread is destroyed.
+ */
+ ThreadKeyAssoc *assoc;
- assoc = (ThreadKeyAssoc *) key->threads;
+ assoc = (ThreadKeyAssoc *) key->threads;
- while (assoc != NULL)
- {
- if (pthread_mutex_lock (&(assoc->lock)) == 0)
- {
- ThreadKeyAssoc *next;
+ while (assoc != NULL)
+ {
+ if (pthread_mutex_lock (&(assoc->lock)) == 0)
+ {
+ ThreadKeyAssoc *next;
- assoc->key = NULL;
- next = assoc->nextThread;
- assoc->nextThread = NULL;
+ assoc->key = NULL;
+ next = assoc->nextThread;
+ assoc->nextThread = NULL;
- pthread_mutex_unlock (&(assoc->lock));
+ pthread_mutex_unlock (&(assoc->lock));
- ptw32_tkAssocDestroy (assoc);
+ ptw32_tkAssocDestroy (assoc);
- assoc = next;
- }
- }
- pthread_mutex_unlock (&(key->threadsLock));
- }
+ assoc = next;
+ }
+ }
+ pthread_mutex_unlock (&(key->threadsLock));
+ }
TlsFree (key->key);
if (key->destructor != NULL)
- {
- pthread_mutex_destroy (&(key->threadsLock));
- }
+ {
+ pthread_mutex_destroy (&(key->threadsLock));
+ }
#if defined( _DEBUG )
memset ((char *) key, 0, sizeof (*key));
diff --git a/pthread_kill.c b/pthread_kill.c
index f96975b..c40235c 100644
--- a/pthread_kill.c
+++ b/pthread_kill.c
@@ -65,26 +65,26 @@ pthread_kill (pthread_t thread, int sig)
* function can be used to check for a valid thread ID.
*
* RESULTS
- * ESRCH the thread is not a valid thread ID,
+ * ESRCH the thread is not a valid thread ID,
* EINVAL the value of the signal is invalid
* or unsupported.
- * 0 the signal was successfully sent.
+ * 0 the signal was successfully sent.
*
* ------------------------------------------------------
*/
{
int result = 0;
- EnterCriticalSection(&ptw32_thread_reuse_lock);
+ EnterCriticalSection (&ptw32_thread_reuse_lock);
if (NULL == thread
- || NULL == thread->threadH
- || THREAD_PRIORITY_ERROR_RETURN == GetThreadPriority(thread->threadH))
+ || NULL == thread->threadH
+ || THREAD_PRIORITY_ERROR_RETURN == GetThreadPriority (thread->threadH))
{
result = ESRCH;
}
- LeaveCriticalSection(&ptw32_thread_reuse_lock);
+ LeaveCriticalSection (&ptw32_thread_reuse_lock);
if (0 == result && 0 != sig)
{
diff --git a/pthread_mutex_destroy.c b/pthread_mutex_destroy.c
index 68a24c5..d23af53 100644
--- a/pthread_mutex_destroy.c
+++ b/pthread_mutex_destroy.c
@@ -39,13 +39,12 @@
int
-pthread_mutex_destroy(pthread_mutex_t *mutex)
+pthread_mutex_destroy (pthread_mutex_t * mutex)
{
int result = 0;
pthread_mutex_t mx;
- if (mutex == NULL
- || *mutex == NULL)
+ if (mutex == NULL || *mutex == NULL)
{
return EINVAL;
}
@@ -57,7 +56,7 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
{
mx = *mutex;
- result = pthread_mutex_trylock(&mx);
+ result = pthread_mutex_trylock (&mx);
/*
* If trylock succeeded and the mutex is not recursively locked it
@@ -80,13 +79,13 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
*/
*mutex = NULL;
- result = pthread_mutex_unlock(&mx);
+ result = pthread_mutex_unlock (&mx);
if (result == 0)
{
- (void) sem_destroy( &mx->wait_sema );
- DeleteCriticalSection( &mx->wait_cs );
- free(mx);
+ (void) sem_destroy (&mx->wait_sema);
+ DeleteCriticalSection (&mx->wait_cs);
+ free (mx);
}
else
{
@@ -96,12 +95,12 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
*mutex = mx;
}
}
- else /* mx->recursive_count > 1 */
+ else /* mx->recursive_count > 1 */
{
/*
* The mutex must be recursive and already locked by us (this thread).
*/
- mx->recursive_count--; /* Undo effect of pthread_mutex_trylock() above */
+ mx->recursive_count--; /* Undo effect of pthread_mutex_trylock() above */
result = EBUSY;
}
}
@@ -111,7 +110,7 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
/*
* See notes in ptw32_mutex_check_need_init() above also.
*/
- EnterCriticalSection(&ptw32_mutex_test_init_lock);
+ EnterCriticalSection (&ptw32_mutex_test_init_lock);
/*
* Check again.
@@ -135,8 +134,8 @@ pthread_mutex_destroy(pthread_mutex_t *mutex)
result = EBUSY;
}
- LeaveCriticalSection(&ptw32_mutex_test_init_lock);
+ LeaveCriticalSection (&ptw32_mutex_test_init_lock);
}
- return(result);
+ return (result);
}
diff --git a/pthread_mutex_init.c b/pthread_mutex_init.c
index eb8f206..ebf26d5 100644
--- a/pthread_mutex_init.c
+++ b/pthread_mutex_init.c
@@ -39,7 +39,7 @@
int
-pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
+pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr)
{
int result = 0;
pthread_mutex_t mx;
@@ -50,9 +50,7 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
}
if (attr != NULL
- && *attr != NULL
- && (*attr)->pshared == PTHREAD_PROCESS_SHARED
- )
+ && *attr != NULL && (*attr)->pshared == PTHREAD_PROCESS_SHARED)
{
/*
* Creating mutex that can be shared between
@@ -74,7 +72,7 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
}
- mx = (pthread_mutex_t) calloc(1, sizeof(*mx));
+ mx = (pthread_mutex_t) calloc (1, sizeof (*mx));
if (mx == NULL)
{
@@ -85,23 +83,22 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
mx->lock_idx = PTW32_MUTEX_LOCK_IDX_INIT;
mx->recursive_count = 0;
mx->kind = (attr == NULL || *attr == NULL
- ? PTHREAD_MUTEX_DEFAULT
- : (*attr)->kind);
+ ? PTHREAD_MUTEX_DEFAULT : (*attr)->kind);
mx->ownerThread = NULL;
- if ( 0 != sem_init( &mx->wait_sema, 0, 0 ))
+ if (0 != sem_init (&mx->wait_sema, 0, 0))
{
result = EAGAIN;
- free(mx);
+ free (mx);
mx = NULL;
}
else
{
- InitializeCriticalSection( &mx->wait_cs );
+ InitializeCriticalSection (&mx->wait_cs);
}
}
*mutex = mx;
- return(result);
+ return (result);
}
diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c
index ceeeb30..a59666a 100644
--- a/pthread_mutex_lock.c
+++ b/pthread_mutex_lock.c
@@ -35,88 +35,13 @@
*/
#ifndef _UWIN
-# include <process.h>
+//# include <process.h>
#endif
#include "pthread.h"
#include "implement.h"
-
-static INLINE int
-ptw32_semwait (sem_t * sem)
- /*
- * ------------------------------------------------------
- * DESCRIPTION
- * This function waits on a POSIX semaphore. If the
- * semaphore value is greater than zero, it decreases
- * its value by one. If the semaphore value is zero, then
- * the calling thread (or process) is blocked until it can
- * successfully decrease the value.
- *
- * Unlike sem_wait(), this routine is non-cancelable.
- *
- * RESULTS
- * 0 successfully decreased semaphore,
- * -1 failed, error in errno.
- * ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS semaphores are not supported,
- * EINTR the function was interrupted by a signal,
- * EDEADLK a deadlock condition was detected.
- *
- * ------------------------------------------------------
- */
-{
- int result = 0;
-
- DWORD status;
-
- if (sem == NULL)
- {
- result = EINVAL;
- }
- else
- {
-
-#ifdef NEED_SEM
-
- status = WaitForSingleObject( (*sem)->event, INFINITE );
-
-#else /* NEED_SEM */
-
- status = WaitForSingleObject( (*sem)->sem, INFINITE );
-
-#endif
-
- if (status == WAIT_OBJECT_0)
- {
-
-#ifdef NEED_SEM
-
- ptw32_decrease_semaphore(sem);
-
-#endif /* NEED_SEM */
-
- return 0;
- }
- else
- {
- result = EINVAL;
- }
- }
-
- if (result != 0)
- {
- errno = result;
- return -1;
- }
-
- return 0;
-
-} /* ptw32_semwait */
-
-
int
-pthread_mutex_lock(pthread_mutex_t *mutex)
+pthread_mutex_lock (pthread_mutex_t * mutex)
{
int result = 0;
pthread_mutex_t mx;
@@ -135,29 +60,29 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
*/
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
{
- if ((result = ptw32_mutex_check_need_init(mutex)) != 0)
+ if ((result = ptw32_mutex_check_need_init (mutex)) != 0)
{
- return(result);
+ return (result);
}
}
mx = *mutex;
- if ( 0 == InterlockedIncrement( &mx->lock_idx ) )
+ if (0 == InterlockedIncrement (&mx->lock_idx))
{
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
+ ? pthread_self ()
: (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
}
else
{
- if ( mx->kind != PTHREAD_MUTEX_FAST_NP &&
- pthread_equal( mx->ownerThread, pthread_self() ) )
+ if (mx->kind != PTHREAD_MUTEX_FAST_NP &&
+ pthread_equal (mx->ownerThread, pthread_self ()))
{
- (void) InterlockedDecrement( &mx->lock_idx );
-
- if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP )
+ (void) InterlockedDecrement (&mx->lock_idx);
+
+ if (mx->kind == PTHREAD_MUTEX_RECURSIVE_NP)
{
mx->recursive_count++;
}
@@ -168,11 +93,11 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
}
else
{
- if (ptw32_semwait( &mx->wait_sema ) == 0)
+ if (ptw32_semwait (&mx->wait_sema) == 0)
{
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
+ ? pthread_self ()
: (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
}
else
@@ -182,5 +107,5 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
}
}
- return(result);
+ return (result);
}
diff --git a/pthread_mutex_timedlock.c b/pthread_mutex_timedlock.c
index 9cf97d5..1abc391 100644
--- a/pthread_mutex_timedlock.c
+++ b/pthread_mutex_timedlock.c
@@ -35,7 +35,7 @@
*/
#ifndef _UWIN
-# include <process.h>
+//# include <process.h>
#endif
#ifndef NEED_FTIME
#include <sys/timeb.h>
@@ -45,7 +45,7 @@
static INLINE int
-ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
+ptw32_timed_semwait (sem_t * sem, const struct timespec *abstime)
/*
* ------------------------------------------------------
* DESCRIPTION
@@ -66,15 +66,15 @@ ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
* Unlike sem_timedwait(), this routine is non-cancelable.
*
* RESULTS
- * 2 abstime has passed already
- * 1 abstime timed out while waiting
- * 0 successfully decreased semaphore,
- * -1 failed, error in errno.
+ * 2 abstime has passed already
+ * 1 abstime timed out while waiting
+ * 0 successfully decreased semaphore,
+ * -1 failed, error in errno.
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS semaphores are not supported,
- * EINTR the function was interrupted by a signal,
- * EDEADLK a deadlock condition was detected.
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOSYS semaphores are not supported,
+ * EINTR the function was interrupted by a signal,
+ * EDEADLK a deadlock condition was detected.
*
* ------------------------------------------------------
*/
@@ -111,41 +111,46 @@ ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
/*
* Calculate timeout as milliseconds from current system time.
*/
-
+
/* get current system time */
-
+
#ifdef NEED_FTIME
-
+
{
FILETIME ft;
SYSTEMTIME st;
-
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
+
+ GetSystemTime (&st);
+ SystemTimeToFileTime (&st, &ft);
/*
* GetSystemTimeAsFileTime(&ft); would be faster,
* but it does not exist on WinCE
*/
-
- ptw32_filetime_to_timespec(&ft, &currSysTime);
+
+ ptw32_filetime_to_timespec (&ft, &currSysTime);
}
-
+
/*
* subtract current system time from abstime
*/
- milliseconds = (abstime->tv_sec - currSysTime.tv_sec) * MILLISEC_PER_SEC;
- milliseconds += ((abstime->tv_nsec - currSysTime.tv_nsec)
- + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
+ milliseconds =
+ (abstime->tv_sec - currSysTime.tv_sec) * MILLISEC_PER_SEC;
+ milliseconds +=
+ ((abstime->tv_nsec - currSysTime.tv_nsec) +
+ (NANOSEC_PER_MILLISEC / 2)) / NANOSEC_PER_MILLISEC;
#else /* NEED_FTIME */
- _ftime(&currSysTime);
+ _ftime (&currSysTime);
/*
* subtract current system time from abstime
*/
- milliseconds = (abstime->tv_sec - currSysTime.time) * MILLISEC_PER_SEC;
- milliseconds += ((abstime->tv_nsec + (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC)
- - currSysTime.millitm;
+ milliseconds =
+ (abstime->tv_sec - currSysTime.time) * MILLISEC_PER_SEC;
+ milliseconds +=
+ ((abstime->tv_nsec +
+ (NANOSEC_PER_MILLISEC / 2)) / NANOSEC_PER_MILLISEC) -
+ currSysTime.millitm;
#endif /* NEED_FTIME */
@@ -157,11 +162,11 @@ ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
#ifdef NEED_SEM
- status = WaitForSingleObject( (*sem)->event, milliseconds );
+ status = WaitForSingleObject ((*sem)->event, milliseconds);
#else /* NEED_SEM */
-
- status = WaitForSingleObject( (*sem)->sem, milliseconds );
+
+ status = WaitForSingleObject ((*sem)->sem, milliseconds);
#endif
@@ -170,7 +175,7 @@ ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
#ifdef NEED_SEM
- ptw32_decrease_semaphore(sem);
+ ptw32_decrease_semaphore (sem);
#endif /* NEED_SEM */
@@ -198,7 +203,8 @@ ptw32_timed_semwait (sem_t * sem, const struct timespec * abstime)
int
-pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
+pthread_mutex_timedlock (pthread_mutex_t * mutex,
+ const struct timespec *abstime)
{
int result = 0;
pthread_mutex_t mx;
@@ -221,29 +227,29 @@ pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
*/
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
{
- if ((result = ptw32_mutex_check_need_init(mutex)) != 0)
+ if ((result = ptw32_mutex_check_need_init (mutex)) != 0)
{
- return(result);
+ return (result);
}
}
mx = *mutex;
- if( 0 == InterlockedIncrement( &mx->lock_idx ) )
+ if (0 == InterlockedIncrement (&mx->lock_idx))
{
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
+ ? pthread_self ()
: (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
}
else
{
- if( mx->kind != PTHREAD_MUTEX_FAST_NP &&
- pthread_equal( mx->ownerThread, pthread_self() ) )
+ if (mx->kind != PTHREAD_MUTEX_FAST_NP &&
+ pthread_equal (mx->ownerThread, pthread_self ()))
{
- (void) InterlockedDecrement( &mx->lock_idx );
+ (void) InterlockedDecrement (&mx->lock_idx);
- if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP )
+ if (mx->kind == PTHREAD_MUTEX_RECURSIVE_NP)
{
mx->recursive_count++;
}
@@ -260,22 +266,23 @@ pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
}
else
{
- switch (ptw32_timed_semwait( &mx->wait_sema, abstime ))
+ switch (ptw32_timed_semwait (&mx->wait_sema, abstime))
{
- case 0: /* We got the mutex. */
+ case 0: /* We got the mutex. */
{
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
- : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
+ ? pthread_self ()
+ : (pthread_t)
+ PTW32_MUTEX_OWNER_ANONYMOUS);
break;
}
- case 1: /* Timedout, try a second grab. */
+ case 1: /* Timedout, try a second grab. */
{
int busy;
- EnterCriticalSection(&mx->wait_cs);
-
+ EnterCriticalSection (&mx->wait_cs);
+
/*
* If we timeout, it is up to us to adjust lock_idx to say
* we're no longer waiting. If the mutex was also unlocked
@@ -302,28 +309,29 @@ pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
* We can almost guarrantee that EAGAIN is the only
* possible error, so no need to test errno.
*/
-
- if ( -1 == (busy = sem_trywait( &mx->wait_sema )) )
+
+ if (-1 == (busy = sem_trywait (&mx->wait_sema)))
{
- (void) InterlockedDecrement( &mx->lock_idx );
+ (void) InterlockedDecrement (&mx->lock_idx);
result = ETIMEDOUT;
}
-
- LeaveCriticalSection(&mx->wait_cs);
- if ( ! busy )
+ LeaveCriticalSection (&mx->wait_cs);
+
+ if (!busy)
{
/*
* We have acquired the lock on second grab - keep it.
*/
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
- : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
+ ? pthread_self ()
+ : (pthread_t)
+ PTW32_MUTEX_OWNER_ANONYMOUS);
}
break;
}
- case 2: /* abstime passed before we started to wait. */
+ case 2: /* abstime passed before we started to wait. */
{
/*
* If we timeout, it is up to us to adjust lock_idx to say
@@ -335,27 +343,27 @@ pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
* we don't how long ago abstime was. We MUST just release it
* immediately.
*/
- EnterCriticalSection(&mx->wait_cs);
-
+ EnterCriticalSection (&mx->wait_cs);
+
result = ETIMEDOUT;
- if ( -1 == sem_trywait( &mx->wait_sema ) )
+ if (-1 == sem_trywait (&mx->wait_sema))
{
- (void) InterlockedDecrement( &mx->lock_idx );
+ (void) InterlockedDecrement (&mx->lock_idx);
}
else
{
- if ( InterlockedDecrement( &mx->lock_idx ) >= 0 )
+ if (InterlockedDecrement (&mx->lock_idx) >= 0)
{
/* Someone else is waiting on that mutex */
- if ( sem_post( &mx->wait_sema ) != 0 )
+ if (sem_post (&mx->wait_sema) != 0)
{
result = errno;
}
}
}
-
- LeaveCriticalSection(&mx->wait_cs);
+
+ LeaveCriticalSection (&mx->wait_cs);
break;
}
default:
@@ -368,5 +376,5 @@ pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
}
}
- return(result);
+ return (result);
}
diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c
index 86ffae9..463e031 100644
--- a/pthread_mutex_trylock.c
+++ b/pthread_mutex_trylock.c
@@ -39,7 +39,7 @@
int
-pthread_mutex_trylock(pthread_mutex_t *mutex)
+pthread_mutex_trylock (pthread_mutex_t * mutex)
{
int result = 0;
pthread_mutex_t mx;
@@ -57,36 +57,38 @@ pthread_mutex_trylock(pthread_mutex_t *mutex)
*/
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
{
- result = ptw32_mutex_check_need_init(mutex);
+ result = ptw32_mutex_check_need_init (mutex);
}
mx = *mutex;
if (result == 0)
{
- if ( (PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT ==
- ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &mx->lock_idx,
+ if ((PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT ==
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) &
+ mx->lock_idx,
(PTW32_INTERLOCKED_LONG) 0,
- (PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT))
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_MUTEX_LOCK_IDX_INIT))
{
mx->recursive_count = 1;
mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self()
+ ? pthread_self ()
: (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
}
else
{
- if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP &&
- pthread_equal( mx->ownerThread, pthread_self() ) )
- {
- mx->recursive_count++;
- }
- else
- {
- result = EBUSY;
- }
+ if (mx->kind == PTHREAD_MUTEX_RECURSIVE_NP &&
+ pthread_equal (mx->ownerThread, pthread_self ()))
+ {
+ mx->recursive_count++;
+ }
+ else
+ {
+ result = EBUSY;
+ }
}
}
- return(result);
+ return (result);
}
diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c
index c25f3a5..aff3637 100644
--- a/pthread_mutex_unlock.c
+++ b/pthread_mutex_unlock.c
@@ -39,7 +39,7 @@
int
-pthread_mutex_unlock(pthread_mutex_t *mutex)
+pthread_mutex_unlock (pthread_mutex_t * mutex)
{
int result = 0;
pthread_mutex_t mx;
@@ -59,24 +59,24 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
if (mx != PTHREAD_MUTEX_INITIALIZER)
{
if (mx->ownerThread == (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS
- || pthread_equal(mx->ownerThread, pthread_self()))
+ || pthread_equal (mx->ownerThread, pthread_self ()))
{
- if( mx->kind != PTHREAD_MUTEX_RECURSIVE_NP
- || 0 == --mx->recursive_count )
+ if (mx->kind != PTHREAD_MUTEX_RECURSIVE_NP
+ || 0 == --mx->recursive_count)
{
mx->ownerThread = NULL;
- EnterCriticalSection( &mx->wait_cs );
+ EnterCriticalSection (&mx->wait_cs);
- if( InterlockedDecrement( &mx->lock_idx ) >= 0 )
+ if (InterlockedDecrement (&mx->lock_idx) >= 0)
{
/* Someone is waiting on that mutex */
- if (sem_post( &mx->wait_sema ) != 0)
+ if (sem_post (&mx->wait_sema) != 0)
{
result = errno;
}
}
- LeaveCriticalSection( &mx->wait_cs );
+ LeaveCriticalSection (&mx->wait_cs);
}
}
else
@@ -89,5 +89,5 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
result = EINVAL;
}
- return(result);
+ return (result);
}
diff --git a/pthread_mutexattr_destroy.c b/pthread_mutexattr_destroy.c
index fb8ea0f..647efe0 100644
--- a/pthread_mutexattr_destroy.c
+++ b/pthread_mutexattr_destroy.c
@@ -48,7 +48,7 @@ pthread_mutexattr_destroy (pthread_mutexattr_t * attr)
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_mutexattr_t
+ * pointer to an instance of pthread_mutexattr_t
*
*
* DESCRIPTION
@@ -56,11 +56,11 @@ pthread_mutexattr_destroy (pthread_mutexattr_t * attr)
* no longer be used.
*
* NOTES:
- * 1) Does not affect mutexes created using 'attr'
+ * 1) Does not affect mutexes created using 'attr'
*
* RESULTS
- * 0 successfully released attr,
- * EINVAL 'attr' is invalid.
+ * 0 successfully released attr,
+ * EINVAL 'attr' is invalid.
*
* ------------------------------------------------------
*/
@@ -79,5 +79,5 @@ pthread_mutexattr_destroy (pthread_mutexattr_t * attr)
free (ma);
}
- return(result);
+ return (result);
} /* pthread_mutexattr_destroy */
diff --git a/pthread_mutexattr_getkind_np.c b/pthread_mutexattr_getkind_np.c
index b04b176..d2035ec 100644
--- a/pthread_mutexattr_getkind_np.c
+++ b/pthread_mutexattr_getkind_np.c
@@ -38,7 +38,7 @@
#include "implement.h"
int
-pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, int *kind)
+pthread_mutexattr_getkind_np (pthread_mutexattr_t * attr, int *kind)
{
- return pthread_mutexattr_gettype( attr, kind );
+ return pthread_mutexattr_gettype (attr, kind);
}
diff --git a/pthread_mutexattr_getpshared.c b/pthread_mutexattr_getpshared.c
index a94bf83..d0e14c8 100644
--- a/pthread_mutexattr_getpshared.c
+++ b/pthread_mutexattr_getpshared.c
@@ -39,8 +39,7 @@
int
-pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr,
- int *pshared)
+pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr, int *pshared)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -49,16 +48,16 @@ pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr,
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_mutexattr_t
+ * pointer to an instance of pthread_mutexattr_t
*
* pshared
- * will be set to one of:
+ * will be set to one of:
*
- * PTHREAD_PROCESS_SHARED
- * May be shared if in shared memory
+ * PTHREAD_PROCESS_SHARED
+ * May be shared if in shared memory
*
- * PTHREAD_PROCESS_PRIVATE
- * Cannot be shared.
+ * PTHREAD_PROCESS_PRIVATE
+ * Cannot be shared.
*
*
* DESCRIPTION
@@ -66,23 +65,22 @@ pthread_mutexattr_getpshared (const pthread_mutexattr_t * attr,
* processes if pthread_mutex_t variable is allocated
* in memory shared by these processes.
* NOTES:
- * 1) pshared mutexes MUST be allocated in shared
- * memory.
- * 2) The following macro is defined if shared mutexes
- * are supported:
- * _POSIX_THREAD_PROCESS_SHARED
+ * 1) pshared mutexes MUST be allocated in shared
+ * memory.
+ * 2) The following macro is defined if shared mutexes
+ * are supported:
+ * _POSIX_THREAD_PROCESS_SHARED
*
* RESULTS
- * 0 successfully retrieved attribute,
- * EINVAL 'attr' is invalid,
+ * 0 successfully retrieved attribute,
+ * EINVAL 'attr' is invalid,
*
* ------------------------------------------------------
*/
{
int result;
- if ((attr != NULL && *attr != NULL) &&
- (pshared != NULL))
+ if ((attr != NULL && *attr != NULL) && (pshared != NULL))
{
*pshared = (*attr)->pshared;
result = 0;
diff --git a/pthread_mutexattr_gettype.c b/pthread_mutexattr_gettype.c
index d8bef41..b1c241a 100644
--- a/pthread_mutexattr_gettype.c
+++ b/pthread_mutexattr_gettype.c
@@ -39,8 +39,7 @@
int
-pthread_mutexattr_gettype (pthread_mutexattr_t * attr,
- int *kind)
+pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind)
{
int result = 0;
diff --git a/pthread_mutexattr_init.c b/pthread_mutexattr_init.c
index abd4208..ae49758 100644
--- a/pthread_mutexattr_init.c
+++ b/pthread_mutexattr_init.c
@@ -48,7 +48,7 @@ pthread_mutexattr_init (pthread_mutexattr_t * attr)
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_mutexattr_t
+ * pointer to an instance of pthread_mutexattr_t
*
*
* DESCRIPTION
@@ -56,11 +56,11 @@ pthread_mutexattr_init (pthread_mutexattr_t * attr)
* attributes.
*
* NOTES:
- * 1) Used to define mutex types
+ * 1) Used to define mutex types
*
* RESULTS
- * 0 successfully initialized attr,
- * ENOMEM insufficient memory for attr.
+ * 0 successfully initialized attr,
+ * ENOMEM insufficient memory for attr.
*
* ------------------------------------------------------
*/
@@ -82,5 +82,5 @@ pthread_mutexattr_init (pthread_mutexattr_t * attr)
*attr = ma;
- return(result);
+ return (result);
} /* pthread_mutexattr_init */
diff --git a/pthread_mutexattr_setkind_np.c b/pthread_mutexattr_setkind_np.c
index d9e3ef0..506567d 100644
--- a/pthread_mutexattr_setkind_np.c
+++ b/pthread_mutexattr_setkind_np.c
@@ -38,8 +38,7 @@
#include "implement.h"
int
-pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, int kind)
+pthread_mutexattr_setkind_np (pthread_mutexattr_t * attr, int kind)
{
- return pthread_mutexattr_settype( attr, kind );
+ return pthread_mutexattr_settype (attr, kind);
}
-
diff --git a/pthread_mutexattr_setpshared.c b/pthread_mutexattr_setpshared.c
index 8446bbf..ea706dc 100644
--- a/pthread_mutexattr_setpshared.c
+++ b/pthread_mutexattr_setpshared.c
@@ -39,8 +39,7 @@
int
-pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
- int pshared)
+pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -50,16 +49,16 @@ pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_mutexattr_t
+ * pointer to an instance of pthread_mutexattr_t
*
* pshared
- * must be one of:
+ * must be one of:
*
- * PTHREAD_PROCESS_SHARED
- * May be shared if in shared memory
+ * PTHREAD_PROCESS_SHARED
+ * May be shared if in shared memory
*
- * PTHREAD_PROCESS_PRIVATE
- * Cannot be shared.
+ * PTHREAD_PROCESS_PRIVATE
+ * Cannot be shared.
*
* DESCRIPTION
* Mutexes creatd with 'attr' can be shared between
@@ -67,17 +66,17 @@ pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
* in memory shared by these processes.
*
* NOTES:
- * 1) pshared mutexes MUST be allocated in shared
- * memory.
+ * 1) pshared mutexes MUST be allocated in shared
+ * memory.
*
- * 2) The following macro is defined if shared mutexes
- * are supported:
- * _POSIX_THREAD_PROCESS_SHARED
+ * 2) The following macro is defined if shared mutexes
+ * are supported:
+ * _POSIX_THREAD_PROCESS_SHARED
*
* RESULTS
- * 0 successfully set attribute,
- * EINVAL 'attr' or pshared is invalid,
- * ENOSYS PTHREAD_PROCESS_SHARED not supported,
+ * 0 successfully set attribute,
+ * EINVAL 'attr' or pshared is invalid,
+ * ENOSYS PTHREAD_PROCESS_SHARED not supported,
*
* ------------------------------------------------------
*/
diff --git a/pthread_mutexattr_settype.c b/pthread_mutexattr_settype.c
index 1ebecec..942a199 100644
--- a/pthread_mutexattr_settype.c
+++ b/pthread_mutexattr_settype.c
@@ -39,8 +39,7 @@
int
-pthread_mutexattr_settype (pthread_mutexattr_t * attr,
- int kind)
+pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind)
/*
* ------------------------------------------------------
*
@@ -52,18 +51,18 @@ pthread_mutexattr_settype (pthread_mutexattr_t * attr,
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_mutexattr_t
+ * pointer to an instance of pthread_mutexattr_t
*
* type
- * must be one of:
+ * must be one of:
*
- * PTHREAD_MUTEX_DEFAULT
+ * PTHREAD_MUTEX_DEFAULT
*
- * PTHREAD_MUTEX_NORMAL
+ * PTHREAD_MUTEX_NORMAL
*
- * PTHREAD_MUTEX_ERRORCHECK
+ * PTHREAD_MUTEX_ERRORCHECK
*
- * PTHREAD_MUTEX_RECURSIVE
+ * PTHREAD_MUTEX_RECURSIVE
*
* DESCRIPTION
* The pthread_mutexattr_settype() and
@@ -76,45 +75,45 @@ pthread_mutexattr_settype (pthread_mutexattr_t * attr,
* mutex attributes. Valid mutex types include:
*
* PTHREAD_MUTEX_NORMAL
- * This type of mutex does not detect deadlock. A
- * thread attempting to relock this mutex without
- * first unlocking it will deadlock. Attempting to
- * unlock a mutex locked by a different thread
- * results in undefined behavior. Attempting to
- * unlock an unlocked mutex results in undefined
- * behavior.
+ * This type of mutex does not detect deadlock. A
+ * thread attempting to relock this mutex without
+ * first unlocking it will deadlock. Attempting to
+ * unlock a mutex locked by a different thread
+ * results in undefined behavior. Attempting to
+ * unlock an unlocked mutex results in undefined
+ * behavior.
*
* PTHREAD_MUTEX_ERRORCHECK
- * This type of mutex provides error checking. A
- * thread attempting to relock this mutex without
- * first unlocking it will return with an error. A
- * thread attempting to unlock a mutex which another
- * thread has locked will return with an error. A
- * thread attempting to unlock an unlocked mutex will
- * return with an error.
+ * This type of mutex provides error checking. A
+ * thread attempting to relock this mutex without
+ * first unlocking it will return with an error. A
+ * thread attempting to unlock a mutex which another
+ * thread has locked will return with an error. A
+ * thread attempting to unlock an unlocked mutex will
+ * return with an error.
*
* PTHREAD_MUTEX_DEFAULT
- * Same as PTHREAD_MUTEX_NORMAL.
+ * Same as PTHREAD_MUTEX_NORMAL.
*
* PTHREAD_MUTEX_RECURSIVE
- * A thread attempting to relock this mutex without
- * first unlocking it will succeed in locking the
- * mutex. The relocking deadlock which can occur with
- * mutexes of type PTHREAD_MUTEX_NORMAL cannot occur
- * with this type of mutex. Multiple locks of this
- * mutex require the same number of unlocks to
- * release the mutex before another thread can
- * acquire the mutex. A thread attempting to unlock a
- * mutex which another thread has locked will return
- * with an error. A thread attempting to unlock an
- * unlocked mutex will return with an error. This
- * type of mutex is only supported for mutexes whose
- * process shared attribute is
- * PTHREAD_PROCESS_PRIVATE.
+ * A thread attempting to relock this mutex without
+ * first unlocking it will succeed in locking the
+ * mutex. The relocking deadlock which can occur with
+ * mutexes of type PTHREAD_MUTEX_NORMAL cannot occur
+ * with this type of mutex. Multiple locks of this
+ * mutex require the same number of unlocks to
+ * release the mutex before another thread can
+ * acquire the mutex. A thread attempting to unlock a
+ * mutex which another thread has locked will return
+ * with an error. A thread attempting to unlock an
+ * unlocked mutex will return with an error. This
+ * type of mutex is only supported for mutexes whose
+ * process shared attribute is
+ * PTHREAD_PROCESS_PRIVATE.
*
* RESULTS
- * 0 successfully set attribute,
- * EINVAL 'attr' or 'type' is invalid,
+ * 0 successfully set attribute,
+ * EINVAL 'attr' or 'type' is invalid,
*
* ------------------------------------------------------
*/
@@ -139,6 +138,6 @@ pthread_mutexattr_settype (pthread_mutexattr_t * attr,
{
result = EINVAL;
}
-
+
return (result);
} /* pthread_mutexattr_settype */
diff --git a/pthread_num_processors_np.c b/pthread_num_processors_np.c
index abe24d7..cf939b2 100644
--- a/pthread_num_processors_np.c
+++ b/pthread_num_processors_np.c
@@ -43,11 +43,11 @@
* Get the number of CPUs available to the process.
*/
int
-pthread_num_processors_np(void)
+pthread_num_processors_np (void)
{
int count;
- if ( ptw32_getprocessors(& count) != 0 )
+ if (ptw32_getprocessors (&count) != 0)
{
count = 1;
}
diff --git a/pthread_once.c b/pthread_once.c
index b698d68..d37ee3d 100644
--- a/pthread_once.c
+++ b/pthread_once.c
@@ -39,38 +39,35 @@
int
-pthread_once (
- pthread_once_t * once_control,
- void (*init_routine) (void)
-)
+pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
/*
* ------------------------------------------------------
* DOCPUBLIC
- * If any thread in a process with a once_control parameter
- * makes a call to pthread_once(), the first call will summon
- * the init_routine(), but subsequent calls will not. The
- * once_control parameter determines whether the associated
- * initialization routine has been called. The init_routine()
- * is complete upon return of pthread_once().
- * This function guarantees that one and only one thread
- * executes the initialization routine, init_routine when
- * access is controlled by the pthread_once_t control
- * key.
+ * If any thread in a process with a once_control parameter
+ * makes a call to pthread_once(), the first call will summon
+ * the init_routine(), but subsequent calls will not. The
+ * once_control parameter determines whether the associated
+ * initialization routine has been called. The init_routine()
+ * is complete upon return of pthread_once().
+ * This function guarantees that one and only one thread
+ * executes the initialization routine, init_routine when
+ * access is controlled by the pthread_once_t control
+ * key.
*
* PARAMETERS
- * once_control
- * pointer to an instance of pthread_once_t
+ * once_control
+ * pointer to an instance of pthread_once_t
*
- * init_routine
- * pointer to an initialization routine
+ * init_routine
+ * pointer to an initialization routine
*
*
* DESCRIPTION
- * See above.
+ * See above.
*
* RESULTS
- * 0 success,
- * EINVAL once_control or init_routine is NULL
+ * 0 success,
+ * EINVAL once_control or init_routine is NULL
*
* ------------------------------------------------------
*/
diff --git a/pthread_rwlock_destroy.c b/pthread_rwlock_destroy.c
index f759ed0..63d0cfd 100644
--- a/pthread_rwlock_destroy.c
+++ b/pthread_rwlock_destroy.c
@@ -41,100 +41,103 @@
#include "implement.h"
int
-pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
+pthread_rwlock_destroy (pthread_rwlock_t * rwlock)
{
- pthread_rwlock_t rwl;
- int result = 0, result1 = 0, result2 = 0;
+ pthread_rwlock_t rwl;
+ int result = 0, result1 = 0, result2 = 0;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- if (*rwlock != PTHREAD_RWLOCK_INITIALIZER)
- {
- rwl = *rwlock;
+ if (*rwlock != PTHREAD_RWLOCK_INITIALIZER)
+ {
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_lock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if ((result =
+ pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- /*
- * Check whether any threads own/wait for the lock (wait for ex.access);
- * report "BUSY" if so.
- */
- if (rwl->nExclusiveAccessCount > 0
- || rwl->nSharedAccessCount > rwl->nCompletedSharedAccessCount)
- {
- result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted));
- result1 = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- result2 = EBUSY;
- }
- else
- {
- rwl->nMagic = 0;
+ /*
+ * Check whether any threads own/wait for the lock (wait for ex.access);
+ * report "BUSY" if so.
+ */
+ if (rwl->nExclusiveAccessCount > 0
+ || rwl->nSharedAccessCount > rwl->nCompletedSharedAccessCount)
+ {
+ result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
+ result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ result2 = EBUSY;
+ }
+ else
+ {
+ rwl->nMagic = 0;
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- pthread_mutex_unlock(&rwl->mtxExclusiveAccess);
- return result;
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ pthread_mutex_unlock (&rwl->mtxExclusiveAccess);
+ return result;
+ }
- if ((result = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- *rwlock = NULL; /* Invalidate rwlock before anything else */
- result = pthread_cond_destroy(&(rwl->cndSharedAccessCompleted));
- result1 = pthread_mutex_destroy(&(rwl->mtxSharedAccessCompleted));
- result2 = pthread_mutex_destroy(&(rwl->mtxExclusiveAccess));
- (void) free(rwl);
- }
- }
- else
- {
- /*
- * See notes in ptw32_rwlock_check_need_init() above also.
- */
- EnterCriticalSection(&ptw32_rwlock_test_init_lock);
+ *rwlock = NULL; /* Invalidate rwlock before anything else */
+ result = pthread_cond_destroy (&(rwl->cndSharedAccessCompleted));
+ result1 = pthread_mutex_destroy (&(rwl->mtxSharedAccessCompleted));
+ result2 = pthread_mutex_destroy (&(rwl->mtxExclusiveAccess));
+ (void) free (rwl);
+ }
+ }
+ else
+ {
+ /*
+ * See notes in ptw32_rwlock_check_need_init() above also.
+ */
+ EnterCriticalSection (&ptw32_rwlock_test_init_lock);
- /*
- * Check again.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- /*
- * This is all we need to do to destroy a statically
- * initialised rwlock that has not yet been used (initialised).
- * If we get to here, another thread
- * waiting to initialise this rwlock will get an EINVAL.
- */
- *rwlock = NULL;
- }
- else
- {
- /*
- * The rwlock has been initialised while we were waiting
- * so assume it's in use.
- */
- result = EBUSY;
- }
+ /*
+ * Check again.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ /*
+ * This is all we need to do to destroy a statically
+ * initialised rwlock that has not yet been used (initialised).
+ * If we get to here, another thread
+ * waiting to initialise this rwlock will get an EINVAL.
+ */
+ *rwlock = NULL;
+ }
+ else
+ {
+ /*
+ * The rwlock has been initialised while we were waiting
+ * so assume it's in use.
+ */
+ result = EBUSY;
+ }
- LeaveCriticalSection(&ptw32_rwlock_test_init_lock);
- }
+ LeaveCriticalSection (&ptw32_rwlock_test_init_lock);
+ }
- return ((result != 0) ? result : ((result1 != 0) ? result1 : result2));
+ return ((result != 0) ? result : ((result1 != 0) ? result1 : result2));
}
diff --git a/pthread_rwlock_init.c b/pthread_rwlock_init.c
index 3a71ff2..8c27cac 100644
--- a/pthread_rwlock_init.c
+++ b/pthread_rwlock_init.c
@@ -41,69 +41,70 @@
#include "implement.h"
int
-pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
+pthread_rwlock_init (pthread_rwlock_t * rwlock,
+ const pthread_rwlockattr_t * attr)
{
- int result;
- pthread_rwlock_t rwl = 0;
-
- if (rwlock == NULL)
- {
- return EINVAL;
- }
-
- if (attr != NULL && *attr != NULL)
- {
- result = EINVAL; /* Not supported */
- goto DONE;
- }
-
- rwl = (pthread_rwlock_t) calloc(1, sizeof(*rwl));
-
- if (rwl == NULL)
- {
- result = ENOMEM;
- goto DONE;
- }
-
- rwl->nSharedAccessCount = 0;
- rwl->nExclusiveAccessCount = 0;
- rwl->nCompletedSharedAccessCount = 0;
-
- result = pthread_mutex_init(&rwl->mtxExclusiveAccess, NULL);
- if (result != 0)
- {
- goto FAIL0;
- }
-
- result = pthread_mutex_init(&rwl->mtxSharedAccessCompleted, NULL);
- if (result != 0)
- {
- goto FAIL1;
- }
-
- result = pthread_cond_init(&rwl->cndSharedAccessCompleted, NULL);
- if (result != 0)
- {
- goto FAIL2;
- }
-
- rwl->nMagic = PTW32_RWLOCK_MAGIC;
-
- result = 0;
- goto DONE;
+ int result;
+ pthread_rwlock_t rwl = 0;
+
+ if (rwlock == NULL)
+ {
+ return EINVAL;
+ }
+
+ if (attr != NULL && *attr != NULL)
+ {
+ result = EINVAL; /* Not supported */
+ goto DONE;
+ }
+
+ rwl = (pthread_rwlock_t) calloc (1, sizeof (*rwl));
+
+ if (rwl == NULL)
+ {
+ result = ENOMEM;
+ goto DONE;
+ }
+
+ rwl->nSharedAccessCount = 0;
+ rwl->nExclusiveAccessCount = 0;
+ rwl->nCompletedSharedAccessCount = 0;
+
+ result = pthread_mutex_init (&rwl->mtxExclusiveAccess, NULL);
+ if (result != 0)
+ {
+ goto FAIL0;
+ }
+
+ result = pthread_mutex_init (&rwl->mtxSharedAccessCompleted, NULL);
+ if (result != 0)
+ {
+ goto FAIL1;
+ }
+
+ result = pthread_cond_init (&rwl->cndSharedAccessCompleted, NULL);
+ if (result != 0)
+ {
+ goto FAIL2;
+ }
+
+ rwl->nMagic = PTW32_RWLOCK_MAGIC;
+
+ result = 0;
+ goto DONE;
FAIL2:
- (void) pthread_mutex_destroy(&(rwl->mtxSharedAccessCompleted));
+ (void) pthread_mutex_destroy (&(rwl->mtxSharedAccessCompleted));
FAIL1:
- (void) pthread_mutex_destroy(&(rwl->mtxExclusiveAccess));
+ (void) pthread_mutex_destroy (&(rwl->mtxExclusiveAccess));
FAIL0:
- (void) free(rwl);
- rwl = NULL;
+ (void) free (rwl);
+ rwl = NULL;
DONE:
- *rwlock = rwl;
+ *rwlock = rwl;
- return result;
+ return result;
}
diff --git a/pthread_rwlock_rdlock.c b/pthread_rwlock_rdlock.c
index 029f6b8..3fbf831 100644
--- a/pthread_rwlock_rdlock.c
+++ b/pthread_rwlock_rdlock.c
@@ -41,61 +41,63 @@
#include "implement.h"
int
-pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
+pthread_rwlock_rdlock (pthread_rwlock_t * rwlock)
{
- int result;
- pthread_rwlock_t rwl;
+ int result;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_lock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- if (++rwl->nSharedAccessCount == INT_MAX)
- {
- if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if (++rwl->nSharedAccessCount == INT_MAX)
+ {
+ if ((result =
+ pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
+ }
- return (pthread_mutex_unlock(&(rwl->mtxExclusiveAccess)));
+ return (pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)));
}
diff --git a/pthread_rwlock_timedrdlock.c b/pthread_rwlock_timedrdlock.c
index 938615f..1e40f6c 100644
--- a/pthread_rwlock_timedrdlock.c
+++ b/pthread_rwlock_timedrdlock.c
@@ -41,65 +41,70 @@
#include "implement.h"
int
-pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec * abstime)
+pthread_rwlock_timedrdlock (pthread_rwlock_t * rwlock,
+ const struct timespec *abstime)
{
- int result;
- pthread_rwlock_t rwl;
+ int result;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_timedlock(&(rwl->mtxExclusiveAccess), abstime)) != 0)
- {
- return result;
- }
+ if ((result =
+ pthread_mutex_timedlock (&(rwl->mtxExclusiveAccess), abstime)) != 0)
+ {
+ return result;
+ }
- if (++rwl->nSharedAccessCount == INT_MAX)
- {
- if ((result = pthread_mutex_timedlock(&(rwl->mtxSharedAccessCompleted), abstime)) != 0)
- {
- if (result == ETIMEDOUT)
- {
- ++rwl->nCompletedSharedAccessCount;
- }
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if (++rwl->nSharedAccessCount == INT_MAX)
+ {
+ if ((result =
+ pthread_mutex_timedlock (&(rwl->mtxSharedAccessCompleted),
+ abstime)) != 0)
+ {
+ if (result == ETIMEDOUT)
+ {
+ ++rwl->nCompletedSharedAccessCount;
+ }
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
+ }
- return (pthread_mutex_unlock(&(rwl->mtxExclusiveAccess)));
+ return (pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)));
}
diff --git a/pthread_rwlock_timedwrlock.c b/pthread_rwlock_timedwrlock.c
index 5844510..b23abd2 100644
--- a/pthread_rwlock_timedwrlock.c
+++ b/pthread_rwlock_timedwrlock.c
@@ -41,95 +41,100 @@
#include "implement.h"
int
-pthread_rwlock_timedwrlock(pthread_rwlock_t * rwlock, const struct timespec * abstime)
+pthread_rwlock_timedwrlock (pthread_rwlock_t * rwlock,
+ const struct timespec *abstime)
{
- int result;
- pthread_rwlock_t rwl;
-
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
-
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
-
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
-
- rwl = *rwlock;
-
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
-
- if ((result = pthread_mutex_timedlock(&(rwl->mtxExclusiveAccess), abstime)) != 0)
- {
- return result;
- }
-
- if ((result = pthread_mutex_timedlock(&(rwl->mtxSharedAccessCompleted), abstime)) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
-
- if (rwl->nExclusiveAccessCount == 0)
- {
- if (rwl->nCompletedSharedAccessCount > 0)
- {
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
- }
-
- if (rwl->nSharedAccessCount > 0)
- {
- rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount;
-
- /*
- * This routine may be a cancelation point
- * according to POSIX 1003.1j section 18.1.2.
- */
+ int result;
+ pthread_rwlock_t rwl;
+
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
+
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
+
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
+
+ rwl = *rwlock;
+
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
+
+ if ((result =
+ pthread_mutex_timedlock (&(rwl->mtxExclusiveAccess), abstime)) != 0)
+ {
+ return result;
+ }
+
+ if ((result =
+ pthread_mutex_timedlock (&(rwl->mtxSharedAccessCompleted),
+ abstime)) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
+
+ if (rwl->nExclusiveAccessCount == 0)
+ {
+ if (rwl->nCompletedSharedAccessCount > 0)
+ {
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
+ }
+
+ if (rwl->nSharedAccessCount > 0)
+ {
+ rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount;
+
+ /*
+ * This routine may be a cancelation point
+ * according to POSIX 1003.1j section 18.1.2.
+ */
#ifdef _MSC_VER
#pragma inline_depth(0)
#endif
- pthread_cleanup_push(ptw32_rwlock_cancelwrwait, (void*)rwl);
-
- do
- {
- result = pthread_cond_timedwait(&(rwl->cndSharedAccessCompleted),
- &(rwl->mtxSharedAccessCompleted),
- abstime);
- }
- while (result == 0 && rwl->nCompletedSharedAccessCount < 0);
-
- pthread_cleanup_pop ((result != 0) ? 1 : 0);
+ pthread_cleanup_push (ptw32_rwlock_cancelwrwait, (void *) rwl);
+
+ do
+ {
+ result =
+ pthread_cond_timedwait (&(rwl->cndSharedAccessCompleted),
+ &(rwl->mtxSharedAccessCompleted),
+ abstime);
+ }
+ while (result == 0 && rwl->nCompletedSharedAccessCount < 0);
+
+ pthread_cleanup_pop ((result != 0) ? 1 : 0);
#ifdef _MSC_VER
#pragma inline_depth()
#endif
- if (result == 0)
- {
- rwl->nSharedAccessCount = 0;
- }
- }
- }
+ if (result == 0)
+ {
+ rwl->nSharedAccessCount = 0;
+ }
+ }
+ }
- if (result == 0)
- {
- rwl->nExclusiveAccessCount++;
- }
+ if (result == 0)
+ {
+ rwl->nExclusiveAccessCount++;
+ }
- return result;
+ return result;
}
diff --git a/pthread_rwlock_tryrdlock.c b/pthread_rwlock_tryrdlock.c
index 284523b..36eb0db 100644
--- a/pthread_rwlock_tryrdlock.c
+++ b/pthread_rwlock_tryrdlock.c
@@ -41,61 +41,63 @@
#include "implement.h"
int
-pthread_rwlock_tryrdlock(pthread_rwlock_t * rwlock)
+pthread_rwlock_tryrdlock (pthread_rwlock_t * rwlock)
{
- int result;
- pthread_rwlock_t rwl;
+ int result;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_trylock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result = pthread_mutex_trylock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- if (++rwl->nSharedAccessCount == INT_MAX)
- {
- if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if (++rwl->nSharedAccessCount == INT_MAX)
+ {
+ if ((result =
+ pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
+ }
- return (pthread_mutex_unlock(&rwl->mtxExclusiveAccess));
+ return (pthread_mutex_unlock (&rwl->mtxExclusiveAccess));
}
diff --git a/pthread_rwlock_trywrlock.c b/pthread_rwlock_trywrlock.c
index 6fa92ed..543fdbf 100644
--- a/pthread_rwlock_trywrlock.c
+++ b/pthread_rwlock_trywrlock.c
@@ -41,80 +41,83 @@
#include "implement.h"
int
-pthread_rwlock_trywrlock(pthread_rwlock_t * rwlock)
+pthread_rwlock_trywrlock (pthread_rwlock_t * rwlock)
{
- int result, result1;
- pthread_rwlock_t rwl;
+ int result, result1;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if ((result = pthread_mutex_trylock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
+ if ((result = pthread_mutex_trylock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
- if ((result = pthread_mutex_trylock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- result1 = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return ((result1 != 0) ? result1 : result);
- }
+ if ((result =
+ pthread_mutex_trylock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return ((result1 != 0) ? result1 : result);
+ }
- if (rwl->nExclusiveAccessCount == 0)
- {
- if (rwl->nCompletedSharedAccessCount > 0)
- {
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
- }
+ if (rwl->nExclusiveAccessCount == 0)
+ {
+ if (rwl->nCompletedSharedAccessCount > 0)
+ {
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
+ }
- if (rwl->nSharedAccessCount > 0)
- {
- if ((result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
+ if (rwl->nSharedAccessCount > 0)
+ {
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
- if ((result = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess))) == 0)
- {
- result = EBUSY;
- }
- }
- else
- {
- rwl->nExclusiveAccessCount = 1;
- }
- }
- else
- {
- result = EBUSY;
- }
+ if ((result =
+ pthread_mutex_unlock (&(rwl->mtxExclusiveAccess))) == 0)
+ {
+ result = EBUSY;
+ }
+ }
+ else
+ {
+ rwl->nExclusiveAccessCount = 1;
+ }
+ }
+ else
+ {
+ result = EBUSY;
+ }
- return result;
+ return result;
}
diff --git a/pthread_rwlock_unlock.c b/pthread_rwlock_unlock.c
index 2d00ab0..1d61408 100644
--- a/pthread_rwlock_unlock.c
+++ b/pthread_rwlock_unlock.c
@@ -41,53 +41,54 @@
#include "implement.h"
int
-pthread_rwlock_unlock(pthread_rwlock_t * rwlock)
+pthread_rwlock_unlock (pthread_rwlock_t * rwlock)
{
- int result, result1;
- pthread_rwlock_t rwl;
+ int result, result1;
+ pthread_rwlock_t rwl;
- if (rwlock == NULL || *rwlock == NULL)
- {
- return(EINVAL);
- }
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return (EINVAL);
+ }
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- /*
- * Assume any race condition here is harmless.
- */
- return 0;
- }
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ /*
+ * Assume any race condition here is harmless.
+ */
+ return 0;
+ }
- rwl = *rwlock;
+ rwl = *rwlock;
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
- if (rwl->nExclusiveAccessCount == 0)
- {
- if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- return result;
- }
+ if (rwl->nExclusiveAccessCount == 0)
+ {
+ if ((result =
+ pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ return result;
+ }
- if (++rwl->nCompletedSharedAccessCount == 0)
- {
- result = pthread_cond_signal(&(rwl->cndSharedAccessCompleted));
- }
+ if (++rwl->nCompletedSharedAccessCount == 0)
+ {
+ result = pthread_cond_signal (&(rwl->cndSharedAccessCompleted));
+ }
- result1 = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted));
- }
- else
- {
- rwl->nExclusiveAccessCount--;
+ result1 = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
+ }
+ else
+ {
+ rwl->nExclusiveAccessCount--;
- result = pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted));
- result1 = pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
+ result = pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
+ result1 = pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
- }
-
- return ((result != 0) ? result : result1);
+ }
+
+ return ((result != 0) ? result : result1);
}
diff --git a/pthread_rwlock_wrlock.c b/pthread_rwlock_wrlock.c
index 3c0eed7..384c779 100644
--- a/pthread_rwlock_wrlock.c
+++ b/pthread_rwlock_wrlock.c
@@ -41,94 +41,94 @@
#include "implement.h"
int
-pthread_rwlock_wrlock(pthread_rwlock_t * rwlock)
+pthread_rwlock_wrlock (pthread_rwlock_t * rwlock)
{
- int result;
- pthread_rwlock_t rwl;
-
- if (rwlock == NULL || *rwlock == NULL)
- {
- return EINVAL;
- }
-
- /*
- * We do a quick check to see if we need to do more work
- * to initialise a static rwlock. We check
- * again inside the guarded section of ptw32_rwlock_check_need_init()
- * to avoid race conditions.
- */
- if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
- {
- result = ptw32_rwlock_check_need_init(rwlock);
-
- if (result != 0 && result != EBUSY)
- {
- return result;
- }
- }
-
- rwl = *rwlock;
-
- if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
- {
- return EINVAL;
- }
-
- if ((result = pthread_mutex_lock(&(rwl->mtxExclusiveAccess))) != 0)
- {
- return result;
- }
-
- if ((result = pthread_mutex_lock(&(rwl->mtxSharedAccessCompleted))) != 0)
- {
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
- return result;
- }
-
- if (rwl->nExclusiveAccessCount == 0)
- {
- if (rwl->nCompletedSharedAccessCount > 0)
- {
- rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
- }
-
- if (rwl->nSharedAccessCount > 0)
- {
- rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount;
-
- /*
- * This routine may be a cancelation point
- * according to POSIX 1003.1j section 18.1.2.
- */
+ int result;
+ pthread_rwlock_t rwl;
+
+ if (rwlock == NULL || *rwlock == NULL)
+ {
+ return EINVAL;
+ }
+
+ /*
+ * We do a quick check to see if we need to do more work
+ * to initialise a static rwlock. We check
+ * again inside the guarded section of ptw32_rwlock_check_need_init()
+ * to avoid race conditions.
+ */
+ if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
+ {
+ result = ptw32_rwlock_check_need_init (rwlock);
+
+ if (result != 0 && result != EBUSY)
+ {
+ return result;
+ }
+ }
+
+ rwl = *rwlock;
+
+ if (rwl->nMagic != PTW32_RWLOCK_MAGIC)
+ {
+ return EINVAL;
+ }
+
+ if ((result = pthread_mutex_lock (&(rwl->mtxExclusiveAccess))) != 0)
+ {
+ return result;
+ }
+
+ if ((result = pthread_mutex_lock (&(rwl->mtxSharedAccessCompleted))) != 0)
+ {
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
+ return result;
+ }
+
+ if (rwl->nExclusiveAccessCount == 0)
+ {
+ if (rwl->nCompletedSharedAccessCount > 0)
+ {
+ rwl->nSharedAccessCount -= rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
+ }
+
+ if (rwl->nSharedAccessCount > 0)
+ {
+ rwl->nCompletedSharedAccessCount = -rwl->nSharedAccessCount;
+
+ /*
+ * This routine may be a cancelation point
+ * according to POSIX 1003.1j section 18.1.2.
+ */
#ifdef _MSC_VER
#pragma inline_depth(0)
#endif
- pthread_cleanup_push(ptw32_rwlock_cancelwrwait, (void*)rwl);
+ pthread_cleanup_push (ptw32_rwlock_cancelwrwait, (void *) rwl);
- do
- {
- result = pthread_cond_wait(&(rwl->cndSharedAccessCompleted),
- &(rwl->mtxSharedAccessCompleted));
- }
- while (result == 0 && rwl->nCompletedSharedAccessCount < 0);
+ do
+ {
+ result = pthread_cond_wait (&(rwl->cndSharedAccessCompleted),
+ &(rwl->mtxSharedAccessCompleted));
+ }
+ while (result == 0 && rwl->nCompletedSharedAccessCount < 0);
- pthread_cleanup_pop ((result != 0) ? 1 : 0);
+ pthread_cleanup_pop ((result != 0) ? 1 : 0);
#ifdef _MSC_VER
#pragma inline_depth()
#endif
- if (result == 0)
- {
- rwl->nSharedAccessCount = 0;
- }
- }
- }
+ if (result == 0)
+ {
+ rwl->nSharedAccessCount = 0;
+ }
+ }
+ }
- if (result == 0)
- {
- rwl->nExclusiveAccessCount++;
- }
+ if (result == 0)
+ {
+ rwl->nExclusiveAccessCount++;
+ }
- return result;
+ return result;
}
diff --git a/pthread_rwlockattr_destroy.c b/pthread_rwlockattr_destroy.c
index 858f248..95651b1 100644
--- a/pthread_rwlockattr_destroy.c
+++ b/pthread_rwlockattr_destroy.c
@@ -50,7 +50,7 @@ pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr)
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_rwlockattr_t
+ * pointer to an instance of pthread_rwlockattr_t
*
*
* DESCRIPTION
@@ -58,11 +58,11 @@ pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr)
* no longer be used.
*
* NOTES:
- * 1) Does not affect rwlockss created using 'attr'
+ * 1) Does not affect rwlockss created using 'attr'
*
* RESULTS
- * 0 successfully released attr,
- * EINVAL 'attr' is invalid.
+ * 0 successfully released attr,
+ * EINVAL 'attr' is invalid.
*
* ------------------------------------------------------
*/
@@ -81,5 +81,5 @@ pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr)
free (rwa);
}
- return(result);
+ return (result);
} /* pthread_rwlockattr_destroy */
diff --git a/pthread_rwlockattr_getpshared.c b/pthread_rwlockattr_getpshared.c
index 9d831de..741a197 100644
--- a/pthread_rwlockattr_getpshared.c
+++ b/pthread_rwlockattr_getpshared.c
@@ -51,16 +51,16 @@ pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_rwlockattr_t
+ * pointer to an instance of pthread_rwlockattr_t
*
* pshared
- * will be set to one of:
+ * will be set to one of:
*
- * PTHREAD_PROCESS_SHARED
- * May be shared if in shared memory
+ * PTHREAD_PROCESS_SHARED
+ * May be shared if in shared memory
*
- * PTHREAD_PROCESS_PRIVATE
- * Cannot be shared.
+ * PTHREAD_PROCESS_PRIVATE
+ * Cannot be shared.
*
*
* DESCRIPTION
@@ -68,23 +68,22 @@ pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
* processes if pthread_rwlock_t variable is allocated
* in memory shared by these processes.
* NOTES:
- * 1) pshared rwlocks MUST be allocated in shared
- * memory.
- * 2) The following macro is defined if shared rwlocks
- * are supported:
- * _POSIX_THREAD_PROCESS_SHARED
+ * 1) pshared rwlocks MUST be allocated in shared
+ * memory.
+ * 2) The following macro is defined if shared rwlocks
+ * are supported:
+ * _POSIX_THREAD_PROCESS_SHARED
*
* RESULTS
- * 0 successfully retrieved attribute,
- * EINVAL 'attr' is invalid,
+ * 0 successfully retrieved attribute,
+ * EINVAL 'attr' is invalid,
*
* ------------------------------------------------------
*/
{
int result;
- if ((attr != NULL && *attr != NULL) &&
- (pshared != NULL))
+ if ((attr != NULL && *attr != NULL) && (pshared != NULL))
{
*pshared = (*attr)->pshared;
result = 0;
diff --git a/pthread_rwlockattr_init.c b/pthread_rwlockattr_init.c
index f7c49fe..242055a 100644
--- a/pthread_rwlockattr_init.c
+++ b/pthread_rwlockattr_init.c
@@ -50,7 +50,7 @@ pthread_rwlockattr_init (pthread_rwlockattr_t * attr)
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_rwlockattr_t
+ * pointer to an instance of pthread_rwlockattr_t
*
*
* DESCRIPTION
@@ -58,8 +58,8 @@ pthread_rwlockattr_init (pthread_rwlockattr_t * attr)
* attributes.
*
* RESULTS
- * 0 successfully initialized attr,
- * ENOMEM insufficient memory for attr.
+ * 0 successfully initialized attr,
+ * ENOMEM insufficient memory for attr.
*
* ------------------------------------------------------
*/
@@ -80,5 +80,5 @@ pthread_rwlockattr_init (pthread_rwlockattr_t * attr)
*attr = rwa;
- return(result);
+ return (result);
} /* pthread_rwlockattr_init */
diff --git a/pthread_rwlockattr_setpshared.c b/pthread_rwlockattr_setpshared.c
index 67dd700..9cd2490 100644
--- a/pthread_rwlockattr_setpshared.c
+++ b/pthread_rwlockattr_setpshared.c
@@ -41,8 +41,7 @@
#include "implement.h"
int
-pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
- int pshared)
+pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, int pshared)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -52,16 +51,16 @@ pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
*
* PARAMETERS
* attr
- * pointer to an instance of pthread_rwlockattr_t
+ * pointer to an instance of pthread_rwlockattr_t
*
* pshared
- * must be one of:
+ * must be one of:
*
- * PTHREAD_PROCESS_SHARED
- * May be shared if in shared memory
+ * PTHREAD_PROCESS_SHARED
+ * May be shared if in shared memory
*
- * PTHREAD_PROCESS_PRIVATE
- * Cannot be shared.
+ * PTHREAD_PROCESS_PRIVATE
+ * Cannot be shared.
*
* DESCRIPTION
* Rwlocks creatd with 'attr' can be shared between
@@ -69,17 +68,17 @@ pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
* in memory shared by these processes.
*
* NOTES:
- * 1) pshared rwlocks MUST be allocated in shared
- * memory.
+ * 1) pshared rwlocks MUST be allocated in shared
+ * memory.
*
- * 2) The following macro is defined if shared rwlocks
- * are supported:
- * _POSIX_THREAD_PROCESS_SHARED
+ * 2) The following macro is defined if shared rwlocks
+ * are supported:
+ * _POSIX_THREAD_PROCESS_SHARED
*
* RESULTS
- * 0 successfully set attribute,
- * EINVAL 'attr' or pshared is invalid,
- * ENOSYS PTHREAD_PROCESS_SHARED not supported,
+ * 0 successfully set attribute,
+ * EINVAL 'attr' or pshared is invalid,
+ * ENOSYS PTHREAD_PROCESS_SHARED not supported,
*
* ------------------------------------------------------
*/
diff --git a/pthread_self.c b/pthread_self.c
index 61979cd..5cad22a 100644
--- a/pthread_self.c
+++ b/pthread_self.c
@@ -55,7 +55,7 @@ pthread_self (void)
* thread.
*
* RESULTS
- * pthread_t reference to the current thread
+ * pthread_t reference to the current thread
*
* ------------------------------------------------------
*/
@@ -63,8 +63,8 @@ pthread_self (void)
pthread_t self;
#ifdef _UWIN
- if(!ptw32_selfThreadKey)
- return(NULL);
+ if (!ptw32_selfThreadKey)
+ return (NULL);
#endif
self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
@@ -75,7 +75,7 @@ pthread_self (void)
* Need to create an implicit 'self' for the currently
* executing thread.
*/
- self = ptw32_new();
+ self = ptw32_new ();
if (self != NULL)
{
@@ -99,28 +99,25 @@ pthread_self (void)
* Therefore, you should not pass the handle to
* other threads for whatever purpose.
*/
- self->threadH = GetCurrentThread();
+ self->threadH = GetCurrentThread ();
#else
- if( !DuplicateHandle(
- GetCurrentProcess(),
- GetCurrentThread(),
- GetCurrentProcess(),
- &self->threadH,
- 0,
- FALSE,
- DUPLICATE_SAME_ACCESS ) )
+ if (!DuplicateHandle (GetCurrentProcess (),
+ GetCurrentThread (),
+ GetCurrentProcess (),
+ &self->threadH,
+ 0, FALSE, DUPLICATE_SAME_ACCESS))
{
/* Thread structs are never freed. */
- ptw32_threadReusePush(self);
+ ptw32_threadReusePush (self);
return (NULL);
}
#endif
- /*
- * No need to explicitly serialise access to sched_priority
- * because the new handle is not yet public.
- */
- self->sched_priority = GetThreadPriority(self->threadH);
+ /*
+ * No need to explicitly serialise access to sched_priority
+ * because the new handle is not yet public.
+ */
+ self->sched_priority = GetThreadPriority (self->threadH);
}
pthread_setspecific (ptw32_selfThreadKey, self);
diff --git a/pthread_setcancelstate.c b/pthread_setcancelstate.c
index dcea53e..4432a6f 100644
--- a/pthread_setcancelstate.c
+++ b/pthread_setcancelstate.c
@@ -80,11 +80,10 @@ pthread_setcancelstate (int state, int *oldstate)
*/
{
int result = 0;
- pthread_t self = pthread_self();
+ pthread_t self = pthread_self ();
if (self == NULL
- || (state != PTHREAD_CANCEL_ENABLE
- && state != PTHREAD_CANCEL_DISABLE))
+ || (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE))
{
return EINVAL;
}
@@ -92,7 +91,7 @@ pthread_setcancelstate (int state, int *oldstate)
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&self->cancelLock);
+ (void) pthread_mutex_lock (&self->cancelLock);
if (oldstate != NULL)
{
@@ -106,20 +105,19 @@ pthread_setcancelstate (int state, int *oldstate)
*/
if (state == PTHREAD_CANCEL_ENABLE
&& self->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
- && WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0)
+ && WaitForSingleObject (self->cancelEvent, 0) == WAIT_OBJECT_0)
{
self->state = PThreadStateCanceling;
self->cancelState = PTHREAD_CANCEL_DISABLE;
- ResetEvent(self->cancelEvent);
- (void) pthread_mutex_unlock(&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
+ ResetEvent (self->cancelEvent);
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ ptw32_throw (PTW32_EPS_CANCEL);
/* Never reached */
}
- (void) pthread_mutex_unlock(&self->cancelLock);
+ (void) pthread_mutex_unlock (&self->cancelLock);
return (result);
-} /* pthread_setcancelstate */
-
+} /* pthread_setcancelstate */
diff --git a/pthread_setcanceltype.c b/pthread_setcanceltype.c
index cb23890..9486353 100644
--- a/pthread_setcanceltype.c
+++ b/pthread_setcanceltype.c
@@ -80,11 +80,11 @@ pthread_setcanceltype (int type, int *oldtype)
*/
{
int result = 0;
- pthread_t self = pthread_self();
+ pthread_t self = pthread_self ();
if (self == NULL
|| (type != PTHREAD_CANCEL_DEFERRED
- && type != PTHREAD_CANCEL_ASYNCHRONOUS))
+ && type != PTHREAD_CANCEL_ASYNCHRONOUS))
{
return EINVAL;
}
@@ -92,7 +92,7 @@ pthread_setcanceltype (int type, int *oldtype)
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&self->cancelLock);
+ (void) pthread_mutex_lock (&self->cancelLock);
if (oldtype != NULL)
{
@@ -106,20 +106,19 @@ pthread_setcanceltype (int type, int *oldtype)
*/
if (self->cancelState == PTHREAD_CANCEL_ENABLE
&& type == PTHREAD_CANCEL_ASYNCHRONOUS
- && WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0)
+ && WaitForSingleObject (self->cancelEvent, 0) == WAIT_OBJECT_0)
{
self->state = PThreadStateCanceling;
self->cancelState = PTHREAD_CANCEL_DISABLE;
- ResetEvent(self->cancelEvent);
- (void) pthread_mutex_unlock(&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
+ ResetEvent (self->cancelEvent);
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ ptw32_throw (PTW32_EPS_CANCEL);
/* Never reached */
}
- (void) pthread_mutex_unlock(&self->cancelLock);
+ (void) pthread_mutex_unlock (&self->cancelLock);
return (result);
-} /* pthread_setcanceltype */
-
+} /* pthread_setcanceltype */
diff --git a/pthread_setconcurrency.c b/pthread_setconcurrency.c
index e4c455a..7ce7d55 100644
--- a/pthread_setconcurrency.c
+++ b/pthread_setconcurrency.c
@@ -39,7 +39,7 @@
int
-pthread_setconcurrency(int level)
+pthread_setconcurrency (int level)
{
if (level < 0)
{
diff --git a/pthread_setschedparam.c b/pthread_setschedparam.c
index 1447c04..d23e5d0 100644
--- a/pthread_setschedparam.c
+++ b/pthread_setschedparam.c
@@ -39,13 +39,13 @@
#include "sched.h"
int
-pthread_setschedparam(pthread_t thread, int policy,
- const struct sched_param *param)
+pthread_setschedparam (pthread_t thread, int policy,
+ const struct sched_param *param)
{
int result;
/* Validate the thread id. */
- result = pthread_kill(thread, 0);
+ result = pthread_kill (thread, 0);
if (0 != result)
{
return result;
@@ -63,12 +63,12 @@ pthread_setschedparam(pthread_t thread, int policy,
return ENOTSUP;
}
- return (ptw32_setthreadpriority(thread, policy, param->sched_priority));
+ return (ptw32_setthreadpriority (thread, policy, param->sched_priority));
}
int
-ptw32_setthreadpriority(pthread_t thread, int policy, int priority)
+ptw32_setthreadpriority (pthread_t thread, int policy, int priority)
{
int prio;
int result;
@@ -76,8 +76,8 @@ ptw32_setthreadpriority(pthread_t thread, int policy, int priority)
prio = priority;
/* Validate priority level. */
- if (prio < sched_get_priority_min(policy) ||
- prio > sched_get_priority_max(policy))
+ if (prio < sched_get_priority_min (policy) ||
+ prio > sched_get_priority_max (policy))
{
return EINVAL;
}
@@ -87,38 +87,37 @@ ptw32_setthreadpriority(pthread_t thread, int policy, int priority)
#else
/* Everything else */
- if (THREAD_PRIORITY_IDLE < prio
- && THREAD_PRIORITY_LOWEST > prio)
+ if (THREAD_PRIORITY_IDLE < prio && THREAD_PRIORITY_LOWEST > prio)
{
prio = THREAD_PRIORITY_LOWEST;
}
else if (THREAD_PRIORITY_TIME_CRITICAL > prio
- && THREAD_PRIORITY_HIGHEST < prio)
+ && THREAD_PRIORITY_HIGHEST < prio)
{
prio = THREAD_PRIORITY_HIGHEST;
}
#endif
- result = pthread_mutex_lock(&thread->threadLock);
+ result = pthread_mutex_lock (&thread->threadLock);
if (0 == result)
{
/* If this fails, the current priority is unchanged. */
- if (0 == SetThreadPriority(thread->threadH, prio))
- {
- result = EINVAL;
- }
+ if (0 == SetThreadPriority (thread->threadH, prio))
+ {
+ result = EINVAL;
+ }
else
- {
- /*
- * Must record the thread's sched_priority as given,
- * not as finally adjusted.
- */
- thread->sched_priority = priority;
- }
-
- (void) pthread_mutex_unlock(&thread->threadLock);
+ {
+ /*
+ * Must record the thread's sched_priority as given,
+ * not as finally adjusted.
+ */
+ thread->sched_priority = priority;
+ }
+
+ (void) pthread_mutex_unlock (&thread->threadLock);
}
return result;
diff --git a/pthread_setspecific.c b/pthread_setspecific.c
index 8003786..b7c82d0 100644
--- a/pthread_setspecific.c
+++ b/pthread_setspecific.c
@@ -44,13 +44,13 @@ pthread_setspecific (pthread_key_t key, const void *value)
* ------------------------------------------------------
* DOCPUBLIC
* This function sets the value of the thread specific
- * key in the calling thread.
+ * key in the calling thread.
*
* PARAMETERS
* key
* an instance of pthread_key_t
- * value
- * the value to set key to
+ * value
+ * the value to set key to
*
*
* DESCRIPTION
@@ -77,9 +77,9 @@ pthread_setspecific (pthread_key_t key, const void *value)
*/
self = pthread_self ();
if (self == NULL)
- {
- return ENOENT;
- }
+ {
+ return ENOENT;
+ }
}
else
{
@@ -89,9 +89,9 @@ pthread_setspecific (pthread_key_t key, const void *value)
*/
self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
if (self == NULL)
- {
- self = (pthread_t) value;
- }
+ {
+ self = (pthread_t) value;
+ }
}
result = 0;
@@ -100,52 +100,50 @@ pthread_setspecific (pthread_key_t key, const void *value)
{
ThreadKeyAssoc *assoc;
- if (self != NULL &&
- key->destructor != NULL &&
- value != NULL)
- {
- /*
- * Only require associations if we have to
- * call user destroy routine.
- * Don't need to locate an existing association
- * when setting data to NULL for WIN32 since the
- * data is stored with the operating system; not
- * on the association; setting assoc to NULL short
- * circuits the search.
- */
- assoc = (ThreadKeyAssoc *) self->keys;
- /*
- * Locate existing association
- */
- while (assoc != NULL)
- {
- if (assoc->key == key)
- {
- /*
- * Association already exists
- */
- break;
- }
- assoc = assoc->nextKey;
- }
+ if (self != NULL && key->destructor != NULL && value != NULL)
+ {
+ /*
+ * Only require associations if we have to
+ * call user destroy routine.
+ * Don't need to locate an existing association
+ * when setting data to NULL for WIN32 since the
+ * data is stored with the operating system; not
+ * on the association; setting assoc to NULL short
+ * circuits the search.
+ */
+ assoc = (ThreadKeyAssoc *) self->keys;
+ /*
+ * Locate existing association
+ */
+ while (assoc != NULL)
+ {
+ if (assoc->key == key)
+ {
+ /*
+ * Association already exists
+ */
+ break;
+ }
+ assoc = assoc->nextKey;
+ }
- /*
- * create an association if not found
- */
+ /*
+ * create an association if not found
+ */
if (assoc == NULL)
{
result = ptw32_tkAssocCreate (&assoc, self, key);
}
- }
+ }
if (result == 0)
- {
- if ( ! TlsSetValue (key->key, (LPVOID) value))
+ {
+ if (!TlsSetValue (key->key, (LPVOID) value))
{
result = EAGAIN;
}
- }
+ }
}
return (result);
-} /* pthread_setspecific */
+} /* pthread_setspecific */
diff --git a/pthread_spin_destroy.c b/pthread_spin_destroy.c
index bf32e6b..3347597 100644
--- a/pthread_spin_destroy.c
+++ b/pthread_spin_destroy.c
@@ -39,7 +39,7 @@
int
-pthread_spin_destroy(pthread_spinlock_t *lock)
+pthread_spin_destroy (pthread_spinlock_t * lock)
{
register pthread_spinlock_t s;
int result = 0;
@@ -52,16 +52,19 @@ pthread_spin_destroy(pthread_spinlock_t *lock)
if ((s = *lock) != PTHREAD_SPINLOCK_INITIALIZER)
{
if (s->interlock == PTW32_SPIN_USE_MUTEX)
- {
- result = pthread_mutex_destroy(&(s->u.mutex));
- }
- else if ( (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED !=
- ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock),
- (PTW32_INTERLOCKED_LONG) PTW32_OBJECT_INVALID,
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED))
- {
- result = EINVAL;
- }
+ {
+ result = pthread_mutex_destroy (&(s->u.mutex));
+ }
+ else if ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED !=
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG)
+ & (s->interlock),
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_OBJECT_INVALID,
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_UNLOCKED))
+ {
+ result = EINVAL;
+ }
if (0 == result)
{
@@ -70,7 +73,7 @@ pthread_spin_destroy(pthread_spinlock_t *lock)
* have finished with the spinlock before destroying it.
*/
*lock = NULL;
- (void) free(s);
+ (void) free (s);
}
}
else
@@ -78,32 +81,32 @@ pthread_spin_destroy(pthread_spinlock_t *lock)
/*
* See notes in ptw32_spinlock_check_need_init() above also.
*/
- EnterCriticalSection(&ptw32_spinlock_test_init_lock);
+ EnterCriticalSection (&ptw32_spinlock_test_init_lock);
/*
* Check again.
*/
if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
- {
- /*
- * This is all we need to do to destroy a statically
- * initialised spinlock that has not yet been used (initialised).
- * If we get to here, another thread
- * waiting to initialise this mutex will get an EINVAL.
- */
- *lock = NULL;
- }
+ {
+ /*
+ * This is all we need to do to destroy a statically
+ * initialised spinlock that has not yet been used (initialised).
+ * If we get to here, another thread
+ * waiting to initialise this mutex will get an EINVAL.
+ */
+ *lock = NULL;
+ }
else
- {
- /*
- * The spinlock has been initialised while we were waiting
- * so assume it's in use.
- */
- result = EBUSY;
- }
+ {
+ /*
+ * The spinlock has been initialised while we were waiting
+ * so assume it's in use.
+ */
+ result = EBUSY;
+ }
- LeaveCriticalSection(&ptw32_spinlock_test_init_lock);
+ LeaveCriticalSection (&ptw32_spinlock_test_init_lock);
}
- return(result);
+ return (result);
}
diff --git a/pthread_spin_init.c b/pthread_spin_init.c
index 3715825..d197ef7 100644
--- a/pthread_spin_init.c
+++ b/pthread_spin_init.c
@@ -39,7 +39,7 @@
int
-pthread_spin_init(pthread_spinlock_t *lock, int pshared)
+pthread_spin_init (pthread_spinlock_t * lock, int pshared)
{
pthread_spinlock_t s;
int cpus = 0;
@@ -50,7 +50,7 @@ pthread_spin_init(pthread_spinlock_t *lock, int pshared)
return EINVAL;
}
- if (0 != ptw32_getprocessors(&cpus))
+ if (0 != ptw32_getprocessors (&cpus))
{
cpus = 1;
}
@@ -58,29 +58,29 @@ pthread_spin_init(pthread_spinlock_t *lock, int pshared)
if (cpus > 1)
{
if (pshared == PTHREAD_PROCESS_SHARED)
- {
- /*
- * Creating spinlock that can be shared between
- * processes.
- */
+ {
+ /*
+ * Creating spinlock that can be shared between
+ * processes.
+ */
#if _POSIX_THREAD_PROCESS_SHARED
- /*
- * Not implemented yet.
- */
+ /*
+ * Not implemented yet.
+ */
#error ERROR [__FILE__, line __LINE__]: Process shared spin locks are not supported yet.
#else
- return ENOSYS;
+ return ENOSYS;
#endif /* _POSIX_THREAD_PROCESS_SHARED */
- }
+ }
}
- s = (pthread_spinlock_t) calloc(1, sizeof(*s));
+ s = (pthread_spinlock_t) calloc (1, sizeof (*s));
if (s == NULL)
{
@@ -95,18 +95,18 @@ pthread_spin_init(pthread_spinlock_t *lock, int pshared)
else
{
pthread_mutexattr_t ma;
- result = pthread_mutexattr_init(&ma);
+ result = pthread_mutexattr_init (&ma);
if (0 == result)
- {
- ma->pshared = pshared;
- result = pthread_mutex_init(&(s->u.mutex), &ma);
- if (0 == result)
- {
- s->interlock = PTW32_SPIN_USE_MUTEX;
- }
- }
- (void) pthread_mutexattr_destroy(&ma);
+ {
+ ma->pshared = pshared;
+ result = pthread_mutex_init (&(s->u.mutex), &ma);
+ if (0 == result)
+ {
+ s->interlock = PTW32_SPIN_USE_MUTEX;
+ }
+ }
+ (void) pthread_mutexattr_destroy (&ma);
}
if (0 == result)
@@ -115,9 +115,9 @@ pthread_spin_init(pthread_spinlock_t *lock, int pshared)
}
else
{
- (void) free(s);
+ (void) free (s);
*lock = NULL;
}
- return(result);
+ return (result);
}
diff --git a/pthread_spin_lock.c b/pthread_spin_lock.c
index eae835d..29c6a62 100644
--- a/pthread_spin_lock.c
+++ b/pthread_spin_lock.c
@@ -39,32 +39,36 @@
int
-pthread_spin_lock(pthread_spinlock_t *lock)
+pthread_spin_lock (pthread_spinlock_t * lock)
{
register pthread_spinlock_t s;
if (NULL == lock || NULL == *lock)
{
- return(EINVAL);
+ return (EINVAL);
}
if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
{
int result;
- if ((result = ptw32_spinlock_check_need_init(lock)) != 0)
- {
- return(result);
- }
+ if ((result = ptw32_spinlock_check_need_init (lock)) != 0)
+ {
+ return (result);
+ }
}
s = *lock;
- while ( (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED ==
- ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock),
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED,
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED) )
- {}
+ while ((PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED ==
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) &
+ (s->interlock),
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_LOCKED,
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_UNLOCKED))
+ {
+ }
if (s->interlock == PTW32_SPIN_LOCKED)
{
@@ -72,7 +76,7 @@ pthread_spin_lock(pthread_spinlock_t *lock)
}
else if (s->interlock == PTW32_SPIN_USE_MUTEX)
{
- return pthread_mutex_lock(&(s->u.mutex));
+ return pthread_mutex_lock (&(s->u.mutex));
}
return EINVAL;
diff --git a/pthread_spin_trylock.c b/pthread_spin_trylock.c
index c54fe53..040a2b0 100644
--- a/pthread_spin_trylock.c
+++ b/pthread_spin_trylock.c
@@ -39,34 +39,41 @@
int
-pthread_spin_trylock(pthread_spinlock_t *lock)
+pthread_spin_trylock (pthread_spinlock_t * lock)
{
register pthread_spinlock_t s;
if (NULL == lock || NULL == *lock)
{
- return(EINVAL);
+ return (EINVAL);
}
if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
{
int result;
- if ((result = ptw32_spinlock_check_need_init(lock)) != 0)
- {
- return(result);
- }
+ if ((result = ptw32_spinlock_check_need_init (lock)) != 0)
+ {
+ return (result);
+ }
}
s = *lock;
- switch ((long) ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock),
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED,
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED ))
+ switch ((long)
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) &
+ (s->interlock),
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_LOCKED,
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_UNLOCKED))
{
- case PTW32_SPIN_UNLOCKED: return 0;
- case PTW32_SPIN_LOCKED: return EBUSY;
- case PTW32_SPIN_USE_MUTEX: return pthread_mutex_trylock(&(s->u.mutex));
+ case PTW32_SPIN_UNLOCKED:
+ return 0;
+ case PTW32_SPIN_LOCKED:
+ return EBUSY;
+ case PTW32_SPIN_USE_MUTEX:
+ return pthread_mutex_trylock (&(s->u.mutex));
}
return EINVAL;
diff --git a/pthread_spin_unlock.c b/pthread_spin_unlock.c
index 42fb4a6..7b40f7f 100644
--- a/pthread_spin_unlock.c
+++ b/pthread_spin_unlock.c
@@ -39,13 +39,13 @@
int
-pthread_spin_unlock(pthread_spinlock_t *lock)
+pthread_spin_unlock (pthread_spinlock_t * lock)
{
register pthread_spinlock_t s;
if (NULL == lock || NULL == *lock)
{
- return(EINVAL);
+ return (EINVAL);
}
s = *lock;
@@ -55,13 +55,20 @@ pthread_spin_unlock(pthread_spinlock_t *lock)
return EPERM;
}
- switch ((long) ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock),
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED,
- (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED ))
+ switch ((long)
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) &
+ (s->interlock),
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_UNLOCKED,
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_LOCKED))
{
- case PTW32_SPIN_LOCKED: return 0;
- case PTW32_SPIN_UNLOCKED: return EPERM;
- case PTW32_SPIN_USE_MUTEX: return pthread_mutex_unlock(&(s->u.mutex));
+ case PTW32_SPIN_LOCKED:
+ return 0;
+ case PTW32_SPIN_UNLOCKED:
+ return EPERM;
+ case PTW32_SPIN_USE_MUTEX:
+ return pthread_mutex_unlock (&(s->u.mutex));
}
return EINVAL;
diff --git a/pthread_testcancel.c b/pthread_testcancel.c
index 9399267..04c214a 100644
--- a/pthread_testcancel.c
+++ b/pthread_testcancel.c
@@ -68,24 +68,22 @@ pthread_testcancel (void)
* ------------------------------------------------------
*/
{
- pthread_t self = pthread_self();
+ pthread_t self = pthread_self ();
- (void) pthread_mutex_lock(&self->cancelLock);
+ (void) pthread_mutex_lock (&self->cancelLock);
if (self != NULL
&& self->cancelState != PTHREAD_CANCEL_DISABLE
- && WaitForSingleObject (self->cancelEvent, 0) == WAIT_OBJECT_0
- )
+ && WaitForSingleObject (self->cancelEvent, 0) == WAIT_OBJECT_0)
{
/*
* Canceling!
*/
self->state = PThreadStateCanceling;
self->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock(&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ ptw32_throw (PTW32_EPS_CANCEL);
}
- (void) pthread_mutex_unlock(&self->cancelLock);
-} /* pthread_testcancel */
-
+ (void) pthread_mutex_unlock (&self->cancelLock);
+} /* pthread_testcancel */
diff --git a/pthread_timechange_handler_np.c b/pthread_timechange_handler_np.c
index eb7d281..f8b1d70 100644
--- a/pthread_timechange_handler_np.c
+++ b/pthread_timechange_handler_np.c
@@ -62,7 +62,7 @@
*/
void *
-pthread_timechange_handler_np(void * arg)
+pthread_timechange_handler_np (void *arg)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -82,8 +82,8 @@ pthread_timechange_handler_np(void * arg)
*
*
* RESULTS
- * 0 successfully broadcast all CVs
- * EAGAIN Not all CVs were broadcast
+ * 0 successfully broadcast all CVs
+ * EAGAIN Not all CVs were broadcast
*
* ------------------------------------------------------
*/
@@ -91,18 +91,17 @@ pthread_timechange_handler_np(void * arg)
int result = 0;
pthread_cond_t cv;
- EnterCriticalSection(&ptw32_cond_list_lock);
+ EnterCriticalSection (&ptw32_cond_list_lock);
cv = ptw32_cond_list_head;
while (cv != NULL && 0 == result)
{
- result = pthread_cond_broadcast(&cv);
+ result = pthread_cond_broadcast (&cv);
cv = cv->next;
}
- LeaveCriticalSection(&ptw32_cond_list_lock);
+ LeaveCriticalSection (&ptw32_cond_list_lock);
- return (void *)(result != 0 ? EAGAIN : 0);
+ return (void *) (result != 0 ? EAGAIN : 0);
}
-
diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c
index 3a6f854..ea0a307 100644
--- a/pthread_win32_attach_detach_np.c
+++ b/pthread_win32_attach_detach_np.c
@@ -34,6 +34,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+//#include "../QueueUserAPCEx/User/QueueUserAPCEx.h"
#include "pthread.h"
#include "implement.h"
@@ -42,6 +43,11 @@
*/
static HINSTANCE ptw32_h_kernel32;
+/*
+ * Handle to quserex.dll
+ */
+static HINSTANCE ptw32_h_quserex;
+
BOOL
pthread_win32_process_attach_np ()
{
@@ -52,21 +58,24 @@ pthread_win32_process_attach_np ()
pthread_count++;
#endif
+ ptw32_features = 0;
+
#ifndef TEST_ICE
/*
* Load KERNEL32 and try to get address of InterlockedCompareExchange
*/
- ptw32_h_kernel32 = LoadLibrary(TEXT("KERNEL32.DLL"));
+ ptw32_h_kernel32 = LoadLibrary (TEXT ("KERNEL32.DLL"));
ptw32_interlocked_compare_exchange =
- (PTW32_INTERLOCKED_LONG (WINAPI *)(PTW32_INTERLOCKED_LPLONG, PTW32_INTERLOCKED_LONG, PTW32_INTERLOCKED_LONG))
+ (PTW32_INTERLOCKED_LONG (WINAPI *)
+ (PTW32_INTERLOCKED_LPLONG, PTW32_INTERLOCKED_LONG,
+ PTW32_INTERLOCKED_LONG))
#if defined(NEED_UNICODE_CONSTS)
- GetProcAddress(ptw32_h_kernel32,
- (const TCHAR *)TEXT("InterlockedCompareExchange"));
+ GetProcAddress (ptw32_h_kernel32,
+ (const TCHAR *) TEXT ("InterlockedCompareExchange"));
#else
- GetProcAddress(ptw32_h_kernel32,
- (LPCSTR) "InterlockedCompareExchange");
+ GetProcAddress (ptw32_h_kernel32, (LPCSTR) "InterlockedCompareExchange");
#endif
if (ptw32_interlocked_compare_exchange == NULL)
@@ -87,9 +96,13 @@ pthread_win32_process_attach_np ()
* provide InterlockedCompareExchange, the bug will be
* effortlessly avoided.
*/
- (void) FreeLibrary(ptw32_h_kernel32);
+ (void) FreeLibrary (ptw32_h_kernel32);
ptw32_h_kernel32 = 0;
}
+ else
+ {
+ ptw32_features |= PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE;
+ }
#else /* TEST_ICE */
@@ -97,6 +110,59 @@ pthread_win32_process_attach_np ()
#endif /* TEST_ICE */
+ /*
+ * Load QUSEREX.DLL and try to get address of QueueUserAPCEx
+ */
+ ptw32_h_quserex = LoadLibrary (TEXT ("QUSEREX.DLL"));
+
+ if (ptw32_h_quserex != NULL)
+ {
+ ptw32_register_cancelation = (DWORD (*)(PAPCFUNC, HANDLE, DWORD))
+#if defined(NEED_UNICODE_CONSTS)
+ GetProcAddress (ptw32_h_quserex,
+ (const TCHAR *) TEXT ("QueueUserAPCEx"));
+#else
+ GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx");
+#endif
+ }
+
+ if (NULL == ptw32_register_cancelation)
+ {
+ ptw32_register_cancelation = ptw32_RegisterCancelation;
+
+ if (ptw32_h_quserex != NULL)
+ {
+ (void) FreeLibrary (ptw32_h_quserex);
+ }
+ ptw32_h_quserex = 0;
+ }
+ else
+ {
+ /* Initialise QueueUserAPCEx */
+ BOOL (*queue_user_apc_ex_init) (VOID);
+
+ queue_user_apc_ex_init = (BOOL (*)(VOID))
+#if defined(NEED_UNICODE_CONSTS)
+ GetProcAddress (ptw32_h_quserex,
+ (const TCHAR *) TEXT ("QueueUserAPCEx_Init"));
+#else
+ GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx_Init");
+#endif
+
+ if (queue_user_apc_ex_init == NULL || !queue_user_apc_ex_init ())
+ {
+ ptw32_register_cancelation = ptw32_RegisterCancelation;
+
+ (void) FreeLibrary (ptw32_h_quserex);
+ ptw32_h_quserex = 0;
+ }
+ }
+
+ if (ptw32_h_quserex)
+ {
+ ptw32_features |= PTW32_ALERTABLE_ASYNC_CANCEL;
+ }
+
return result;
}
@@ -112,22 +178,41 @@ pthread_win32_process_detach_np ()
* Detached threads have their resources automatically
* cleaned up upon exit (others must be 'joined').
*/
- if (self != NULL &&
- self->detachState == PTHREAD_CREATE_DETACHED)
- {
- ptw32_threadDestroy (self);
+ if (self != NULL && self->detachState == PTHREAD_CREATE_DETACHED)
+ {
+ ptw32_threadDestroy (self);
TlsSetValue (ptw32_selfThreadKey->key, NULL);
- }
+ }
/*
* The DLL is being unmapped from the process's address space
*/
ptw32_processTerminate ();
+ if (ptw32_h_quserex)
+ {
+ /* Close QueueUserAPCEx */
+ BOOL (*queue_user_apc_ex_fini) (VOID);
+
+ queue_user_apc_ex_fini = (BOOL (*)(VOID))
+#if defined(NEED_UNICODE_CONSTS)
+ GetProcAddress (ptw32_h_quserex,
+ (const TCHAR *) TEXT ("QueueUserAPCEx_Fini"));
+#else
+ GetProcAddress (ptw32_h_quserex, (LPCSTR) "QueueUserAPCEx_Fini");
+#endif
+
+ if (queue_user_apc_ex_fini != NULL)
+ {
+ (void) queue_user_apc_ex_fini ();
+ }
+ (void) FreeLibrary (ptw32_h_quserex);
+ }
+
if (ptw32_h_kernel32)
- {
- (void) FreeLibrary(ptw32_h_kernel32);
- }
+ {
+ (void) FreeLibrary (ptw32_h_kernel32);
+ }
}
return TRUE;
@@ -145,22 +230,27 @@ pthread_win32_thread_detach_np ()
if (ptw32_processInitialized)
{
/*
- * Don't use pthread_self() to avoid creating an implicit POSIX thread handle
+ * Don't use pthread_self() - to avoid creating an implicit POSIX thread handle
* unnecessarily.
*/
- pthread_t self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
-
- /*
- * Detached threads have their resources automatically
- * cleaned up upon exit (others must be 'joined').
- */
- if (self != NULL &&
- self->detachState == PTHREAD_CREATE_DETACHED)
- {
- ptw32_threadDestroy (self);
- TlsSetValue (ptw32_selfThreadKey->key, NULL);
- }
+ pthread_t self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
+
+ /*
+ * Detached threads have their resources automatically
+ * cleaned up upon exit (others must be 'joined').
+ */
+ if (self != NULL && self->detachState == PTHREAD_CREATE_DETACHED)
+ {
+ ptw32_threadDestroy (self);
+ TlsSetValue (ptw32_selfThreadKey->key, NULL);
+ }
}
return TRUE;
}
+
+BOOL
+pthread_win32_test_features_np (int feature_mask)
+{
+ return ((ptw32_features & feature_mask) == feature_mask);
+}
diff --git a/ptw32_InterlockedCompareExchange.c b/ptw32_InterlockedCompareExchange.c
index 7f996d5..0980710 100644
--- a/ptw32_InterlockedCompareExchange.c
+++ b/ptw32_InterlockedCompareExchange.c
@@ -50,30 +50,39 @@
* This can't be inlined because we need to know it's address so that
* we can call it through a pointer.
*/
+
PTW32_INTERLOCKED_LONG WINAPI
-ptw32_InterlockedCompareExchange(PTW32_INTERLOCKED_LPLONG location,
- PTW32_INTERLOCKED_LONG value,
- PTW32_INTERLOCKED_LONG comparand)
+ptw32_InterlockedCompareExchange (PTW32_INTERLOCKED_LPLONG location,
+ PTW32_INTERLOCKED_LONG value,
+ PTW32_INTERLOCKED_LONG comparand)
{
+
+#if defined(__WATCOMC__)
+/* Don't report that result is not assigned a value before being referenced */
+#pragma disable_message (200)
+#endif
+
PTW32_INTERLOCKED_LONG result;
+/* *INDENT-OFF* */
+
#if defined(_M_IX86) || defined(_X86_)
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__WATCOMC__)
_asm {
- PUSH ecx
- PUSH edx
- MOV ecx,dword ptr [location]
- MOV edx,dword ptr [value]
- MOV eax,dword ptr [comparand]
- LOCK CMPXCHG dword ptr [ecx],edx ; if (EAX == [ECX]),
- ; [ECX] = EDX
- ; else
- ; EAX = [ECX]
- MOV dword ptr [result], eax
- POP edx
- POP ecx
+ PUSH ecx
+ PUSH edx
+ MOV ecx,dword ptr [location]
+ MOV edx,dword ptr [value]
+ MOV eax,dword ptr [comparand]
+ LOCK CMPXCHG dword ptr [ecx],edx ; if (EAX == [ECX]),
+ ; [ECX] = EDX
+ ; else
+ ; EAX = [ECX]
+ MOV dword ptr [result], eax
+ POP edx
+ POP ecx
}
#elif defined(__GNUC__)
@@ -81,10 +90,10 @@ ptw32_InterlockedCompareExchange(PTW32_INTERLOCKED_LPLONG location,
__asm__
(
"lock\n\t"
- "cmpxchgl %3,(%0)" /* if (EAX == [location]), */
- /* [location] = value */
- /* else */
- /* EAX = [location] */
+ "cmpxchgl %3,(%0)" /* if (EAX == [location]), */
+ /* [location] = value */
+ /* else */
+ /* EAX = [location] */
:"=r" (location), "=a" (result)
:"0" (location), "q" (value), "a" (comparand)
: "memory" );
@@ -104,5 +113,12 @@ ptw32_InterlockedCompareExchange(PTW32_INTERLOCKED_LPLONG location,
#endif
+/* *INDENT-ON* */
+
return result;
+
+#if defined(__WATCOMC__)
+#pragma enable_message (200)
+#endif
+
}
diff --git a/ptw32_callUserDestroyRoutines.c b/ptw32_callUserDestroyRoutines.c
index 8f19be1..90b0b73 100644
--- a/ptw32_callUserDestroyRoutines.c
+++ b/ptw32_callUserDestroyRoutines.c
@@ -39,8 +39,9 @@
#include "implement.h"
#ifdef __cplusplus
-# if ! defined (_MSC_VER) && ! (defined(__GNUC__) && __GNUC__ < 3)
- using std::terminate;
+# if ! defined (_MSC_VER) && ! (defined(__GNUC__) && __GNUC__ < 3) && ! defined(__WATCOMC__)
+using
+ std::terminate;
# endif
#endif
@@ -55,16 +56,18 @@ ptw32_callUserDestroyRoutines (pthread_t thread)
* It simulates the behaviour of POSIX Threads.
*
* PARAMETERS
- * thread
- * an instance of pthread_t
+ * thread
+ * an instance of pthread_t
*
* RETURNS
- * N/A
+ * N/A
* -------------------------------------------------------------------
*/
{
- ThreadKeyAssoc **nextP;
- ThreadKeyAssoc *assoc;
+ ThreadKeyAssoc **
+ nextP;
+ ThreadKeyAssoc *
+ assoc;
if (thread != NULL)
{
@@ -87,7 +90,8 @@ ptw32_callUserDestroyRoutines (pthread_t thread)
if (pthread_mutex_lock (&(assoc->lock)) == 0)
{
- pthread_key_t k;
+ pthread_key_t
+ k;
if ((k = assoc->key) != NULL)
{
/*
@@ -97,7 +101,8 @@ ptw32_callUserDestroyRoutines (pthread_t thread)
* key is valid and we can call the destroy
* routine;
*/
- void *value = NULL;
+ void *
+ value = NULL;
value = pthread_getspecific (k);
if (value != NULL && k->destructor != NULL)
@@ -123,15 +128,15 @@ ptw32_callUserDestroyRoutines (pthread_t thread)
* should not get any internal pthreads
* exceptions.
*/
- terminate();
+ terminate ();
}
-#else /* __cplusplus */
+#else /* __cplusplus */
- /*
- * Run the caller's cleanup routine.
- */
- (*(k->destructor)) (value);
+ /*
+ * Run the caller's cleanup routine.
+ */
+ (*(k->destructor)) (value);
#endif /* __cplusplus */
}
diff --git a/ptw32_calloc.c b/ptw32_calloc.c
index 45aab88..b98df38 100644
--- a/ptw32_calloc.c
+++ b/ptw32_calloc.c
@@ -40,15 +40,17 @@
#ifdef NEED_CALLOC
void *
-ptw32_calloc(size_t n, size_t s) {
- unsigned int m = n*s;
- void *p;
-
- p = malloc(m);
- if (p == NULL) return NULL;
-
- memset(p, 0, m);
+ptw32_calloc (size_t n, size_t s)
+{
+ unsigned int m = n * s;
+ void *p;
- return p;
+ p = malloc (m);
+ if (p == NULL)
+ return NULL;
+
+ memset (p, 0, m);
+
+ return p;
}
#endif
diff --git a/ptw32_cond_check_need_init.c b/ptw32_cond_check_need_init.c
index 2f295c5..42b5a96 100644
--- a/ptw32_cond_check_need_init.c
+++ b/ptw32_cond_check_need_init.c
@@ -40,7 +40,7 @@
INLINE int
-ptw32_cond_check_need_init (pthread_cond_t *cond)
+ptw32_cond_check_need_init (pthread_cond_t * cond)
{
int result = 0;
@@ -65,7 +65,7 @@ ptw32_cond_check_need_init (pthread_cond_t *cond)
* the number of processors + 1.
*
*/
- EnterCriticalSection(&ptw32_cond_test_init_lock);
+ EnterCriticalSection (&ptw32_cond_test_init_lock);
/*
* We got here possibly under race
@@ -76,7 +76,7 @@ ptw32_cond_check_need_init (pthread_cond_t *cond)
*/
if (*cond == PTHREAD_COND_INITIALIZER)
{
- result = pthread_cond_init(cond, NULL);
+ result = pthread_cond_init (cond, NULL);
}
else if (*cond == NULL)
{
@@ -88,7 +88,7 @@ ptw32_cond_check_need_init (pthread_cond_t *cond)
result = EINVAL;
}
- LeaveCriticalSection(&ptw32_cond_test_init_lock);
+ LeaveCriticalSection (&ptw32_cond_test_init_lock);
return result;
}
diff --git a/ptw32_decrease_semaphore.c b/ptw32_decrease_semaphore.c
index 77c34ec..2dfe72d 100644
--- a/ptw32_decrease_semaphore.c
+++ b/ptw32_decrease_semaphore.c
@@ -49,26 +49,26 @@
#ifdef NEED_SEM
INLINE void
-ptw32_decrease_semaphore(sem_t * sem)
+ptw32_decrease_semaphore (sem_t * sem)
{
register sem_t s = *sem;
- EnterCriticalSection(&s->sem_lock_cs);
+ EnterCriticalSection (&s->sem_lock_cs);
if (s->value != 0)
{
s->value--;
if (s->value != 0)
- {
- SetEvent(s->event);
- }
+ {
+ SetEvent (s->event);
+ }
}
else
{
/* this case should not happen! */
}
- LeaveCriticalSection(&s->sem_lock_cs);
+ LeaveCriticalSection (&s->sem_lock_cs);
}
#endif /* NEED_SEM */
diff --git a/ptw32_getprocessors.c b/ptw32_getprocessors.c
index 01dfa3a..bfaa82d 100644
--- a/ptw32_getprocessors.c
+++ b/ptw32_getprocessors.c
@@ -53,15 +53,20 @@
* newly initialised spinlocks will notice.
*/
int
-ptw32_getprocessors(int * count)
+ptw32_getprocessors (int *count)
{
DWORD_PTR vProcessCPUs;
DWORD_PTR vSystemCPUs;
int result = 0;
- if (GetProcessAffinityMask(GetCurrentProcess(),
- &vProcessCPUs,
- &vSystemCPUs))
+#if defined(NEED_PROCESS_AFFINITY_MASK)
+
+ *count = 1;
+
+#else
+
+ if (GetProcessAffinityMask (GetCurrentProcess (),
+ &vProcessCPUs, &vSystemCPUs))
{
DWORD_PTR bit;
int CPUs = 0;
@@ -80,5 +85,7 @@ ptw32_getprocessors(int * count)
result = EAGAIN;
}
- return(result);
+#endif
+
+ return (result);
}
diff --git a/ptw32_increase_semaphore.c b/ptw32_increase_semaphore.c
index 9eafaed..a4a8e84 100644
--- a/ptw32_increase_semaphore.c
+++ b/ptw32_increase_semaphore.c
@@ -48,25 +48,25 @@
#ifdef NEED_SEM
INLINE BOOL
-ptw32_increase_semaphore(sem_t * sem, unsigned int n)
+ptw32_increase_semaphore (sem_t * sem, unsigned int n)
{
BOOL result;
register sem_t s = *sem;
- EnterCriticalSection(&s->sem_lock_cs);
+ EnterCriticalSection (&s->sem_lock_cs);
if (s->value + n > s->value)
{
- s->value += n;
- SetEvent(s->event);
- result = PTW32_TRUE;
+ s->value += n;
+ SetEvent (s->event);
+ result = PTW32_TRUE;
}
else
{
- result = PTW32_FALSE;
+ result = PTW32_FALSE;
}
- LeaveCriticalSection(&s->sem_lock_cs);
+ LeaveCriticalSection (&s->sem_lock_cs);
return result;
}
diff --git a/ptw32_is_attr.c b/ptw32_is_attr.c
index 19933c9..5179b81 100644
--- a/ptw32_is_attr.c
+++ b/ptw32_is_attr.c
@@ -38,12 +38,10 @@
#include "implement.h"
int
-ptw32_is_attr(const pthread_attr_t *attr)
+ptw32_is_attr (const pthread_attr_t * attr)
{
/* Return 0 if the attr object is valid, non-zero otherwise. */
return (attr == NULL ||
- *attr == NULL ||
- (*attr)->valid != PTW32_ATTR_VALID);
+ *attr == NULL || (*attr)->valid != PTW32_ATTR_VALID);
}
-
diff --git a/ptw32_mutex_check_need_init.c b/ptw32_mutex_check_need_init.c
index f20024f..bcaaf8b 100644
--- a/ptw32_mutex_check_need_init.c
+++ b/ptw32_mutex_check_need_init.c
@@ -39,7 +39,7 @@
INLINE int
-ptw32_mutex_check_need_init(pthread_mutex_t *mutex)
+ptw32_mutex_check_need_init (pthread_mutex_t * mutex)
{
int result = 0;
@@ -64,7 +64,7 @@ ptw32_mutex_check_need_init(pthread_mutex_t *mutex)
* the number of processors + 1.
*
*/
- EnterCriticalSection(&ptw32_mutex_test_init_lock);
+ EnterCriticalSection (&ptw32_mutex_test_init_lock);
/*
* We got here possibly under race
@@ -76,7 +76,7 @@ ptw32_mutex_check_need_init(pthread_mutex_t *mutex)
*/
if (*mutex == PTHREAD_MUTEX_INITIALIZER)
{
- result = pthread_mutex_init(mutex, NULL);
+ result = pthread_mutex_init (mutex, NULL);
}
else if (*mutex == NULL)
{
@@ -88,7 +88,7 @@ ptw32_mutex_check_need_init(pthread_mutex_t *mutex)
result = EINVAL;
}
- LeaveCriticalSection(&ptw32_mutex_test_init_lock);
+ LeaveCriticalSection (&ptw32_mutex_test_init_lock);
- return(result);
+ return (result);
}
diff --git a/ptw32_new.c b/ptw32_new.c
index dc1d8e9..c2da5d5 100644
--- a/ptw32_new.c
+++ b/ptw32_new.c
@@ -46,7 +46,7 @@ ptw32_new (void)
/*
* If there's a reusable pthread_t then use it.
*/
- t = ptw32_threadReusePop();
+ t = ptw32_threadReusePop ();
if (NULL == t)
{
@@ -56,23 +56,21 @@ ptw32_new (void)
if (t != NULL)
{
t->sched_priority = THREAD_PRIORITY_NORMAL;
- t->detachState = PTHREAD_CREATE_JOINABLE;
- t->cancelState = PTHREAD_CANCEL_ENABLE;
- t->cancelType = PTHREAD_CANCEL_DEFERRED;
- t->cancelLock = PTHREAD_MUTEX_INITIALIZER;
- t->threadLock = PTHREAD_MUTEX_INITIALIZER;
- t->cancelEvent = CreateEvent (
- 0,
- (int) PTW32_TRUE, /* manualReset */
- (int) PTW32_FALSE, /* setSignaled */
- NULL);
+ t->detachState = PTHREAD_CREATE_JOINABLE;
+ t->cancelState = PTHREAD_CANCEL_ENABLE;
+ t->cancelType = PTHREAD_CANCEL_DEFERRED;
+ t->cancelLock = PTHREAD_MUTEX_INITIALIZER;
+ t->threadLock = PTHREAD_MUTEX_INITIALIZER;
+ t->cancelEvent = CreateEvent (0, (int) PTW32_TRUE, /* manualReset */
+ (int) PTW32_FALSE, /* setSignaled */
+ NULL);
if (t->cancelEvent == NULL)
{
/*
* Thread ID structs are never freed.
*/
- ptw32_threadReusePush(t);
+ ptw32_threadReusePush (t);
t = NULL;
}
}
diff --git a/ptw32_processInitialize.c b/ptw32_processInitialize.c
index a8371ec..de74bc1 100644
--- a/ptw32_processInitialize.c
+++ b/ptw32_processInitialize.c
@@ -57,22 +57,23 @@ ptw32_processInitialize (void)
* ptw32_processInitialized to TRUE.
*
* RESULTS
- * TRUE if successful,
- * FALSE otherwise
+ * TRUE if successful,
+ * FALSE otherwise
*
* ------------------------------------------------------
*/
{
- if (ptw32_processInitialized) {
- /*
- * Ignore if already initialized. this is useful for
- * programs that uses a non-dll pthread
- * library. Such programs must call ptw32_processInitialize() explicitly,
- * since this initialization routine is automatically called only when
- * the dll is loaded.
- */
- return PTW32_TRUE;
- }
+ if (ptw32_processInitialized)
+ {
+ /*
+ * Ignore if already initialized. this is useful for
+ * programs that uses a non-dll pthread
+ * library. Such programs must call ptw32_processInitialize() explicitly,
+ * since this initialization routine is automatically called only when
+ * the dll is loaded.
+ */
+ return PTW32_TRUE;
+ }
ptw32_processInitialized = PTW32_TRUE;
@@ -89,12 +90,12 @@ ptw32_processInitialize (void)
/*
* Set up the global locks.
*/
- InitializeCriticalSection(&ptw32_thread_reuse_lock);
- InitializeCriticalSection(&ptw32_mutex_test_init_lock);
- InitializeCriticalSection(&ptw32_cond_list_lock);
- InitializeCriticalSection(&ptw32_cond_test_init_lock);
- InitializeCriticalSection(&ptw32_rwlock_test_init_lock);
- InitializeCriticalSection(&ptw32_spinlock_test_init_lock);
+ InitializeCriticalSection (&ptw32_thread_reuse_lock);
+ InitializeCriticalSection (&ptw32_mutex_test_init_lock);
+ InitializeCriticalSection (&ptw32_cond_list_lock);
+ InitializeCriticalSection (&ptw32_cond_test_init_lock);
+ InitializeCriticalSection (&ptw32_rwlock_test_init_lock);
+ InitializeCriticalSection (&ptw32_spinlock_test_init_lock);
return (ptw32_processInitialized);
diff --git a/ptw32_processTerminate.c b/ptw32_processTerminate.c
index 13c564d..13d73aa 100644
--- a/ptw32_processTerminate.c
+++ b/ptw32_processTerminate.c
@@ -57,13 +57,12 @@ ptw32_processTerminate (void)
* ptw32_processInitialized to FALSE
*
* RESULTS
- * N/A
+ * N/A
*
* ------------------------------------------------------
*/
{
- pthread_t thread,
- nextThread;
+ pthread_t thread, nextThread;
if (ptw32_processInitialized)
{
@@ -88,27 +87,27 @@ ptw32_processTerminate (void)
ptw32_cleanupKey = NULL;
}
- EnterCriticalSection(&ptw32_thread_reuse_lock);
+ EnterCriticalSection (&ptw32_thread_reuse_lock);
thread = ptw32_threadReuseTop;
while (thread != PTW32_THREAD_REUSE_BOTTOM)
- {
- nextThread = thread->prevReuse;
- free(thread);
- thread = nextThread;
- }
+ {
+ nextThread = thread->prevReuse;
+ free (thread);
+ thread = nextThread;
+ }
- LeaveCriticalSection(&ptw32_thread_reuse_lock);
+ LeaveCriticalSection (&ptw32_thread_reuse_lock);
/*
* Destroy the global locks.
*/
- DeleteCriticalSection(&ptw32_spinlock_test_init_lock);
- DeleteCriticalSection(&ptw32_rwlock_test_init_lock);
- DeleteCriticalSection(&ptw32_cond_test_init_lock);
- DeleteCriticalSection(&ptw32_cond_list_lock);
- DeleteCriticalSection(&ptw32_mutex_test_init_lock);
- DeleteCriticalSection(&ptw32_thread_reuse_lock);
+ DeleteCriticalSection (&ptw32_spinlock_test_init_lock);
+ DeleteCriticalSection (&ptw32_rwlock_test_init_lock);
+ DeleteCriticalSection (&ptw32_cond_test_init_lock);
+ DeleteCriticalSection (&ptw32_cond_list_lock);
+ DeleteCriticalSection (&ptw32_mutex_test_init_lock);
+ DeleteCriticalSection (&ptw32_thread_reuse_lock);
ptw32_processInitialized = PTW32_FALSE;
}
diff --git a/ptw32_reuse.c b/ptw32_reuse.c
index b407b82..a21737a 100644
--- a/ptw32_reuse.c
+++ b/ptw32_reuse.c
@@ -53,7 +53,7 @@ ptw32_threadReusePop (void)
{
pthread_t t;
- EnterCriticalSection(&ptw32_thread_reuse_lock);
+ EnterCriticalSection (&ptw32_thread_reuse_lock);
t = ptw32_threadReuseTop;
@@ -67,7 +67,7 @@ ptw32_threadReusePop (void)
t = NULL;
}
- LeaveCriticalSection(&ptw32_thread_reuse_lock);
+ LeaveCriticalSection (&ptw32_thread_reuse_lock);
return t;
@@ -79,12 +79,11 @@ ptw32_threadReusePop (void)
void
ptw32_threadReusePush (pthread_t thread)
{
- EnterCriticalSection(&ptw32_thread_reuse_lock);
+ EnterCriticalSection (&ptw32_thread_reuse_lock);
- memset(thread, 0, sizeof (*thread));
+ memset (thread, 0, sizeof (*thread));
thread->prevReuse = ptw32_threadReuseTop;
ptw32_threadReuseTop = thread;
- LeaveCriticalSection(&ptw32_thread_reuse_lock);
+ LeaveCriticalSection (&ptw32_thread_reuse_lock);
}
-
diff --git a/ptw32_rwlock_cancelwrwait.c b/ptw32_rwlock_cancelwrwait.c
index 7723a64..6b2456e 100644
--- a/ptw32_rwlock_cancelwrwait.c
+++ b/ptw32_rwlock_cancelwrwait.c
@@ -38,13 +38,13 @@
#include "implement.h"
void
-ptw32_rwlock_cancelwrwait(void * arg)
+ptw32_rwlock_cancelwrwait (void *arg)
{
- pthread_rwlock_t rwl = (pthread_rwlock_t) arg;
+ pthread_rwlock_t rwl = (pthread_rwlock_t) arg;
- rwl->nSharedAccessCount = -rwl->nCompletedSharedAccessCount;
- rwl->nCompletedSharedAccessCount = 0;
+ rwl->nSharedAccessCount = -rwl->nCompletedSharedAccessCount;
+ rwl->nCompletedSharedAccessCount = 0;
- (void) pthread_mutex_unlock(&(rwl->mtxSharedAccessCompleted));
- (void) pthread_mutex_unlock(&(rwl->mtxExclusiveAccess));
+ (void) pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
+ (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
}
diff --git a/ptw32_rwlock_check_need_init.c b/ptw32_rwlock_check_need_init.c
index 034ce7d..472af4e 100644
--- a/ptw32_rwlock_check_need_init.c
+++ b/ptw32_rwlock_check_need_init.c
@@ -38,7 +38,7 @@
#include "implement.h"
INLINE int
-ptw32_rwlock_check_need_init(pthread_rwlock_t *rwlock)
+ptw32_rwlock_check_need_init (pthread_rwlock_t * rwlock)
{
int result = 0;
@@ -63,7 +63,7 @@ ptw32_rwlock_check_need_init(pthread_rwlock_t *rwlock)
* the number of processors + 1.
*
*/
- EnterCriticalSection(&ptw32_rwlock_test_init_lock);
+ EnterCriticalSection (&ptw32_rwlock_test_init_lock);
/*
* We got here possibly under race
@@ -75,7 +75,7 @@ ptw32_rwlock_check_need_init(pthread_rwlock_t *rwlock)
*/
if (*rwlock == PTHREAD_RWLOCK_INITIALIZER)
{
- result = pthread_rwlock_init(rwlock, NULL);
+ result = pthread_rwlock_init (rwlock, NULL);
}
else if (*rwlock == NULL)
{
@@ -87,7 +87,7 @@ ptw32_rwlock_check_need_init(pthread_rwlock_t *rwlock)
result = EINVAL;
}
- LeaveCriticalSection(&ptw32_rwlock_test_init_lock);
+ LeaveCriticalSection (&ptw32_rwlock_test_init_lock);
return result;
}
diff --git a/ptw32_spinlock_check_need_init.c b/ptw32_spinlock_check_need_init.c
index f77a214..c4a651f 100644
--- a/ptw32_spinlock_check_need_init.c
+++ b/ptw32_spinlock_check_need_init.c
@@ -39,7 +39,7 @@
INLINE int
-ptw32_spinlock_check_need_init(pthread_spinlock_t *lock)
+ptw32_spinlock_check_need_init (pthread_spinlock_t * lock)
{
int result = 0;
@@ -51,7 +51,7 @@ ptw32_spinlock_check_need_init(pthread_spinlock_t *lock)
* introducing race conditions into applications which are
* correctly written.
*/
- EnterCriticalSection(&ptw32_spinlock_test_init_lock);
+ EnterCriticalSection (&ptw32_spinlock_test_init_lock);
/*
* We got here possibly under race
@@ -63,7 +63,7 @@ ptw32_spinlock_check_need_init(pthread_spinlock_t *lock)
*/
if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
{
- result = pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE);
+ result = pthread_spin_init (lock, PTHREAD_PROCESS_PRIVATE);
}
else if (*lock == NULL)
{
@@ -75,7 +75,7 @@ ptw32_spinlock_check_need_init(pthread_spinlock_t *lock)
result = EINVAL;
}
- LeaveCriticalSection(&ptw32_spinlock_test_init_lock);
+ LeaveCriticalSection (&ptw32_spinlock_test_init_lock);
- return(result);
+ return (result);
}
diff --git a/ptw32_threadDestroy.c b/ptw32_threadDestroy.c
index be6542a..9432e2e 100644
--- a/ptw32_threadDestroy.c
+++ b/ptw32_threadDestroy.c
@@ -46,22 +46,22 @@ ptw32_threadDestroy (pthread_t thread)
if (thread != NULL)
{
- (void) pthread_mutex_lock(&thread->cancelLock);
+ (void) pthread_mutex_lock (&thread->cancelLock);
thread->state = PThreadStateLast;
- (void) pthread_mutex_unlock(&thread->cancelLock);
+ (void) pthread_mutex_unlock (&thread->cancelLock);
ptw32_callUserDestroyRoutines (thread);
/*
* Copy thread state so that the thread can be atomically NULLed.
*/
- memcpy(&threadCopy, thread, sizeof(threadCopy));
+ memcpy (&threadCopy, thread, sizeof (threadCopy));
/*
* Thread ID structs are never freed. They're NULLed and reused.
* This also sets the thread to PThreadStateInitial (invalid).
*/
- ptw32_threadReusePush(thread);
+ ptw32_threadReusePush (thread);
/* Now work on the copy. */
if (threadCopy.cancelEvent != NULL)
@@ -78,13 +78,12 @@ ptw32_threadDestroy (pthread_t thread)
* Don't close the Win32 handle of implicit POSIX threads
* because the process may want to call GetExitCodeThread().
*/
- if( threadCopy.threadH != 0 && ! threadCopy.implicit )
+ if (threadCopy.threadH != 0 && !threadCopy.implicit)
{
- CloseHandle( threadCopy.threadH );
+ CloseHandle (threadCopy.threadH);
}
#endif
}
} /* ptw32_threadDestroy */
-
diff --git a/ptw32_threadStart.c b/ptw32_threadStart.c
index d031241..4bc0b19 100644
--- a/ptw32_threadStart.c
+++ b/ptw32_threadStart.c
@@ -38,7 +38,6 @@
#include "pthread.h"
#include "implement.h"
-
#ifdef __CLEANUP_SEH
static DWORD
@@ -46,36 +45,36 @@ ExceptionFilter (EXCEPTION_POINTERS * ep, DWORD * ei)
{
switch (ep->ExceptionRecord->ExceptionCode)
{
- case EXCEPTION_PTW32_SERVICES:
- {
- DWORD param;
- DWORD numParams = ep->ExceptionRecord->NumberParameters;
+ case EXCEPTION_PTW32_SERVICES:
+ {
+ DWORD param;
+ DWORD numParams = ep->ExceptionRecord->NumberParameters;
- numParams = (numParams > 3) ? 3 : numParams;
+ numParams = (numParams > 3) ? 3 : numParams;
- for (param = 0; param < numParams; param++)
- {
- ei[param] = ep->ExceptionRecord->ExceptionInformation[param];
- }
+ for (param = 0; param < numParams; param++)
+ {
+ ei[param] = ep->ExceptionRecord->ExceptionInformation[param];
+ }
- return EXCEPTION_EXECUTE_HANDLER;
- break;
- }
- default:
- {
- /*
- * A system unexpected exception has occurred running the user's
- * routine. We need to cleanup before letting the exception
- * out of thread scope.
- */
- pthread_t self = pthread_self();
+ return EXCEPTION_EXECUTE_HANDLER;
+ break;
+ }
+ default:
+ {
+ /*
+ * A system unexpected exception has occurred running the user's
+ * routine. We need to cleanup before letting the exception
+ * out of thread scope.
+ */
+ pthread_t self = pthread_self ();
- (void) pthread_mutex_destroy(&self->cancelLock);
- ptw32_callUserDestroyRoutines(self);
+ (void) pthread_mutex_destroy (&self->cancelLock);
+ ptw32_callUserDestroyRoutines (self);
- return EXCEPTION_CONTINUE_SEARCH;
- break;
- }
+ return EXCEPTION_CONTINUE_SEARCH;
+ break;
+ }
}
}
@@ -83,53 +82,71 @@ ExceptionFilter (EXCEPTION_POINTERS * ep, DWORD * ei)
#if defined(_MSC_VER)
# include <eh.h>
+#elif defined(__WATCOMC__)
+# include <eh.h>
+# include <exceptio.h>
+typedef terminate_handler
+ terminate_function;
#else
# if defined(__GNUC__) && __GNUC__ < 3
# include <new.h>
# else
# include <new>
- using std::terminate_handler;
- using std::terminate;
- using std::set_terminate;
+using
+ std::terminate_handler;
+using
+ std::terminate;
+using
+ std::set_terminate;
# endif
- typedef terminate_handler terminate_function;
+typedef terminate_handler
+ terminate_function;
#endif
-static terminate_function ptw32_oldTerminate;
+static terminate_function
+ ptw32_oldTerminate;
void
ptw32_terminate ()
{
- pthread_t self = pthread_self();
- set_terminate(ptw32_oldTerminate);
- (void) pthread_mutex_destroy(&self->cancelLock);
- ptw32_callUserDestroyRoutines(self);
- terminate();
+ pthread_t
+ self = pthread_self ();
+ set_terminate (ptw32_oldTerminate);
+ (void) pthread_mutex_destroy (&self->cancelLock);
+ ptw32_callUserDestroyRoutines (self);
+ terminate ();
}
#endif
#if ! defined (__MINGW32__) || defined (__MSVCRT__)
-unsigned __stdcall
+unsigned
+ __stdcall
#else
void
#endif
-ptw32_threadStart (void * vthreadParms)
+ptw32_threadStart (void *vthreadParms)
{
- ThreadParms *threadParms = (ThreadParms *) vthreadParms;
- pthread_t self;
+ ThreadParms *
+ threadParms = (ThreadParms *) vthreadParms;
+ pthread_t
+ self;
void *(*start) (void *);
- void *arg;
+ void *
+ arg;
#ifdef __CLEANUP_SEH
- DWORD ei[] = {0,0,0};
+ DWORD
+ ei[] = { 0, 0, 0 };
#endif
#ifdef __CLEANUP_C
- int setjmp_rc;
+ int
+ setjmp_rc;
#endif
- void * status = (void *) 0;
+ void *
+ status = (void *) 0;
self = threadParms->tid;
start = threadParms->start;
@@ -148,9 +165,9 @@ ptw32_threadStart (void * vthreadParms)
* to make the new thread wait until the creating thread
* has the new handle.
*/
- if (pthread_mutex_lock(&self->cancelLock) == 0)
+ if (pthread_mutex_lock (&self->cancelLock) == 0)
{
- (void) pthread_mutex_unlock(&self->cancelLock);
+ (void) pthread_mutex_unlock (&self->cancelLock);
}
#endif
@@ -168,49 +185,50 @@ ptw32_threadStart (void * vthreadParms)
status = self->exitStatus = (*start) (arg);
#ifdef _UWIN
- if (--pthread_count <= 0)
- exit(0);
+ if (--pthread_count <= 0)
+ exit (0);
#endif
}
- __except (ExceptionFilter(GetExceptionInformation(), ei))
+ __except (ExceptionFilter (GetExceptionInformation (), ei))
{
- switch (ei[0])
- {
- case PTW32_EPS_CANCEL:
- status = PTHREAD_CANCELED;
+ switch (ei[0])
+ {
+ case PTW32_EPS_CANCEL:
+ status = PTHREAD_CANCELED;
#ifdef _UWIN
- if (--pthread_count <= 0)
- exit(0);
+ if (--pthread_count <= 0)
+ exit (0);
#endif
- break;
- case PTW32_EPS_EXIT:
- status = self->exitStatus;
- break;
- default:
- status = PTHREAD_CANCELED;
- break;
- }
+ break;
+ case PTW32_EPS_EXIT:
+ status = self->exitStatus;
+ break;
+ default:
+ status = PTHREAD_CANCELED;
+ break;
+ }
}
#else /* __CLEANUP_SEH */
#ifdef __CLEANUP_C
- setjmp_rc = setjmp( self->start_mark );
-
- if( 0 == setjmp_rc ) {
+ setjmp_rc = setjmp (self->start_mark);
- /*
- * Run the caller's routine;
- */
- status = self->exitStatus = (*start) (arg);
- }
+ if (0 == setjmp_rc)
+ {
- else {
+ /*
+ * Run the caller's routine;
+ */
+ status = self->exitStatus = (*start) (arg);
+ }
- switch (setjmp_rc)
- {
+ else
+ {
+ switch (setjmp_rc)
+ {
case PTW32_EPS_CANCEL:
status = PTHREAD_CANCELED;
break;
@@ -220,14 +238,14 @@ ptw32_threadStart (void * vthreadParms)
default:
status = PTHREAD_CANCELED;
break;
- }
- }
+ }
+ }
#else /* __CLEANUP_C */
#ifdef __CLEANUP_CXX
- ptw32_oldTerminate = set_terminate(&ptw32_terminate);
+ ptw32_oldTerminate = set_terminate (&ptw32_terminate);
try
{
@@ -237,73 +255,75 @@ ptw32_threadStart (void * vthreadParms)
* pthread_exit() or be canceled.
*/
try
- {
- status = self->exitStatus = (*start) (arg);
- }
- catch (ptw32_exception &)
- {
- /*
- * Pass these through to the outer block.
- */
- throw;
- }
- catch(...)
- {
- /*
- * We want to run the user's terminate function if supplied.
- * That function may call pthread_exit() or be canceled, which will
- * be handled by the outer try block.
- *
- * ptw32_terminate() will be called if there is no user
- * supplied function.
- */
-
- terminate_function term_func = set_terminate(0);
- set_terminate(term_func);
-
- if (term_func != 0) {
- term_func();
- }
-
- throw;
- }
- }
- catch (ptw32_exception_cancel &)
{
- /*
- * Thread was canceled.
- */
- status = self->exitStatus = PTHREAD_CANCELED;
+ status = self->exitStatus = (*start) (arg);
}
- catch (ptw32_exception_exit &)
+ catch (ptw32_exception &)
{
/*
- * Thread was exited via pthread_exit().
+ * Pass these through to the outer block.
*/
- status = self->exitStatus;
+ throw;
}
- catch (...)
+ catch (...)
{
/*
- * A system unexpected exception has occurred running the user's
- * terminate routine. We get control back within this block - cleanup
- * and release the exception out of thread scope.
+ * We want to run the user's terminate function if supplied.
+ * That function may call pthread_exit() or be canceled, which will
+ * be handled by the outer try block.
+ *
+ * ptw32_terminate() will be called if there is no user
+ * supplied function.
*/
- status = self->exitStatus = PTHREAD_CANCELED;
- (void) pthread_mutex_lock(&self->cancelLock);
- self->state = PThreadStateException;
- (void) pthread_mutex_unlock(&self->cancelLock);
- (void) pthread_mutex_destroy(&self->cancelLock);
- (void) set_terminate(ptw32_oldTerminate);
- ptw32_callUserDestroyRoutines(self);
- throw;
- /*
- * Never reached.
- */
+ terminate_function
+ term_func = set_terminate (0);
+ set_terminate (term_func);
+
+ if (term_func != 0)
+ {
+ term_func ();
+ }
+
+ throw;
}
+ }
+ catch (ptw32_exception_cancel &)
+ {
+ /*
+ * Thread was canceled.
+ */
+ status = self->exitStatus = PTHREAD_CANCELED;
+ }
+ catch (ptw32_exception_exit &)
+ {
+ /*
+ * Thread was exited via pthread_exit().
+ */
+ status = self->exitStatus;
+ }
+ catch (...)
+ {
+ /*
+ * A system unexpected exception has occurred running the user's
+ * terminate routine. We get control back within this block - cleanup
+ * and release the exception out of thread scope.
+ */
+ status = self->exitStatus = PTHREAD_CANCELED;
+ (void) pthread_mutex_lock (&self->cancelLock);
+ self->state = PThreadStateException;
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ (void) pthread_mutex_destroy (&self->cancelLock);
+ (void) set_terminate (ptw32_oldTerminate);
+ ptw32_callUserDestroyRoutines (self);
+ throw;
+
+ /*
+ * Never reached.
+ */
+ }
- (void) set_terminate(ptw32_oldTerminate);
+ (void) set_terminate (ptw32_oldTerminate);
#else
diff --git a/ptw32_throw.c b/ptw32_throw.c
index 20bfcf5..17d610d 100644
--- a/ptw32_throw.c
+++ b/ptw32_throw.c
@@ -47,7 +47,7 @@
* C++, and SEH).
*/
void
-ptw32_throw(DWORD exception)
+ptw32_throw (DWORD exception)
{
/*
* Don't use pthread_self() to avoid creating an implicit POSIX thread handle
@@ -59,11 +59,10 @@ ptw32_throw(DWORD exception)
DWORD exceptionInformation[3];
#endif
- if (exception != PTW32_EPS_CANCEL &&
- exception != PTW32_EPS_EXIT)
+ if (exception != PTW32_EPS_CANCEL && exception != PTW32_EPS_EXIT)
{
/* Should never enter here */
- exit(1);
+ exit (1);
}
if (NULL == self || self->implicit)
@@ -86,7 +85,7 @@ ptw32_throw(DWORD exception)
break;
}
- pthread_win32_thread_detach_np();
+ pthread_win32_thread_detach_np ();
#if ! defined (__MINGW32__) || defined (__MSVCRT__)
_endthreadex (exitCode);
@@ -103,19 +102,14 @@ ptw32_throw(DWORD exception)
exceptionInformation[1] = (DWORD) (0);
exceptionInformation[2] = (DWORD) (0);
- RaiseException (
- EXCEPTION_PTW32_SERVICES,
- 0,
- 3,
- exceptionInformation);
+ RaiseException (EXCEPTION_PTW32_SERVICES, 0, 3, exceptionInformation);
#else /* __CLEANUP_SEH */
#ifdef __CLEANUP_C
- ptw32_pop_cleanup_all( 1 );
-
- longjmp( self->start_mark, exception );
+ ptw32_pop_cleanup_all (1);
+ longjmp (self->start_mark, exception);
#else /* __CLEANUP_C */
@@ -124,10 +118,10 @@ ptw32_throw(DWORD exception)
switch (exception)
{
case PTW32_EPS_CANCEL:
- throw ptw32_exception_cancel();
+ throw ptw32_exception_cancel ();
break;
case PTW32_EPS_EXIT:
- throw ptw32_exception_exit();
+ throw ptw32_exception_exit ();
break;
}
@@ -146,15 +140,16 @@ ptw32_throw(DWORD exception)
void
-ptw32_pop_cleanup_all(int execute)
+ptw32_pop_cleanup_all (int execute)
{
- while( NULL != ptw32_pop_cleanup(execute) ) {
- }
+ while (NULL != ptw32_pop_cleanup (execute))
+ {
+ }
}
DWORD
-ptw32_get_exception_services_code(void)
+ptw32_get_exception_services_code (void)
{
#ifdef __CLEANUP_SEH
diff --git a/ptw32_timespec.c b/ptw32_timespec.c
index aa1640a..cad3327 100644
--- a/ptw32_timespec.c
+++ b/ptw32_timespec.c
@@ -48,7 +48,7 @@
( ((LONGLONG) 27111902 << 32) + (LONGLONG) 3577643008 )
INLINE void
-ptw32_timespec_to_filetime(const struct timespec *ts, FILETIME *ft)
+ptw32_timespec_to_filetime (const struct timespec *ts, FILETIME * ft)
/*
* -------------------------------------------------------------------
* converts struct timespec
@@ -58,13 +58,12 @@ ptw32_timespec_to_filetime(const struct timespec *ts, FILETIME *ft)
* -------------------------------------------------------------------
*/
{
- *(LONGLONG *)ft = ts->tv_sec * 10000000
- + (ts->tv_nsec + 50) / 100
- + PTW32_TIMESPEC_TO_FILETIME_OFFSET;
+ *(LONGLONG *) ft = ts->tv_sec * 10000000
+ + (ts->tv_nsec + 50) / 100 + PTW32_TIMESPEC_TO_FILETIME_OFFSET;
}
INLINE void
-ptw32_filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
+ptw32_filetime_to_timespec (const FILETIME * ft, struct timespec *ts)
/*
* -------------------------------------------------------------------
* converts FILETIME (as set by GetSystemTimeAsFileTime), where the time is
@@ -74,8 +73,11 @@ ptw32_filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
* -------------------------------------------------------------------
*/
{
- ts->tv_sec = (int)((*(LONGLONG *)ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET) / 10000000);
- ts->tv_nsec = (int)((*(LONGLONG *)ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET - ((LONGLONG)ts->tv_sec * (LONGLONG)10000000)) * 100);
+ ts->tv_sec =
+ (int) ((*(LONGLONG *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET) / 10000000);
+ ts->tv_nsec =
+ (int) ((*(LONGLONG *) ft - PTW32_TIMESPEC_TO_FILETIME_OFFSET -
+ ((LONGLONG) ts->tv_sec * (LONGLONG) 10000000)) * 100);
}
#endif /* NEED_FTIME */
diff --git a/ptw32_tkAssocCreate.c b/ptw32_tkAssocCreate.c
index c6f38a6..c2a5c81 100644
--- a/ptw32_tkAssocCreate.c
+++ b/ptw32_tkAssocCreate.c
@@ -41,8 +41,7 @@
int
ptw32_tkAssocCreate (ThreadKeyAssoc ** assocP,
- pthread_t thread,
- pthread_key_t key)
+ pthread_t thread, pthread_key_t key)
/*
* -------------------------------------------------------------------
* This routine creates an association that
@@ -56,25 +55,25 @@ ptw32_tkAssocCreate (ThreadKeyAssoc ** assocP,
*
* Notes:
* 1) New associations are pushed to the beginning of the
- * chain so that the internal ptw32_selfThreadKey association
- * is always last, thus allowing selfThreadExit to
- * be implicitly called by pthread_exit last.
+ * chain so that the internal ptw32_selfThreadKey association
+ * is always last, thus allowing selfThreadExit to
+ * be implicitly called by pthread_exit last.
*
* Parameters:
- * assocP
- * address into which the association is returned.
- * thread
- * current running thread. If NULL, then association
- * is only added to the key. A NULL thread indicates
- * that the user called pthread_setspecific prior
- * to starting a thread. That's ok.
- * key
- * key on which to create an association.
+ * assocP
+ * address into which the association is returned.
+ * thread
+ * current running thread. If NULL, then association
+ * is only added to the key. A NULL thread indicates
+ * that the user called pthread_setspecific prior
+ * to starting a thread. That's ok.
+ * key
+ * key on which to create an association.
* Returns:
- * 0 - if successful,
- * ENOMEM - not enough memory to create assoc or other object
- * EINVAL - an internal error occurred
- * ENOSYS - an internal error occurred
+ * 0 - if successful,
+ * ENOMEM - not enough memory to create assoc or other object
+ * EINVAL - an internal error occurred
+ * ENOSYS - an internal error occurred
* -------------------------------------------------------------------
*/
{
diff --git a/ptw32_tkAssocDestroy.c b/ptw32_tkAssocDestroy.c
index 0daa434..682b896 100644
--- a/ptw32_tkAssocDestroy.c
+++ b/ptw32_tkAssocDestroy.c
@@ -48,16 +48,15 @@ ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc)
* ie) both the key and thread have stopped referencing it.
*
* Parameters:
- * assoc
- * an instance of ThreadKeyAssoc.
+ * assoc
+ * an instance of ThreadKeyAssoc.
* Returns:
* N/A
* -------------------------------------------------------------------
*/
{
- if ((assoc != NULL) &&
- (assoc->key == NULL && assoc->thread == NULL))
+ if ((assoc != NULL) && (assoc->key == NULL && assoc->thread == NULL))
{
pthread_mutex_destroy (&(assoc->lock));
diff --git a/sched_get_priority_max.c b/sched_get_priority_max.c
index c3fb715..f9f365a 100644
--- a/sched_get_priority_max.c
+++ b/sched_get_priority_max.c
@@ -116,7 +116,7 @@
int
-sched_get_priority_max(int policy)
+sched_get_priority_max (int policy)
{
if (policy < SCHED_MIN || policy > SCHED_MAX)
{
@@ -126,9 +126,9 @@ sched_get_priority_max(int policy)
#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
/* WinCE? */
- return PTW32_MAX(THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
+ return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
#else
/* This is independent of scheduling policy in Win32. */
- return PTW32_MAX(THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
+ return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
#endif
}
diff --git a/sched_get_priority_min.c b/sched_get_priority_min.c
index 5c88137..1051f67 100644
--- a/sched_get_priority_min.c
+++ b/sched_get_priority_min.c
@@ -117,7 +117,7 @@
int
-sched_get_priority_min(int policy)
+sched_get_priority_min (int policy)
{
if (policy < SCHED_MIN || policy > SCHED_MAX)
{
@@ -127,9 +127,9 @@ sched_get_priority_min(int policy)
#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
/* WinCE? */
- return PTW32_MIN(THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
+ return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
#else
/* This is independent of scheduling policy in Win32. */
- return PTW32_MIN(THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
+ return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
#endif
}
diff --git a/sched_getscheduler.c b/sched_getscheduler.c
index 5e7728a..144dec5 100644
--- a/sched_getscheduler.c
+++ b/sched_getscheduler.c
@@ -39,7 +39,7 @@
#include "sched.h"
int
-sched_getscheduler(pid_t pid)
+sched_getscheduler (pid_t pid)
{
/*
* Win32 only has one policy which we call SCHED_OTHER.
@@ -48,18 +48,21 @@ sched_getscheduler(pid_t pid)
*/
if (0 != pid)
{
- int selfPid = (int) GetCurrentProcessId();
+ int selfPid = (int) GetCurrentProcessId ();
if (pid != selfPid)
- {
- HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, PTW32_FALSE, (DWORD) pid);
+ {
+ HANDLE h =
+ OpenProcess (PROCESS_QUERY_INFORMATION, PTW32_FALSE, (DWORD) pid);
- if (NULL == h)
- {
- errno = (GetLastError() == (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH;
- return -1;
- }
- }
+ if (NULL == h)
+ {
+ errno =
+ (GetLastError () ==
+ (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH;
+ return -1;
+ }
+ }
}
return SCHED_OTHER;
diff --git a/sched_setscheduler.c b/sched_setscheduler.c
index 47564d5..138ad94 100644
--- a/sched_setscheduler.c
+++ b/sched_setscheduler.c
@@ -39,7 +39,7 @@
#include "sched.h"
int
-sched_setscheduler(pid_t pid, int policy)
+sched_setscheduler (pid_t pid, int policy)
{
/*
* Win32 only has one policy which we call SCHED_OTHER.
@@ -50,18 +50,21 @@ sched_setscheduler(pid_t pid, int policy)
*/
if (0 != pid)
{
- int selfPid = (int) GetCurrentProcessId();
+ int selfPid = (int) GetCurrentProcessId ();
if (pid != selfPid)
- {
- HANDLE h = OpenProcess(PROCESS_SET_INFORMATION, PTW32_FALSE, (DWORD) pid);
+ {
+ HANDLE h =
+ OpenProcess (PROCESS_SET_INFORMATION, PTW32_FALSE, (DWORD) pid);
- if (NULL == h)
- {
- errno = (GetLastError() == (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH;
- return -1;
- }
- }
+ if (NULL == h)
+ {
+ errno =
+ (GetLastError () ==
+ (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH;
+ return -1;
+ }
+ }
}
if (SCHED_OTHER != policy)
diff --git a/sched_yield.c b/sched_yield.c
index 36ab705..a750ea7 100644
--- a/sched_yield.c
+++ b/sched_yield.c
@@ -39,7 +39,7 @@
#include "sched.h"
int
-sched_yield(void)
+sched_yield (void)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -65,7 +65,7 @@ sched_yield(void)
* ------------------------------------------------------
*/
{
- Sleep(0);
+ Sleep (0);
return 0;
}
diff --git a/sem_destroy.c b/sem_destroy.c
index bd6cb7e..733afd3 100644
--- a/sem_destroy.c
+++ b/sem_destroy.c
@@ -55,19 +55,19 @@ sem_destroy (sem_t * sem)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* DESCRIPTION
* This function destroys an unnamed semaphore.
*
* RESULTS
- * 0 successfully destroyed semaphore,
- * -1 failed, error in errno
+ * 0 successfully destroyed semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS semaphores are not supported,
- * EBUSY threads (or processes) are currently
- * blocked on 'sem'
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOSYS semaphores are not supported,
+ * EBUSY threads (or processes) are currently
+ * blocked on 'sem'
*
* ------------------------------------------------------
*/
@@ -86,19 +86,19 @@ sem_destroy (sem_t * sem)
#ifdef NEED_SEM
- if (! CloseHandle(s->event))
+ if (!CloseHandle (s->event))
{
*sem = s;
result = EINVAL;
}
else
{
- DeleteCriticalSection(&s->sem_lock_cs);
+ DeleteCriticalSection (&s->sem_lock_cs);
}
#else /* NEED_SEM */
- if (! CloseHandle (s->sem))
+ if (!CloseHandle (s->sem))
{
*sem = s;
result = EINVAL;
@@ -114,7 +114,7 @@ sem_destroy (sem_t * sem)
return -1;
}
- free(s);
+ free (s);
return 0;
diff --git a/sem_getvalue.c b/sem_getvalue.c
index c583f7b..c34739a 100644
--- a/sem_getvalue.c
+++ b/sem_getvalue.c
@@ -47,7 +47,7 @@
int
-sem_getvalue(sem_t * sem, int * sval)
+sem_getvalue (sem_t * sem, int *sval)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -57,20 +57,20 @@ sem_getvalue(sem_t * sem, int * sval)
*
* Return value
*
- * 0 sval has been set.
- * -1 failed, error in errno
+ * 0 sval has been set.
+ * -1 failed, error in errno
*
* in global errno
*
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS this function is not supported,
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOSYS this function is not supported,
*
*
* PARAMETERS
*
- * sem pointer to an instance of sem_t
+ * sem pointer to an instance of sem_t
*
- * sval pointer to int.
+ * sval pointer to int.
*
* DESCRIPTION
* This function stores the current count value of the semaphore
@@ -78,21 +78,21 @@ sem_getvalue(sem_t * sem, int * sval)
*/
{
int result = 0;
- long value;
-
- if ( sem == NULL || *sem == NULL || sval == NULL )
+ long value;
+
+ if (sem == NULL || *sem == NULL || sval == NULL)
{
result = EINVAL;
}
else
{
- register sem_t s = *sem;
-
+ register sem_t s = *sem;
+
#ifdef NEED_SEM
- EnterCriticalSection(&s->sem_lock_cs);
- value = s->value;
- LeaveCriticalSection(&s->sem_lock_cs);
+ EnterCriticalSection (&s->sem_lock_cs);
+ value = s->value;
+ LeaveCriticalSection (&s->sem_lock_cs);
#else
@@ -126,29 +126,29 @@ sem_getvalue(sem_t * sem, int * sval)
* decrement/increment it inside of sem_wait() and sem_post()
* etc using the Interlocked* functions.
*/
- if ( WaitForSingleObject( s->sem, 0 ) == WAIT_TIMEOUT )
- {
- /* Failed - must be zero */
- value = 0;
- }
+ if (WaitForSingleObject (s->sem, 0) == WAIT_TIMEOUT)
+ {
+ /* Failed - must be zero */
+ value = 0;
+ }
else
- {
- /* Decremented semaphore - release it and note the value */
- (void) ReleaseSemaphore( s->sem, 1L, &value);
- value++;
- }
+ {
+ /* Decremented semaphore - release it and note the value */
+ (void) ReleaseSemaphore (s->sem, 1L, &value);
+ value++;
+ }
#endif
}
- if ( result != 0 )
+ if (result != 0)
{
errno = result;
return -1;
}
- *sval = value;
+ *sval = value;
return 0;
-} /* sem_getvalue */
+} /* sem_getvalue */
diff --git a/sem_init.c b/sem_init.c
index 4841530..eca0026 100644
--- a/sem_init.c
+++ b/sem_init.c
@@ -11,8 +11,6 @@
*
* -------------------------------------------------------------
*
- * --------------------------------------------------------------------------
- *
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2003 Pthreads-win32 contributors
@@ -41,10 +39,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifndef _UWIN
-# include <process.h>
-#endif
-
#include "pthread.h"
#include "semaphore.h"
#include "implement.h"
@@ -59,29 +53,30 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* pshared
- * if zero, this semaphore may only be shared between
- * threads in the same process.
- * if nonzero, the semaphore can be shared between
- * processes
+ * if zero, this semaphore may only be shared between
+ * threads in the same process.
+ * if nonzero, the semaphore can be shared between
+ * processes
*
* value
- * initial value of the semaphore counter
+ * initial value of the semaphore counter
*
* DESCRIPTION
* This function initializes a semaphore. The
* initial value of the semaphore is set to 'value'.
*
* RESULTS
- * 0 successfully created semaphore,
- * -1 failed, error in errno
+ * 0 successfully created semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSPC a required resource has been exhausted,
- * ENOSYS semaphores are not supported,
- * EPERM the process lacks appropriate privilege
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOMEM out of memory,
+ * ENOSPC a required resource has been exhausted,
+ * ENOSYS semaphores are not supported,
+ * EPERM the process lacks appropriate privilege
*
* ------------------------------------------------------
*/
@@ -96,57 +91,56 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
* processes
*/
result = EPERM;
-
}
else
{
-
s = (sem_t) calloc (1, sizeof (*s));
if (NULL == s)
- {
- result = ENOMEM;
- }
+ {
+ result = ENOMEM;
+ }
+ else
+ {
#ifdef NEED_SEM
- else
- {
- s->value = value;
- s->event = CreateEvent (NULL,
- PTW32_FALSE, /* manual reset */
- PTW32_FALSE, /* initial state */
- NULL);
-
- if (0 == s->event)
- {
- result = ENOSPC;
- }
- else
- {
- if (value != 0)
- {
- SetEvent(s->event);
- }
-
- InitializeCriticalSection(&s->sem_lock_cs);
- }
- }
+ s->value = value;
+ s->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset */
+ PTW32_FALSE, /* initial state */
+ NULL);
+
+ if (0 == s->event)
+ {
+ free (s);
+ result = ENOSPC;
+ }
+ else
+ {
+ if (value != 0)
+ {
+ SetEvent (s->event);
+ }
+
+ InitializeCriticalSection (&s->sem_lock_cs);
+ }
#else /* NEED_SEM */
- s->sem = CreateSemaphore (NULL, /* Always NULL */
- (long) value, /* Initial value */
- (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
- NULL); /* Name */
-
- if (0 == s->sem)
- {
- result = ENOSPC;
- }
+ s->sem = CreateSemaphore (NULL, /* Always NULL */
+ (long) value, /* Initial value */
+ (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
+ NULL); /* Name */
+
+ if (0 == s->sem)
+ {
+ free (s);
+ result = ENOSPC;
+ }
#endif /* NEED_SEM */
+ }
}
if (result != 0)
diff --git a/sem_open.c b/sem_open.c
index 672b505..2c998e3 100644
--- a/sem_open.c
+++ b/sem_open.c
@@ -51,7 +51,7 @@
#endif
int
-sem_open (const char * name, int oflag, mode_t mode, unsigned int value)
+sem_open (const char *name, int oflag, mode_t mode, unsigned int value)
{
errno = ENOSYS;
return -1;
diff --git a/sem_post.c b/sem_post.c
index a0ee019..3281643 100644
--- a/sem_post.c
+++ b/sem_post.c
@@ -55,7 +55,7 @@ sem_post (sem_t * sem)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* DESCRIPTION
* This function posts a wakeup to a semaphore. If there
@@ -63,11 +63,11 @@ sem_post (sem_t * sem)
* otherwise, the semaphore value is incremented by one.
*
* RESULTS
- * 0 successfully posted semaphore,
- * -1 failed, error in errno
+ * 0 successfully posted semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS semaphores are not supported,
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOSYS semaphores are not supported,
*
* ------------------------------------------------------
*/
@@ -76,21 +76,21 @@ sem_post (sem_t * sem)
if (sem == NULL || *sem == NULL)
{
- result = EINVAL;
+ result = EINVAL;
}
#ifdef NEED_SEM
- else if (! ptw32_increase_semaphore (sem, 1))
+ else if (!ptw32_increase_semaphore (sem, 1))
#else /* NEED_SEM */
- else if (! ReleaseSemaphore ((*sem)->sem, 1, 0))
+ else if (!ReleaseSemaphore ((*sem)->sem, 1, 0))
#endif /* NEED_SEM */
{
- result = EINVAL;
+ result = EINVAL;
}
if (result != 0)
diff --git a/sem_post_multiple.c b/sem_post_multiple.c
index 998778c..43c71a6 100644
--- a/sem_post_multiple.c
+++ b/sem_post_multiple.c
@@ -47,7 +47,7 @@
int
-sem_post_multiple (sem_t * sem, int count )
+sem_post_multiple (sem_t * sem, int count)
/*
* ------------------------------------------------------
* DOCPUBLIC
@@ -55,10 +55,10 @@ sem_post_multiple (sem_t * sem, int count )
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* count
- * counter, must be greater than zero.
+ * counter, must be greater than zero.
*
* DESCRIPTION
* This function posts multiple wakeups to a semaphore. If there
@@ -66,11 +66,11 @@ sem_post_multiple (sem_t * sem, int count )
* the semaphore value is incremented by count - n.
*
* RESULTS
- * 0 successfully posted semaphore,
- * -1 failed, error in errno
+ * 0 successfully posted semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore
- * or count is less than or equal to zero.
+ * EINVAL 'sem' is not a valid semaphore
+ * or count is less than or equal to zero.
*
* ------------------------------------------------------
*/
@@ -84,11 +84,11 @@ sem_post_multiple (sem_t * sem, int count )
#ifdef NEED_SEM
- else if (! ptw32_increase_semaphore (sem, count))
+ else if (!ptw32_increase_semaphore (sem, count))
#else /* NEED_SEM */
- else if (! ReleaseSemaphore ((*sem)->sem, count, 0))
+ else if (!ReleaseSemaphore ((*sem)->sem, count, 0))
#endif /* NEED_SEM */
diff --git a/sem_trywait.c b/sem_trywait.c
index 1dbe06d..342ee06 100644
--- a/sem_trywait.c
+++ b/sem_trywait.c
@@ -55,7 +55,7 @@ sem_trywait (sem_t * sem)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* DESCRIPTION
* This function tries to wait on a semaphore. If the
@@ -64,14 +64,14 @@ sem_trywait (sem_t * sem)
* this function returns immediately with the error EAGAIN
*
* RESULTS
- * 0 successfully decreased semaphore,
- * -1 failed, error in errno
+ * 0 successfully decreased semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EAGAIN the semaphore was already locked,
- * EINVAL 'sem' is not a valid semaphore,
- * ENOTSUP sem_trywait is not supported,
- * EINTR the function was interrupted by a signal,
- * EDEADLK a deadlock condition was detected.
+ * EAGAIN the semaphore was already locked,
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOTSUP sem_trywait is not supported,
+ * EINTR the function was interrupted by a signal,
+ * EDEADLK a deadlock condition was detected.
*
* ------------------------------------------------------
*/
diff --git a/sem_unlink.c b/sem_unlink.c
index 99ad841..ae034f4 100644
--- a/sem_unlink.c
+++ b/sem_unlink.c
@@ -51,7 +51,7 @@
#endif
int
-sem_unlink (const char * name)
+sem_unlink (const char *name)
{
errno = ENOSYS;
return -1;
diff --git a/sem_wait.c b/sem_wait.c
index 2f6fe3c..e2e171c 100644
--- a/sem_wait.c
+++ b/sem_wait.c
@@ -55,7 +55,7 @@ sem_wait (sem_t * sem)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* DESCRIPTION
* This function waits on a semaphore. If the
@@ -66,13 +66,13 @@ sem_wait (sem_t * sem)
* a signal.
*
* RESULTS
- * 0 successfully decreased semaphore,
- * -1 failed, error in errno
+ * 0 successfully decreased semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSYS semaphores are not supported,
- * EINTR the function was interrupted by a signal,
- * EDEADLK a deadlock condition was detected.
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOSYS semaphores are not supported,
+ * EINTR the function was interrupted by a signal,
+ * EDEADLK a deadlock condition was detected.
*
* ------------------------------------------------------
*/
@@ -88,11 +88,11 @@ sem_wait (sem_t * sem)
#ifdef NEED_SEM
- result = pthreadCancelableWait ((*sem)->event);
+ result = pthreadCancelableWait ((*sem)->event);
#else /* NEED_SEM */
- result = pthreadCancelableWait ((*sem)->sem);
+ result = pthreadCancelableWait ((*sem)->sem);
#endif /* NEED_SEM */
@@ -106,7 +106,7 @@ sem_wait (sem_t * sem)
#ifdef NEED_SEM
- ptw32_decrease_semaphore(sem);
+ ptw32_decrease_semaphore (sem);
#endif /* NEED_SEM */
diff --git a/semaphore.c b/semaphore.c
index cc38e93..9b86043 100644
--- a/semaphore.c
+++ b/semaphore.c
@@ -45,9 +45,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifndef _UWIN
-# include <process.h>
-#endif
#ifndef NEED_FTIME
# include <sys/timeb.h>
#endif
@@ -74,4 +71,3 @@
#include "ptw32_decrease_semaphore.c"
#include "ptw32_increase_semaphore.c"
#endif
-
diff --git a/signal.c b/signal.c
index 3725127..a7c3ef0 100644
--- a/signal.c
+++ b/signal.c
@@ -87,26 +87,26 @@
#if HAVE_SIGSET_T
static void
-ptw32_signal_thread()
+ptw32_signal_thread ()
{
}
static void
-ptw32_signal_callhandler()
+ptw32_signal_callhandler ()
{
}
int
-pthread_sigmask(int how, sigset_t const *set, sigset_t *oset)
+pthread_sigmask (int how, sigset_t const *set, sigset_t * oset)
{
- pthread_t thread = pthread_self();
+ pthread_t thread = pthread_self ();
if (thread == NULL)
{
return ENOENT;
}
- /* Validate the `how' argument.*/
+ /* Validate the `how' argument. */
if (set != NULL)
{
switch (how)
@@ -126,7 +126,7 @@ pthread_sigmask(int how, sigset_t const *set, sigset_t *oset)
/* Copy the old mask before modifying it. */
if (oset != NULL)
{
- memcpy(oset, &(thread->sigmask), sizeof(sigset_t));
+ memcpy (oset, &(thread->sigmask), sizeof (sigset_t));
}
if (set != NULL)
@@ -134,7 +134,7 @@ pthread_sigmask(int how, sigset_t const *set, sigset_t *oset)
unsigned int i;
/* FIXME: this code assumes that sigmask is an even multiple of
- the size of a long integer. */
+ the size of a long integer. */
unsigned long *src = (unsigned long const *) set;
unsigned long *dest = (unsigned long *) &(thread->sigmask);
@@ -142,21 +142,21 @@ pthread_sigmask(int how, sigset_t const *set, sigset_t *oset)
switch (how)
{
case SIG_BLOCK:
- for (i = 0; i < (sizeof(sigset_t) / sizeof(unsigned long)); i++)
+ for (i = 0; i < (sizeof (sigset_t) / sizeof (unsigned long)); i++)
{
/* OR the bit field longword-wise. */
*dest++ |= *src++;
}
break;
case SIG_UNBLOCK:
- for (i = 0; i < (sizeof(sigset_t) / sizeof(unsigned long)); i++)
+ for (i = 0; i < (sizeof (sigset_t) / sizeof (unsigned long)); i++)
{
/* XOR the bitfield longword-wise. */
*dest++ ^= *src++;
}
case SIG_SETMASK:
/* Replace the whole sigmask. */
- memcpy(&(thread->sigmask), set, sizeof(sigset_t));
+ memcpy (&(thread->sigmask), set, sizeof (sigset_t));
break;
}
}
@@ -164,14 +164,13 @@ pthread_sigmask(int how, sigset_t const *set, sigset_t *oset)
return 0;
}
-int sigwait(const sigset_t *set,
- int *sig)
+int
+sigwait (const sigset_t * set, int *sig)
{
}
-int sigaction(int signum,
- const struct sigaction *act,
- struct sigaction *oldact)
+int
+sigaction (int signum, const struct sigaction *act, struct sigaction *oldact)
{
}
diff --git a/spin.c b/spin.c
index b9f3356..dacf3e6 100644
--- a/spin.c
+++ b/spin.c
@@ -44,4 +44,3 @@
#include "pthread_spin_lock.c"
#include "pthread_spin_unlock.c"
#include "pthread_spin_trylock.c"
-
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 667747f..e62c257 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,21 +1,35 @@
+2004-05-16 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * cancel9.c: New test.
+ * cancel3.c: Remove inappropriate conditional compilation;
+ GNU C version of test suite no longer quietly skips this test.
+ * cancel5.c: Likewise.
+ * GNUmakefile: Can now build individual test app using default
+ C version of library using 'make clean testname.c'.
+ * Makefile: Likewise for VC using 'nmake clean test testname.c'.
+
+2003-10-14 Ross Johnson <rpj@callisto.canberra.edu.au>
+
+ * Wmakefile: New makefile for Watcom testing.
+
2003-09-18 Ross Johnson <rpj@callisto.canberra.edu.au>
- * benchtest.h: Move old mutex code into benchlib.c.
- * benchlib.c: New statically linked module to ensure that
- bench apps don't inline the code and therefore have an unfair
- advantage over the pthreads lib routines. Made little or no
- difference.
- * benchtest1.c: Minor change to avoid compiler warnings.
- * benchtest5.c: Likewise.
- * benchtest2.c: Fix misinformation in output report.
- * README.BENCH: Add comments on results.
+ * benchtest.h: Move old mutex code into benchlib.c.
+ * benchlib.c: New statically linked module to ensure that
+ bench apps don't inline the code and therefore have an unfair
+ advantage over the pthreads lib routines. Made little or no
+ difference.
+ * benchtest1.c: Minor change to avoid compiler warnings.
+ * benchtest5.c: Likewise.
+ * benchtest2.c: Fix misinformation in output report.
+ * README.BENCH: Add comments on results.
2003-09-14 Ross Johnson <rpj@callisto.canberra.edu.au>
- * priority1.c: Reworked to comply with modified priority
- management and provide additional output.
- * priority2.c: Likewise.
- * inherit1.c: Likewise.
+ * priority1.c: Reworked to comply with modified priority
+ management and provide additional output.
+ * priority2.c: Likewise.
+ * inherit1.c: Likewise.
2003-09-03 Ross Johnson <rpj@callisto.canberra.edu.au>
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index 7ed1c85..a7c8079 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -35,9 +35,11 @@
CP = cp -f
MV = mv -f
RM = rm -f
+CAT = cat
#CP = copy
#MV = rename
#RM = erase
+#CAT = type
MKDIR = mkdir
TOUCH = echo Passed >
ECHO = @echo
@@ -47,18 +49,22 @@ MAKE = make
# Mingw32
#
XXCFLAGS =
-XXLIBS =
+XXLIBS = -lws2_32
CFLAGS = -O3 -UNDEBUG -Wall $(XXCFLAGS)
#CFLAGS = -g -O0 -UNDEBUG -Wall $(XXCFLAGS)
BUILD_DIR = ..
INCLUDES = -I.
-GCX = DUMMY
+# Default lib version
+GCX = GC
+# Files we need to run the tests
+# - paths are relative to pthreads build dir.
HDR = pthread.h semaphore.h sched.h
LIB = libpthread$(GCX).a
DLL = pthread$(GCX).dll
+QAPC = ../QueueUserAPCEx/User/quserex.dll
-COPYFILES = $(HDR) $(LIB) $(DLL)
+COPYFILES = $(HDR) $(LIB) $(DLL) $(QAPC)
# If a test case returns a non-zero exit code to the shell, make will
# stop.
@@ -85,7 +91,8 @@ TESTS = sizes loadfree \
priority1 priority2 inherit1 \
spin1 spin2 spin3 spin4 \
barrier1 barrier2 barrier3 barrier4 barrier5 \
- exception1 exception2 exception3
+ exception1 exception2 exception3 \
+ cancel9
BENCHTESTS = \
benchtest1 benchtest2 benchtest3 benchtest4 benchtest5
@@ -240,30 +247,37 @@ spin4.pass: spin3.pass
tsd1.pass: join1.pass
valid1.pass: join1.pass
valid2.pass: valid1.pass
+cancel9.pass: cancel8.pass
-#%.pass: %.exe $(HDR)
-%.pass: %.exe $(LIB) $(DLL) $(HDR)
+sizes.pass: sizes.exe
+ @ $(ECHO) Running $*
+ $< > SIZES.$(GCX)
+ @ $(CAT) SIZES.$(GCX)
+ @ $(ECHO) Passed
+ @ $(TOUCH) $@
+
+%.pass: %.exe
@ $(ECHO) Running $*
$*
@ $(ECHO) Passed
@ $(TOUCH) $@
-%.bench: $(LIB) $(DLL) $(HDR) $(XXLIBS) %.exe
+%.bench: $(XXLIBS) %.exe
@ $(ECHO) Running $*
$*
@ $(ECHO) Done
@ $(TOUCH) $@
-%.exe: %.c
+%.exe: %.c $(LIB) $(DLL) $(HDR) $(QAPC)
@ $(ECHO) Compiling $@
- @ $(ECHO) $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) -L. -lpthread$(GCX) -lsupc++ $(XXLIBS)
- @ $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) -L. -lpthread$(GCX) -lsupc++ $(XXLIBS)
+ @ $(ECHO) $(CC) $(CFLAGS) -o $@ $< $(INCLUDES) -L. -lpthread$(GCX) -lsupc++ $(XXLIBS)
+ @ $(CC) $(CFLAGS) -o $@ $< $(INCLUDES) -L. -lpthread$(GCX) -lsupc++ $(XXLIBS)
-%.pre: %.c
- @ $(CC) -E $(CFLAGS) -o $@ $^ $(INCLUDES)
+%.pre: %.c $(HDR)
+ @ $(CC) -E $(CFLAGS) -o $@ $< $(INCLUDES)
-%.s: %.c
- @ $(CC) -S $(CFLAGS) -o $@ $^ $(INCLUDES)
+%.s: %.c $(HDR)
+ @ $(CC) -S $(CFLAGS) -o $@ $< $(INCLUDES)
$(COPYFILES):
@ $(ECHO) Copying $@
@@ -274,8 +288,8 @@ pthread.dll:
benchlib.o: benchlib.c
@ $(ECHO) Compiling $@
- @ $(ECHO) $(CC) -c $(CFLAGS) $^ $(INCLUDES)
- @ $(CC) -c $(CFLAGS) $^ $(INCLUDES)
+ @ $(ECHO) $(CC) -c $(CFLAGS) $< $(INCLUDES)
+ @ $(CC) -c $(CFLAGS) $< $(INCLUDES)
clean:
- $(RM) *.dll
diff --git a/tests/Makefile b/tests/Makefile
index 210b8a1..17cb0c8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -34,15 +34,18 @@
CP = copy
RM = erase
+CAT = type
MKDIR = mkdir
TOUCH = echo Passed >
ECHO = @echo
+QAPC = ..\QueueUserAPCEx\User\quserex.dll
+
CPHDR = pthread.h semaphore.h sched.h
OPTIM = /O2 /Ob0
-XXLIBS =
+XXLIBS = ws2_32.lib
# C++ Exceptions
VCEFLAGS = /GX /TP /DPtW32NoCatchWarn /D__CLEANUP_CXX
@@ -59,12 +62,16 @@ VCDLL = pthreadVC.dll
# C++ Exceptions in application - using VC version of pthreads dll
VCXFLAGS = /GX /TP /D__CLEANUP_C
+# Defaults
+CPLIB = pthreadVC.lib
+CPDLL = pthreadVC.dll
+
CFLAGS= $(OPTIM) /W3 /WX /MD /nologo /Yd /Zi -D_WIN32_WINNT=0x400
LFLAGS= /INCREMENTAL:NO
INCLUDES=-I.
BUILD_DIR=..
-COPYFILES = $(CPHDR) $(CPLIB) $(CPDLL)
+COPYFILES = $(CPHDR) $(CPLIB) $(CPDLL) $(QAPC)
TEST =
EHFLAGS =
@@ -100,7 +107,8 @@ PASSES= sizes.pass loadfree.pass \
priority1.pass priority2.pass inherit1.pass \
spin1.pass spin2.pass spin3.pass spin4.pass \
barrier1.pass barrier2.pass barrier3.pass barrier4.pass barrier5.pass \
- exception1.pass exception2.pass exception3.pass
+ exception1.pass exception2.pass exception3.pass \
+ cancel9
BENCHRESULTS = \
benchtest1.bench benchtest2.bench benchtest3.bench benchtest4.bench benchtest5.bench
@@ -123,12 +131,23 @@ all:
@ nmake clean VSE
@ nmake clean VC-bench
-tests: $(CPLIB) $(CPDLL) $(CPHDR) $(PASSES)
+# This allows an individual test application to be made using the default lib.
+# e.g. nmake clean test cancel3.exe
+test: $(CPLIB) $(CPDLL) $(CPHDR) $(QAPC)
+
+tests: $(CPLIB) $(CPDLL) $(CPHDR) $(QAPC) $(PASSES)
@ $(ECHO) ALL TESTS PASSED! Congratulations!
benchtests: $(CPLIB) $(CPDLL) $(CPHDR) $(XXLIBS) $(BENCHRESULTS)
@ $(ECHO) ALL BENCH TESTS DONE.
+sizes.pass: sizes.exe
+ @ $(ECHO) ... Running $(TEST) test: $*.exe
+ @ .\$*.exe > SIZES.$(TEST)
+ @ $(CAT) SIZES.$(TEST)
+ @ $(ECHO) ...... Passed
+ @ $(TOUCH) $*.pass
+
$(PASSES): $*.exe
@ $(ECHO) ... Running $(TEST) test: $*.exe
@ .\$*.exe
@@ -180,9 +199,9 @@ $(COPYFILES):
@ $(ECHO) Copying $@
@ $(CP) $(BUILD_DIR)\$@ .
-pthread.dll:
- @ $(CP) $(CPDLL) $*.dll
- @ $(CP) $(CPLIB) $*.lib
+pthread.dll: $(CPDLL)
+ @ $(CP) $(CPDLL) pthread.dll
+ @ $(CP) $(CPLIB) pthread.lib
clean:
- $(RM) *.dll
@@ -312,3 +331,4 @@ spin4.pass: spin3.pass
tsd1.pass: join1.pass
valid1.pass: join1.pass
valid2.pass: valid1.pass
+cancel9.pass: cancel8.pass
diff --git a/tests/cancel3.c b/tests/cancel3.c
index ed1df0f..c3657d6 100644
--- a/tests/cancel3.c
+++ b/tests/cancel3.c
@@ -33,13 +33,13 @@
*
* --------------------------------------------------------------------------
*
- * Test Synopsis: Test asynchronous cancelation.
+ * Test Synopsis: Test asynchronous cancelation (alertable or non-alertable).
*
* Test Method (Validation or Falsification):
* -
*
* Requirements Tested:
- * -
+ * - Async cancel if thread is not blocked (i.e. voluntarily resumes if blocked).
*
* Features Tested:
* -
@@ -62,7 +62,8 @@
*
* Assumptions:
* - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
- * pthread_testcancel, pthread_cancel, pthread_join
+ * pthread_testcancel, pthread_cancel, pthread_join.
+ * - quserex.dll and alertdrv.sys are not available.
*
* Pass Criteria:
* - Process returns zero exit status.
@@ -71,19 +72,19 @@
* - Process returns non-zero exit status.
*/
-#if defined(_MSC_VER) || defined(__cplusplus)
-
#include "test.h"
/*
* Create NUMTHREADS threads in addition to the Main thread.
*/
-enum {
+enum
+{
NUMTHREADS = 4
};
typedef struct bag_t_ bag_t;
-struct bag_t_ {
+struct bag_t_
+{
int threadnum;
int started;
/* Add more per-thread state variables here */
@@ -93,75 +94,77 @@ struct bag_t_ {
static bag_t threadbag[NUMTHREADS + 1];
void *
-mythread(void * arg)
+mythread (void *arg)
{
- int result = ((int)PTHREAD_CANCELED + 1);
- bag_t * bag = (bag_t *) arg;
+ int result = ((int) PTHREAD_CANCELED + 1);
+ bag_t *bag = (bag_t *) arg;
- assert(bag == &threadbag[bag->threadnum]);
- assert(bag->started == 0);
+ assert (bag == &threadbag[bag->threadnum]);
+ assert (bag->started == 0);
bag->started = 1;
/* Set to known state and type */
- assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
+ assert (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) == 0);
- assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
+ assert (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
/*
* We wait up to 10 seconds, waking every 0.1 seconds,
* for a cancelation to be applied to us.
*/
for (bag->count = 0; bag->count < 100; bag->count++)
- Sleep(100);
+ Sleep (100);
return (void *) result;
}
int
-main()
+main ()
{
int failed = 0;
int i;
pthread_t t[NUMTHREADS + 1];
- assert((t[0] = pthread_self()) != NULL);
+ assert ((t[0] = pthread_self ()) != NULL);
for (i = 1; i <= NUMTHREADS; i++)
{
threadbag[i].started = 0;
threadbag[i].threadnum = i;
- assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
+ assert (pthread_create (&t[i], NULL, mythread, (void *) &threadbag[i])
+ == 0);
}
/*
* Code to control or munipulate child threads should probably go here.
*/
- Sleep(500);
+ Sleep (500);
for (i = 1; i <= NUMTHREADS; i++)
{
- assert(pthread_cancel(t[i]) == 0);
+ assert (pthread_cancel (t[i]) == 0);
}
/*
* Give threads time to run.
*/
- Sleep(NUMTHREADS * 100);
+ Sleep (NUMTHREADS * 100);
/*
* Standard check that all threads started.
*/
for (i = 1; i <= NUMTHREADS; i++)
- {
+ {
if (!threadbag[i].started)
{
failed |= !threadbag[i].started;
- fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ fprintf (stderr, "Thread %d: started %d\n", i,
+ threadbag[i].started);
}
}
- assert(!failed);
+ assert (!failed);
/*
* Check any results here. Set "failed" and only print output on failure.
@@ -177,34 +180,22 @@ main()
* a return value of PTHREAD_CANCELED confirms that async
* cancelation succeeded.
*/
- assert(pthread_join(t[i], (void **) &result) == 0);
+ assert (pthread_join (t[i], (void **) &result) == 0);
fail = (result != (int) PTHREAD_CANCELED);
if (fail)
{
- fprintf(stderr, "Thread %d: started %d: count %d\n",
- i,
- threadbag[i].started,
- threadbag[i].count);
+ fprintf (stderr, "Thread %d: started %d: count %d\n",
+ i, threadbag[i].started, threadbag[i].count);
}
failed = (failed || fail);
}
- assert(!failed);
+ assert (!failed);
/*
* Success.
*/
return 0;
}
-
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
-
-int
-main()
-{
- return 0;
-}
-
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
diff --git a/tests/cancel4.c b/tests/cancel4.c
index 3313ab4..b77f921 100644
--- a/tests/cancel4.c
+++ b/tests/cancel4.c
@@ -76,8 +76,6 @@
* - Process returns non-zero exit status.
*/
-#if defined(_MSC_VER) || defined(__cplusplus)
-
#include "test.h"
/*
@@ -203,13 +201,3 @@ main()
*/
return 0;
}
-
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
-
-int
-main()
-{
- return 0;
-}
-
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
diff --git a/tests/cancel5.c b/tests/cancel5.c
index 808ab14..76d0a5a 100644
--- a/tests/cancel5.c
+++ b/tests/cancel5.c
@@ -72,19 +72,19 @@
* - Process returns non-zero exit status.
*/
-#if defined(_MSC_VER) || defined(__cplusplus)
-
#include "test.h"
/*
* Create NUMTHREADS threads in addition to the Main thread.
*/
-enum {
+enum
+{
NUMTHREADS = 4
};
typedef struct bag_t_ bag_t;
-struct bag_t_ {
+struct bag_t_
+{
int threadnum;
int started;
/* Add more per-thread state variables here */
@@ -94,33 +94,33 @@ struct bag_t_ {
static bag_t threadbag[NUMTHREADS + 1];
void *
-mythread(void * arg)
+mythread (void *arg)
{
- int result = ((int)PTHREAD_CANCELED + 1);
- bag_t * bag = (bag_t *) arg;
+ int result = ((int) PTHREAD_CANCELED + 1);
+ bag_t *bag = (bag_t *) arg;
- assert(bag == &threadbag[bag->threadnum]);
- assert(bag->started == 0);
+ assert (bag == &threadbag[bag->threadnum]);
+ assert (bag->started == 0);
bag->started = 1;
/* Set to known state and type */
- assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
+ assert (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) == 0);
- assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
+ assert (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
/*
* We wait up to 10 seconds, waking every 0.1 seconds,
* for a cancelation to be applied to us.
*/
for (bag->count = 0; bag->count < 100; bag->count++)
- Sleep(100);
+ Sleep (100);
return (void *) result;
}
int
-main()
+main ()
{
int failed = 0;
int i;
@@ -130,37 +130,39 @@ main()
{
threadbag[i].started = 0;
threadbag[i].threadnum = i;
- assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
+ assert (pthread_create (&t[i], NULL, mythread, (void *) &threadbag[i])
+ == 0);
}
/*
* Code to control or munipulate child threads should probably go here.
*/
- Sleep(500);
+ Sleep (500);
for (i = 1; i <= NUMTHREADS; i++)
{
- assert(pthread_cancel(t[i]) == 0);
+ assert (pthread_cancel (t[i]) == 0);
}
/*
* Give threads time to run.
*/
- Sleep(NUMTHREADS * 100);
+ Sleep (NUMTHREADS * 100);
/*
* Standard check that all threads started.
*/
for (i = 1; i <= NUMTHREADS; i++)
- {
+ {
if (!threadbag[i].started)
{
failed |= !threadbag[i].started;
- fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ fprintf (stderr, "Thread %d: started %d\n", i,
+ threadbag[i].started);
}
}
- assert(!failed);
+ assert (!failed);
/*
* Check any results here. Set "failed" and only print output on failure.
@@ -176,34 +178,22 @@ main()
* a return value of PTHREAD_CANCELED confirms that async
* cancelation succeeded.
*/
- assert(pthread_join(t[i], (void **) &result) == 0);
+ assert (pthread_join (t[i], (void **) &result) == 0);
fail = (result != (int) PTHREAD_CANCELED);
if (fail)
{
- fprintf(stderr, "Thread %d: started %d: count %d\n",
- i,
- threadbag[i].started,
- threadbag[i].count);
+ fprintf (stderr, "Thread %d: started %d: count %d\n",
+ i, threadbag[i].started, threadbag[i].count);
}
failed = (failed || fail);
}
- assert(!failed);
+ assert (!failed);
/*
* Success.
*/
return 0;
}
-
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
-
-int
-main()
-{
- return 0;
-}
-
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
diff --git a/tests/cancel6a.c b/tests/cancel6a.c
index 81f8d04..4aea81a 100644
--- a/tests/cancel6a.c
+++ b/tests/cancel6a.c
@@ -63,8 +63,6 @@
* - Process returns non-zero exit status.
*/
-#if defined(_MSC_VER) || defined(__cplusplus)
-
#include "test.h"
/*
@@ -191,13 +189,3 @@ main()
*/
return 0;
}
-
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
-
-int
-main()
-{
- return 0;
-}
-
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
diff --git a/tests/cancel6d.c b/tests/cancel6d.c
index cdb09f5..9a69adb 100644
--- a/tests/cancel6d.c
+++ b/tests/cancel6d.c
@@ -64,8 +64,6 @@
* - Process returns non-zero exit status.
*/
-#if defined(_MSC_VER) || defined(__cplusplus)
-
#include "test.h"
/*
@@ -195,13 +193,3 @@ main()
*/
return 0;
}
-
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
-
-int
-main()
-{
- return 0;
-}
-
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
diff --git a/tsd.c b/tsd.c
index 69e1262..5b61052 100644
--- a/tsd.c
+++ b/tsd.c
@@ -42,5 +42,3 @@
#include "pthread_key_delete.c"
#include "pthread_setspecific.c"
#include "pthread_getspecific.c"
-
-
diff --git a/w32_CancelableWait.c b/w32_CancelableWait.c
index 6352ff9..a40fa4d 100644
--- a/w32_CancelableWait.c
+++ b/w32_CancelableWait.c
@@ -62,87 +62,83 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout)
handles[0] = waitHandle;
- if ((self = pthread_self()) != NULL)
+ if ((self = pthread_self ()) != NULL)
{
/*
* Get cancelEvent handle
*/
if (self->cancelState == PTHREAD_CANCEL_ENABLE)
- {
+ {
- if ((handles[1] = self->cancelEvent) != NULL)
- {
- nHandles++;
- }
- }
+ if ((handles[1] = self->cancelEvent) != NULL)
+ {
+ nHandles++;
+ }
+ }
}
else
{
handles[1] = NULL;
}
- status = WaitForMultipleObjects (
- nHandles,
- handles,
- PTW32_FALSE,
- timeout);
-
-
- switch (status - WAIT_OBJECT_0)
- {
- case 0:
- /*
- * Got the handle.
- * In the event that both handles are signalled, the smallest index
- * value (us) is returned. As it has been arranged, this ensures that
- * we don't drop a signal that we should act on (i.e. semaphore,
- * mutex, or condition variable etc).
- */
- result = 0;
- break;
-
- case 1:
- /*
- * Got cancel request.
- * In the event that both handles are signaled, the cancel will
- * be ignored (see case 0 comment).
- */
- ResetEvent (handles[1]);
-
- if (self != NULL)
- {
- /*
- * Should handle POSIX and implicit POSIX threads..
- * Make sure we haven't been async-canceled in the meantime.
- */
- (void) pthread_mutex_lock(&self->cancelLock);
- if (self->state < PThreadStateCanceling)
- {
- self->state = PThreadStateCanceling;
- self->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock(&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
-
- /* Never reached */
- }
- (void) pthread_mutex_unlock(&self->cancelLock);
- }
-
- /* Should never get to here. */
- result = EINVAL;
- break;
-
- default:
- if (status == WAIT_TIMEOUT)
- {
- result = ETIMEDOUT;
- }
- else
- {
- result = EINVAL;
- }
- break;
- }
+ status = WaitForMultipleObjects (nHandles, handles, PTW32_FALSE, timeout);
+
+
+ switch (status - WAIT_OBJECT_0)
+ {
+ case 0:
+ /*
+ * Got the handle.
+ * In the event that both handles are signalled, the smallest index
+ * value (us) is returned. As it has been arranged, this ensures that
+ * we don't drop a signal that we should act on (i.e. semaphore,
+ * mutex, or condition variable etc).
+ */
+ result = 0;
+ break;
+
+ case 1:
+ /*
+ * Got cancel request.
+ * In the event that both handles are signaled, the cancel will
+ * be ignored (see case 0 comment).
+ */
+ ResetEvent (handles[1]);
+
+ if (self != NULL)
+ {
+ /*
+ * Should handle POSIX and implicit POSIX threads..
+ * Make sure we haven't been async-canceled in the meantime.
+ */
+ (void) pthread_mutex_lock (&self->cancelLock);
+ if (self->state < PThreadStateCanceling)
+ {
+ self->state = PThreadStateCanceling;
+ self->cancelState = PTHREAD_CANCEL_DISABLE;
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ ptw32_throw (PTW32_EPS_CANCEL);
+
+ /* Never reached */
+ }
+ (void) pthread_mutex_unlock (&self->cancelLock);
+ }
+
+ /* Should never get to here. */
+ result = EINVAL;
+ break;
+
+ default:
+ if (status == WAIT_TIMEOUT)
+ {
+ result = ETIMEDOUT;
+ }
+ else
+ {
+ result = EINVAL;
+ }
+ break;
+ }
return (result);
@@ -151,11 +147,11 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout)
int
pthreadCancelableWait (HANDLE waitHandle)
{
- return (ptw32_cancelable_wait(waitHandle, INFINITE));
+ return (ptw32_cancelable_wait (waitHandle, INFINITE));
}
int
pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout)
{
- return (ptw32_cancelable_wait(waitHandle, timeout));
+ return (ptw32_cancelable_wait (waitHandle, timeout));
}