diff options
| author | rpj <rpj> | 1999-01-12 14:48:53 +0000 | 
|---|---|---|
| committer | rpj <rpj> | 1999-01-12 14:48:53 +0000 | 
| commit | bc374000d4dda28009ceb1f03a5514687be8904c (patch) | |
| tree | ed0423713c55ec8c5fcd7ea801edbda62bef6ab7 | |
| parent | 66f7d3aafbde9b4f628dcdc23c7f59b28d86760b (diff) | |
Wed Jan 13 09:34:52 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au>
        * build.bat: Delete old binaries before compiling/linking.
Tue Jan 12 09:58:38 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au>
        * dll.c: The Microsoft compiler pragmas probably are more
        appropriately protected by _MSC_VER than by _WIN32.
        - Tor Lillqvist <tml@iki.fi>.
        * condvar.c (pthread_cond_timedwait): Fix function description
        comments.
        * pthread.h: Define ETIMEDOUT. This should be returned by
        pthread_cond_timedwait which is not implemented yet as of
        snapshot-1999-01-04-1305. It was implemented in the older version.
        The Microsoft compiler pragmas probably are more appropriately
        protected by _MSC_VER than by _WIN32.
        - Tor Lillqvist <tml@iki.fi>.
        * pthread.def: pthread_mutex_destroy was missing from the def file
        - Tor Lillqvist <tml@iki.fi>.
        * condvar.c (pthread_cond_broadcast): Ensure we only wait on threads
        if there were any waiting on the condition.
        I think pthread_cond_broadcast should do the WaitForSingleObject
        only if cv->waiters > 0? Otherwise it seems to hang, at least in the
        testg thread program from glib.
        - Tor Lillqvist <tml@iki.fi>.
        * semaphore.c (sem_post): Correct typo in comment.
Mon Jan 11 20:33:19 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au>
        * pthread.h: Re-arrange conditional compile of pthread_cleanup-*
        macros.
        * cleanup.c (_pthread_push_cleanup): Provide conditional
        compile of cleanup->prev.
| -rw-r--r-- | ChangeLog | 41 | ||||
| -rw-r--r-- | build.bat | 2 | ||||
| -rw-r--r-- | cleanup.c | 9 | ||||
| -rw-r--r-- | condvar.c | 46 | ||||
| -rw-r--r-- | dll.c | 2 | ||||
| -rw-r--r-- | private.c | 37 | ||||
| -rw-r--r-- | pthread.def | 3 | ||||
| -rw-r--r-- | pthread.h | 52 | ||||
| -rw-r--r-- | semaphore.c | 6 | 
9 files changed, 158 insertions, 40 deletions
| @@ -1,7 +1,48 @@ +Wed Jan 13 09:34:52 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> + +	* build.bat: Delete old binaries before compiling/linking. + +Tue Jan 12 09:58:38 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> + +	* dll.c: The Microsoft compiler pragmas probably are more +	appropriately protected by _MSC_VER than by _WIN32. +	- Tor Lillqvist <tml@iki.fi>. + +	* condvar.c (pthread_cond_timedwait): Fix function description +	comments. + +	* pthread.h: Define ETIMEDOUT. This should be returned by +	pthread_cond_timedwait which is not implemented yet as of +	snapshot-1999-01-04-1305. It was implemented in the older version. +	The Microsoft compiler pragmas probably are more appropriately +	protected by _MSC_VER than by _WIN32. +	- Tor Lillqvist <tml@iki.fi>. + +	* pthread.def: pthread_mutex_destroy was missing from the def file +	- Tor Lillqvist <tml@iki.fi>. + +	* condvar.c (pthread_cond_broadcast): Ensure we only wait on threads +	if there were any waiting on the condition. +	I think pthread_cond_broadcast should do the WaitForSingleObject +	only if cv->waiters > 0? Otherwise it seems to hang, at least in the +	testg thread program from glib. +	- Tor Lillqvist <tml@iki.fi>.  + +	* semaphore.c (sem_post): Correct typo in comment. + +Mon Jan 11 20:33:19 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> + +	* pthread.h: Re-arrange conditional compile of pthread_cleanup-* +	macros. + +	* cleanup.c (_pthread_push_cleanup): Provide conditional  +	compile of cleanup->prev. +  1999-01-11  Ben Elliston  <bje@cygnus.com>  	* condvar.c (pthread_cond_init): Invert logic when testing the  	return value from calloc(). +	- Tor Lillqvist <tml@iki.fi>.  Sat Jan  9 14:32:08 1999  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> @@ -1,2 +1,4 @@ +del aout.exe +del %1.obj  cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c %1.c  cl /Feaout.exe /Zi %1.obj pthread.lib @@ -102,7 +102,11 @@ _pthread_pop_cleanup (int execute)          } +#if !defined(_WIN32) && !defined(_cplusplus) +        pthread_setspecific (_pthread_cleanupKey, cleanup->prev); + +#endif      }    return (cleanup); @@ -156,8 +160,13 @@ _pthread_push_cleanup (_pthread_cleanup_t * cleanup,  {    cleanup->routine = routine;    cleanup->arg = arg; + +#if !defined(_WIN32) && !defined(_cplusplus) +    cleanup->prev = pthread_getspecific (_pthread_cleanupKey); +#endif +    pthread_setspecific (_pthread_cleanupKey, (void *) cleanup);  }                               /* _pthread_push_cleanup */ @@ -543,20 +543,37 @@ pthread_cond_timedwait (pthread_cond_t * cond,        *      initial value of the semaphore is 'value'        *        * PARAMETERS -      *      sem -      *              pointer to an instance of sem_t +      *      cond +      *              pointer to an instance of pthread_cond_t +      * +      *      mutex +      *              pointer to an instance of pthread_mutex_t +      * +      *      abstime +      *              pointer to an instance of (const struct timespec)        *        *        * DESCRIPTION -      *      This function  initializes an unnamed semaphore. The -      *      initial value of the semaphore is set to 'value'. +      *      This function waits on a condition variable either until +      *      awakened by a signal or broadcast; or until the time +      *      specified by abstime passes. +      * +      *      NOTES: +      *      1)      The function must be called with 'mutex' LOCKED +      *               by the calling thread, or undefined behaviour +      *              will result. +      * +      *      2)      This routine atomically releases 'mutex' and causes +      *              the calling thread to block on the condition variable. +      *              The blocked thread may be awakened by  +      *                      pthread_cond_signal or  +      *                      pthread_cond_broadcast.        *        * RESULTS -      *              0               successfully created semaphore, -      *              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 +      *              0               caught condition; mutex released, +      *              EINVAL          'cond' or 'mutex' is invalid, +      *              EINVAL          different mutexes for concurrent waits, +      *              EINVAL          mutex is not held by the calling thread,        *        * ------------------------------------------------------        */ @@ -636,13 +653,13 @@ pthread_cond_broadcast (pthread_cond_t * cond)        *      waking all current waiters.        *        * PARAMETERS -      *      sem +      *      cond        *              pointer to an instance of pthread_cond_t        *        *        * DESCRIPTION -      *      This function  initializes an unnamed semaphore. The -      *      initial value of the semaphore is set to 'value'. +      *      This function signals a condition variable, waking +      *      all waiting threads.        *        *      NOTES:        *      1)      This function MUST be called under the protection @@ -657,7 +674,8 @@ pthread_cond_broadcast (pthread_cond_t * cond)        *              not be able to respond        *        * RESULTS -      *              0               successfully created semaphore, +      *              0               successfully signalled condition to all +      *                              waiting threads,        *              EINVAL          'cond' is invalid        *              ENOSPC          a required resource has been exhausted,        * @@ -679,7 +697,7 @@ pthread_cond_broadcast (pthread_cond_t * cond)        result = sem_post (&(cv->sema));      } -  if (result == 0) +  if (cv->waiters > 0 && result == 0)      {        /*         * Wait for all the awakened threads to acquire their part of @@ -16,7 +16,7 @@ BOOL (WINAPI *_pthread_try_enter_critical_section)(LPCRITICAL_SECTION) = NULL;  /* Handle to kernel32.dll */  static HINSTANCE _pthread_h_kernel32; -#ifdef _WIN32 +#ifdef _MSC_VER  /*    * lpvReserved yields an unreferenced formal parameter;   * ignore it @@ -121,6 +121,8 @@ _pthread_threadStart (ThreadParms * threadParms)    pthread_setspecific (_pthread_selfThreadKey, tid); +#ifdef _WIN32 +    __try    {      /* @@ -138,6 +140,41 @@ _pthread_threadStart (ThreadParms * threadParms)      status = -1;    } +#else /* _WIN32 */ + +#ifdef __cplusplus + +  try +  { +    /* +     * Run the caller's routine; +     */ +    (*start) (arg); +    status = 0; +  } +  catch (...) +  { +    /* +     * A system unexpected exception had occurred running the user's +     * routine. We get control back within this block. +     */ +    status = -1; +  } + +#else /* __cplusplus */ + +#error Warning: Compile __FILE__ as C++ or thread cancellation will not work. + +  /* +   * Run the caller's routine; +   */ +  (*start) (arg); +  status = 0; + +#endif /* __cplusplus */ + +#endif /* _WIN32 */ +    pthread_exit ((void *) status);    return ((void *) status); diff --git a/pthread.def b/pthread.def index bd294b9..3f68e5c 100644 --- a/pthread.def +++ b/pthread.def @@ -1,5 +1,5 @@  ; pthread.def -; Last updated: $Date: 1999/01/03 18:48:06 $ +; Last updated: $Date: 1999/01/12 14:48:59 $  ; Currently unimplemented functions are commented out. @@ -56,6 +56,7 @@ pthread_mutexattr_init  ;pthread_mutexattr_setpshared  pthread_mutexattr_destroy  pthread_mutex_init +pthread_mutex_destroy  pthread_mutex_lock  pthread_mutex_trylock  pthread_mutex_unlock @@ -174,7 +174,7 @@  #if !defined( PTHREAD_H )  #define PTHREAD_H -#ifdef _WIN32 +#ifdef _MSC_VER  /*   * Disable following warnings when including Windows headers   * @@ -229,6 +229,12 @@ struct timespec {  #include <errno.h>  #ifdef _WIN32 +#ifndef ETIMEDOUT +#define ETIMEDOUT 19981220     /* Let's hope this is unique */ +#endif +#endif /* _WIN32 */ + +#ifdef _MSC_VER  /*   * Re-enable all but 4127, 4514   */ @@ -644,29 +650,11 @@ struct pthread_once_t_ {      {        void (*routine) (void *);        void *arg; -#if !defined(__cplusplus) +#if !defined(_WIN32) && !defined(__cplusplus)        _pthread_cleanup_t *prev;  #endif      }; -#ifndef __cplusplus - -/* - * C implementation of PThreads cancel cleanup - */ - -#define pthread_cleanup_push( _rout, _arg ) \ -	{ \ -	    _pthread_cleanup_t	_cleanup; \ -            \ -	    _pthread_push_cleanup( &_cleanup, (_rout), (_arg) ); \ - -#define pthread_cleanup_pop( _execute ) \ -	    (void) _pthread_pop_cleanup( _execute ); \ -	} - -#else /* !__cplusplus */ -  #ifdef _WIN32  	/*  	 * WIN32 SEH version of cancel cleanup. @@ -694,6 +682,24 @@ struct pthread_once_t_ {  #else /* _WIN32 */ +#ifndef __cplusplus + +	/* +	 * C implementation of PThreads cancel cleanup +	 */ + +#define pthread_cleanup_push( _rout, _arg ) \ +	{ \ +	    _pthread_cleanup_t	_cleanup; \ +            \ +	    _pthread_push_cleanup( &_cleanup, (_rout), (_arg) ); \ + +#define pthread_cleanup_pop( _execute ) \ +	    (void) _pthread_pop_cleanup( _execute ); \ +	} + +#else /* !__cplusplus */ +  	/*  	 * C++ (ie. Cygwin32 or Mingw32) version of cancel cleanup.  	 * @@ -783,13 +789,15 @@ pthread_t pthread_self (void);  int pthread_cancel (pthread_t thread); -#ifndef __cplusplus +#if !defined(__cplusplus) && !defined(_WIN32) +  _pthread_cleanup_t *_pthread_pop_cleanup (int execute);  void _pthread_push_cleanup (_pthread_cleanup_t * cleanup,  			   void (*routine) (void *),  			   void *arg); -#endif /* !__cplusplus */ + +#endif /* !__cplusplus && ! _WIN32 */  int pthread_setcancelstate (int state,  			    int *oldstate); diff --git a/semaphore.c b/semaphore.c index c163336..8ab326b 100644 --- a/semaphore.c +++ b/semaphore.c @@ -234,11 +234,11 @@ sem_post (sem_t * sem)        *        * DESCRIPTION        *      This function posts a wakeup to a semaphore. If there -      *      are waiting threads (or processes), on is awakened; +      *      are waiting threads (or processes), one is awakened;        *      otherwise, the semaphore value is incremented by one.        *        * RESULTS -      *              0                       successfully destroyed semaphore, +      *              0               successfully destroyed semaphore,        *              EINVAL          'sem' is not a valid semaphore,        *              ENOSYS          semaphores are not supported,        * @@ -252,3 +252,5 @@ sem_post (sem_t * sem)  	     : EINVAL));  }				/* sem_post */ + + | 
