From 528fccade9ca5f90db376e08b2cb85b3fc822a45 Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 19 Jun 2001 04:49:08 +0000 Subject: * Made organisational-only changes to UWIN additions. * dll.c (dllMain): Moved UWIN process attach code to pthread_win32_process_attach_np(); moved instance of pthread_count to global.c. * global.c (pthread_count): Moved from dll.c. * nonportable.c (pthread_win32_process_attach_np): Moved _UWIN code to here from dll.c. * implement.h (pthread_count): Define extern int. * create.c (pthread_count): Remove extern int. * private.c (pthread_count): Likewise. * exit.c (pthread_count): Likewise. Contributed by - David Korn * dll.c: Added changes necessary to work with UWIN. * create.c: Likewise. * pthread.h: Likewise. * misc.c: Likewise. * exit.c: Likewise. * private.c: Likewise. * implement.h: Likewise. There is some room at the start of struct pthread_t_ to implement the signal semantics in UWIN's posix.dll although this is not yet complete. * Nmakefile: Compatible with UWIN's Nmake utility. * Nmakefile.tests: Likewise - for running the tests. --- ChangeLog | 31 ++++++++++++++ Nmakefile | 24 +++++++++++ Nmakefile.tests | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ create.c | 6 +++ exit.c | 8 +++- global.c | 7 +++ implement.h | 25 +++++++++++ misc.c | 5 +++ nonportable.c | 4 +- private.c | 13 +++++- pthread.h | 13 ++++++ 11 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 Nmakefile create mode 100644 Nmakefile.tests diff --git a/ChangeLog b/ChangeLog index c88e5e0..4bd5a44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2001-06-18 Ross Johnson + + * Made organisational-only changes to UWIN additions. + * dll.c (dllMain): Moved UWIN process attach code + to pthread_win32_process_attach_np(); moved + instance of pthread_count to global.c. + * global.c (pthread_count): Moved from dll.c. + * nonportable.c (pthread_win32_process_attach_np): + Moved _UWIN code to here from dll.c. + * implement.h (pthread_count): Define extern int. + * create.c (pthread_count): Remove extern int. + * private.c (pthread_count): Likewise. + * exit.c (pthread_count): Likewise. + +2001-06-18 Ross Johnson + + Contributed by - David Korn + + * dll.c: Added changes necessary to work with UWIN. + * create.c: Likewise. + * pthread.h: Likewise. + * misc.c: Likewise. + * exit.c: Likewise. + * private.c: Likewise. + * implement.h: Likewise. + There is some room at the start of struct pthread_t_ + to implement the signal semantics in UWIN's posix.dll + although this is not yet complete. + * Nmakefile: Compatible with UWIN's Nmake utility. + * Nmakefile.tests: Likewise - for running the tests. + 2001-06-08 Ross Johnson * semaphore.h (sem_t): Fixed for compile and test. diff --git a/Nmakefile b/Nmakefile new file mode 100644 index 0000000..49c2766 --- /dev/null +++ b/Nmakefile @@ -0,0 +1,24 @@ +/* + * nmake file for uwin pthread library + */ + +VERSION = - +CCFLAGS = -g $(CC.DLL) +PTW32_BUILD == 1 +_MT == 1 +_timeb == timeb +_ftime == ftime +_errno == _ast_errno + +$(INCLUDEDIR) :INSTALLDIR: pthread.h sched.h + +pthread $(VERSION) :LIBRARY: pthread.def attr.c cancel.c cleanup.c condvar.c \ + create.c dll.c exit.c fork.c global.c misc.c mutex.c private.c \ + rwlock.c sched.c semaphore.c sync.c tsd.c nonportable.c + +:: ANNOUNCE CONTRIBUTORS COPYING.LIB ChangeLog FAQ GNUmakefile MAINTAINERS \ + Makefile Makefile.in Makefile.vc NEWS PROGRESS README README.WinCE \ + TODO WinCE-PORT install-sh errno.c tests tests.mk acconfig.h \ + config.guess config.h.in config.sub configure configure.in signal.c \ + README.CV README.NONPORTABLE pthread.dsp pthread.dsw + diff --git a/Nmakefile.tests b/Nmakefile.tests new file mode 100644 index 0000000..5ba32ff --- /dev/null +++ b/Nmakefile.tests @@ -0,0 +1,131 @@ +/* for running tests */ +CCFLAGS = -g +_MT == 1 +_timeb == timeb +_ftime == ftime + +.SOURCE: tests +/* +:PACKAGE: pthread +*/ + +set keepgoing + +":test:" : .MAKE .OPERATOR + local I + $(<:D:B:S=.pass) : .IMPLICIT $(>:D:B:S=.pass) + for I $(<) $(>) + $(I:D:B:S=.pass) : .VIRTUAL .FORCE $(I) + $(>) + end +loadfree:: loadfree.c +mutex1:: mutex1.c +mutex1e:: mutex1e.c +mutex1n:: mutex1n.c +mutex1r:: mutex1r.c +mutex2:: mutex1.2 +exit1:: exit1.c +condvar1:: condvar1.c +self1:: self1.c +condvar2:: condvar2.c +condvar2_1:: condvar2_1.c +condvar3_1:: condvar3_1.c +condvar3_2:: condvar3_2.c +create1.:: create1.c +cancel1:: cancel1.c +cancel2:: cancel2.c +mutex3:: mutex3.c +mutex4:: mutex4.c +mutex5:: mutex5.c +mutex6:: mutex6.c +mutex6e:: mutex6e.c +mutex6n:: mutex6n.c +mutex6r:: mutex6r.c +equal1:: equal1.c +exit2:: exit2.c +exit3:: exit3.c +join0:: join0.c +join1:: join1.c +join2:: join2.c +count1:: count1.c +once1:: once1.c +tsd1:: tsd1.c +self2:: self2.c +eyal1:: eyal1.c +condvar3:: condvar3.c +condvar4:: condvar4.c +condvar5:: condvar5.c +condvar6:: condvar6.c +condvar7:: condvar7.c +condvar8:: condvar8.c +condvar9:: condvar9.c +errno1:: errno1.c +rwlock1:: rwlock1.c +rwlock2:: rwlock2.c +rwlock3:: rwlock3.c +rwlock4:: rwlock4.c +rwlock5:: rwlock5.c +rwlock6:: rwlock6.c +rwlock7:: rwlock7.c +context1:: context1.c +cancel3:: cancel3.c +cancel4:: cancel4.c +cancel5:: cancel5.c +cleanup0:: cleanup0.c +cleanup1:: cleanup1.c +cleanup2:: cleanup2.c +cleanup3:: cleanup3.c +exception1:: exception1.c +exception2:: exception2.c +exception3:: exception3.c + +loadfree: :test: +mutex1 :test: loadfree +mutex2 :test: loadfree +exit1 :test: loadfree +condvar1 :test: loadfree +self1 :test: loadfree +condvar2 :test: condvar1 +create1. :test: mutex2 +cancel1 :test: create1 +cancel2 :test: cancel1 +mutex3 :test: create1 +mutex4 :test: mutex3 +equal1 :test: create1 +exit2 :test: create1 +exit3 :test: create1 +join0 :test: create1 +join1 :test: create1 +join2 :test: create1 +count1 :test: join1 +once1 :test: create1 +tsd1 :test: join1 +self2 :test: create1 +eyal1 :test: tsd1 +condvar3 :test: create1 +condvar4 :test: create1 +condvar5 :test: condvar4 +condvar6 :test: condvar5 +condvar7 :test: condvar6 cleanup1 +condvar8 :test: condvar7 +condvar9 :test: condvar8 +errno1 :test: mutex3 +rwlock1 :test: condvar6 +rwlock2 :test: rwlock1 +rwlock3 :test: rwlock2 +rwlock4 :test: rwlock3 +rwlock5 :test: rwlock4 +rwlock6 :test: rwlock5 +context1 :test: cancel2 +cancel3 :test: context1 +cancel4 :test: cancel3 +cancel5 :test: cancel3 +cleanup0 :test: cancel5 +cleanup1 :test: cleanup0 +cleanup2 :test: cleanup1 +cleanup3 :test: cleanup2 +exception1 :test: cancel4 +exception2 :test: exception1 +exception3 :test: exception2 +tryentercs :test: +tryentercs2 :test: diff --git a/create.c b/create.c index dfaada6..b8fd864 100644 --- a/create.c +++ b/create.c @@ -26,7 +26,9 @@ #include "pthread.h" #include "implement.h" +#ifndef _UWIN #include +#endif int pthread_create (pthread_t * tid, @@ -213,6 +215,10 @@ FAIL0: } *tid = thread; +#ifdef _UWIN + if (result == 0) + pthread_count++; +#endif return (result); } /* pthread_create */ diff --git a/exit.c b/exit.c index 631ef66..04f3277 100644 --- a/exit.c +++ b/exit.c @@ -26,7 +26,9 @@ #include "pthread.h" #include "implement.h" -#include +#ifndef _UWIN +# include +#endif void pthread_exit (void *value_ptr) @@ -62,6 +64,10 @@ pthread_exit (void *value_ptr) */ self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey); +#ifdef _UWIN + if(--pthread_count <= 0) + exit((int)value_ptr); +#endif if (self == NULL || self->implicit) { diff --git a/global.c b/global.c index 920f556..9291949 100644 --- a/global.c +++ b/global.c @@ -51,3 +51,10 @@ CRITICAL_SECTION ptw32_cond_test_init_lock; * created read/write locks. */ CRITICAL_SECTION ptw32_rwlock_test_init_lock; + +#ifdef _UWIN +/* + * Keep a count of the number of threads. + */ +int pthread_count = 0; +#endif diff --git a/implement.h b/implement.h index 0df0e4c..da094c8 100644 --- a/implement.h +++ b/implement.h @@ -71,6 +71,9 @@ typedef enum { PThreadDemise; struct pthread_t_ { +#ifdef _UWIN + DWORD dummy[5]; +#endif DWORD thread; HANDLE threadH; PThreadState state; @@ -331,6 +334,9 @@ extern CRITICAL_SECTION ptw32_mutex_test_init_lock; extern CRITICAL_SECTION ptw32_cond_test_init_lock; extern CRITICAL_SECTION ptw32_rwlock_test_init_lock; +#ifdef _UWIN +extern int pthread_count; +#endif /* Declared in misc.c */ #ifdef NEED_CALLOC @@ -391,6 +397,25 @@ BOOL ptw32_increase_semaphore(sem_t * sem, #endif /* __cplusplus */ +#ifdef _UWIN_ +# ifdef _MT +# ifdef __cplusplus + 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); +# ifdef __cplusplus + } +# endif +# endif +#else +# include +#endif + /* * Check for old and new versions of cygwin. See the FAQ file: * diff --git a/misc.c b/misc.c index 0545e5c..fffbcde 100644 --- a/misc.c +++ b/misc.c @@ -144,6 +144,11 @@ pthread_self (void) { pthread_t self; +#ifdef _UWIN + if(!ptw32_selfThreadKey) + return(NULL); +#endif + self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey); if (self == NULL) diff --git a/nonportable.c b/nonportable.c index 404d831..150b0c0 100644 --- a/nonportable.c +++ b/nonportable.c @@ -101,7 +101,6 @@ pthread_getw32threadhandle_np(pthread_t thread) * tsWait.tv_nsec = 500000000L; * intRC = pthread_delay_np(&tsWait); */ - int pthread_delay_np (struct timespec * interval) { @@ -141,6 +140,9 @@ pthread_win32_process_attach_np () BOOL result = TRUE; result = ptw32_processInitialize (); +#ifdef _UWIN + pthread_count++; +#endif return result; } diff --git a/private.c b/private.c index ecae84a..a9953c9 100644 --- a/private.c +++ b/private.c @@ -24,7 +24,9 @@ * MA 02111-1307, USA */ -#include +#ifndef _UWIN +# include +#endif #ifndef NEED_FTIME #include #endif @@ -278,6 +280,11 @@ ptw32_threadStart (void * vthreadParms) * Run the caller's routine; */ status = self->exitStatus = (*start) (arg); +#ifdef _UWIN + if (--pthread_count <= 0) + exit(0); +#endif + } __except (ExceptionFilter(GetExceptionInformation(), ei)) { @@ -285,6 +292,10 @@ ptw32_threadStart (void * vthreadParms) { case PTW32_EPS_CANCEL: status = PTHREAD_CANCELED; +#ifdef _UWIN + if (--pthread_count <= 0) + exit(0); +#endif break; case PTW32_EPS_EXIT: status = self->exitStatus; diff --git a/pthread.h b/pthread.h index bf9e970..d4cfd13 100644 --- a/pthread.h +++ b/pthread.h @@ -22,6 +22,13 @@ #if !defined( PTHREAD_H ) #define PTHREAD_H +#ifdef _UWIN +# define HAVE_STRUCT_TIMESPEC 1 +# define HAVE_SIGNAL_H 1 +# undef HAVE_CONFIG_H +# pragma comment(lib, "pthread") +#endif + /* * ------------------------------------------------------------- * @@ -304,6 +311,9 @@ extern "C" #define PTHREAD_THREADS_MAX 2019 +#ifdef _UWIN +# include +#else typedef struct pthread_t_ *pthread_t; typedef struct pthread_attr_t_ *pthread_attr_t; typedef struct pthread_once_t_ pthread_once_t; @@ -312,6 +322,7 @@ typedef struct pthread_mutex_t_ *pthread_mutex_t; typedef struct pthread_mutexattr_t_ *pthread_mutexattr_t; typedef struct pthread_cond_t_ *pthread_cond_t; typedef struct pthread_condattr_t_ *pthread_condattr_t; +#endif typedef struct pthread_rwlock_t_ *pthread_rwlock_t; typedef struct pthread_rwlockattr_t_ *pthread_rwlockattr_t; @@ -853,6 +864,7 @@ int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout); /* * Thread-Safe C Runtime Library Mappings. */ +#ifndef _UWIN #if 1 #if (! defined(HAVE_ERRNO)) && (! defined(_REENTRANT)) && (! defined(_MT)) int * _errno( void ); @@ -866,6 +878,7 @@ int * _errno( void ); #endif #endif #endif +#endif /* * WIN32 C runtime library had been made thread-safe -- cgit v1.2.3