summaryrefslogtreecommitdiff
path: root/libs/pthreads/src/pthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pthreads/src/pthread.h')
-rw-r--r--libs/pthreads/src/pthread.h632
1 files changed, 246 insertions, 386 deletions
diff --git a/libs/pthreads/src/pthread.h b/libs/pthreads/src/pthread.h
index 32ff72bb54..2d96d90177 100644
--- a/libs/pthreads/src/pthread.h
+++ b/libs/pthreads/src/pthread.h
@@ -1,45 +1,38 @@
-/* This is an implementation of the threads API of POSIX 1003.1-2001.
+/* This is an implementation of the threads API of the Single Unix Specification.
*
* --------------------------------------------------------------------------
*
- * Pthreads-win32 - POSIX Threads Library for Win32
+ * Pthreads4w - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
+ * Copyright(C) 1999-2018, Pthreads4w contributors
+ *
+ * Homepage: https://sourceforge.net/projects/pthreads4w/
+ *
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
* following World Wide Web location:
- * http://sources.redhat.com/pthreads-win32/contributors.html
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
+ *
+ * This file is part of Pthreads4w.
+ *
+ * Pthreads4w is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pthreads4w is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pthreads4w. If not, see <http://www.gnu.org/licenses/>. *
*/
#if !defined( PTHREAD_H )
#define PTHREAD_H
-/*
- * See the README file for an explanation of the pthreads-win32 version
- * numbering scheme and how the DLL is named etc.
- */
-#define PTW32_VERSION 2,9,1,0
-#define PTW32_VERSION_STRING "2, 9, 1, 0\0"
-
/* There are three implementations of cancel cleanup.
* Note that pthread.h is included in both application
* compilation units and also internally for the library.
@@ -65,7 +58,7 @@
* Define defaults for cleanup code.
* Note: Unless the build explicitly defines one of the following, then
* we default to standard C style cleanup. This style uses setjmp/longjmp
- * in the cancelation and thread exit implementations and therefore won't
+ * in the cancellation and thread exit implementations and therefore won't
* do stack unwinding if linked to applications that have it (e.g.
* C++ apps). This is currently consistent with most/all commercial Unix
* POSIX threads implementations.
@@ -78,42 +71,31 @@
#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.
#endif
+#include <_ptw32.h>
+
/*
* Stop here if we are being included by the resource compiler.
*/
#if !defined(RC_INVOKED)
-#undef PTW32_LEVEL
+#undef __PTW32_LEVEL
+#undef __PTW32_LEVEL_MAX
+#define __PTW32_LEVEL_MAX 3
-#if defined(_POSIX_SOURCE)
-#define PTW32_LEVEL 0
-/* Early POSIX */
-#endif
+#if _POSIX_C_SOURCE >= 200112L /* POSIX.1-2001 and later */
+# define __PTW32_LEVEL __PTW32_LEVEL_MAX /* include everything */
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 1
-/* Include 1b, 1c and 1d */
-#endif
+#elif defined INCLUDE_NP /* earlier than POSIX.1-2001, but... */
+# define __PTW32_LEVEL 2 /* include non-portable extensions */
-#if defined(INCLUDE_NP)
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 2
-/* Include Non-Portable extensions */
-#endif
+#elif _POSIX_C_SOURCE >= 199309L /* POSIX.1-1993 */
+# define __PTW32_LEVEL 1 /* include 1b, 1c, and 1d */
-#define PTW32_LEVEL_MAX 3
-
-#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL)
-#define PTW32_LEVEL PTW32_LEVEL_MAX
-/* Include everything */
-#endif
+#elif defined _POSIX_SOURCE /* early POSIX */
+# define __PTW32_LEVEL 0 /* minimal support */
-#if defined(_UWIN)
-# define HAVE_STRUCT_TIMESPEC 1
-# define HAVE_SIGNAL_H 1
-# undef HAVE_PTW32_CONFIG_H
-# pragma comment(lib, "pthread")
+#else /* unspecified support level */
+# define __PTW32_LEVEL __PTW32_LEVEL_MAX /* include everything anyway */
#endif
/*
@@ -184,191 +166,47 @@
* The source code and other information about this library
* are available from
*
- * http://sources.redhat.com/pthreads-win32/
+ * https://sourceforge.net/projects/pthreads4w//
*
* -------------------------------------------------------------
*/
-
-/* Try to avoid including windows.h */
-#if (defined(__MINGW64__) || defined(__MINGW32__)) && defined(__cplusplus)
-#define PTW32_INCLUDE_WINDOWS_H
-#endif
-
-#if defined(PTW32_INCLUDE_WINDOWS_H)
-#include <windows.h>
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__)
-/*
- * VC++6.0 or early compiler's header has no DWORD_PTR type.
- */
-typedef unsigned long DWORD_PTR;
-typedef unsigned long ULONG_PTR;
-#endif
-/*
- * -----------------
- * autoconf switches
- * -----------------
- */
-
-#if defined(HAVE_PTW32_CONFIG_H)
-#include "config.h"
-#endif /* HAVE_PTW32_CONFIG_H */
-
-#if !defined(NEED_FTIME)
-#include <time.h>
-#else /* NEED_FTIME */
-/* use native WIN32 time API */
-#endif /* NEED_FTIME */
-
-#if defined(HAVE_SIGNAL_H)
-#include <signal.h>
-#endif /* HAVE_SIGNAL_H */
-
-#include <limits.h>
-
-/*
- * Boolean values to make us independent of system includes.
- */
-enum {
+enum
+{ /* Boolean values to make us independent of system includes. */
PTW32_FALSE = 0,
PTW32_TRUE = (! PTW32_FALSE)
};
-/*
- * This is a duplicate of what is in the autoconf config.h,
- * which is only used when building the pthread-win32 libraries.
- */
-
-#if !defined(PTW32_CONFIG_H)
-# if defined(WINCE)
-# define NEED_ERRNO
-# define NEED_SEM
-# endif
-# if defined(_MSC_VER) || defined(__MINGW64__)
-# define HAVE_STRUCT_TIMESPEC
-# define HAVE_MODE_T
-# elif defined(_UWIN) || defined(__MINGW32__)
-# define HAVE_MODE_T
-# endif
-#endif
-
-/*
- *
- */
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-#if defined(NEED_ERRNO)
-#include "need_errno.h"
-#else
-#include <errno.h>
-#endif
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-/*
- * Several systems don't define some error numbers.
- */
-#if !defined(ENOTSUP)
-# define ENOTSUP 48 /* This is the value in Solaris. */
-#endif
-
-#if !defined(ETIMEDOUT)
-# define ETIMEDOUT 10060 /* Same as WSAETIMEDOUT */
-#endif
-
-#if !defined(ENOSYS)
-# define ENOSYS 140 /* Semi-arbitrary value */
-#endif
-
-#if !defined(EDEADLK)
-# if defined(EDEADLOCK)
-# define EDEADLK EDEADLOCK
-# else
-# define EDEADLK 36 /* This is the value in MSVC. */
-# endif
-#endif
-
-/* POSIX 2008 - related to robust mutexes */
-#if !defined(EOWNERDEAD)
-# define EOWNERDEAD 43
-#endif
-#if !defined(ENOTRECOVERABLE)
-# define ENOTRECOVERABLE 44
-#endif
-
+#include <time.h>
#include <sched.h>
/*
- * To avoid including windows.h we define only those things that we
- * actually need from it.
- */
-#if !defined(PTW32_INCLUDE_WINDOWS_H)
-#if !defined(HANDLE)
-# define PTW32__HANDLE_DEF
-# define HANDLE void *
-#endif
-#if !defined(DWORD)
-# define PTW32__DWORD_DEF
-# define DWORD unsigned long
-#endif
-#endif
-
-#if !defined(HAVE_STRUCT_TIMESPEC)
-#define HAVE_STRUCT_TIMESPEC
-#if !defined(_TIMESPEC_DEFINED)
-#define _TIMESPEC_DEFINED
-struct timespec {
- time_t tv_sec;
- long tv_nsec;
-};
-#endif /* _TIMESPEC_DEFINED */
-#endif /* HAVE_STRUCT_TIMESPEC */
-
-#if !defined(SIG_BLOCK)
-#define SIG_BLOCK 0
-#endif /* SIG_BLOCK */
-
-#if !defined(SIG_UNBLOCK)
-#define SIG_UNBLOCK 1
-#endif /* SIG_UNBLOCK */
-
-#if !defined(SIG_SETMASK)
-#define SIG_SETMASK 2
-#endif /* SIG_SETMASK */
-
-#if defined(__cplusplus)
-extern "C"
-{
-#endif /* __cplusplus */
-
-/*
* -------------------------------------------------------------
*
* POSIX 1003.1-2001 Options
* =========================
*
* Options are normally set in <unistd.h>, which is not provided
- * with pthreads-win32.
+ * with Pthreads4w.
*
* For conformance with the Single Unix Specification (version 3), all of the
* options below are defined, and have a value of either -1 (not supported)
- * or 200112L (supported).
+ * or yyyymm[dd]L (supported).
*
* These options can neither be left undefined nor have a value of 0, because
* either indicates that sysconf(), which is not implemented, may be used at
* runtime to check the status of the option.
*
- * _POSIX_THREADS (== 200112L)
- * If == 200112L, you can use threads
+ * _POSIX_THREADS (== 20080912L)
+ * If == 20080912L, you can use threads
*
- * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L)
- * If == 200112L, you can control the size of a thread's
+ * _POSIX_THREAD_ATTR_STACKSIZE (== 200809L)
+ * If == 200809L, you can control the size of a thread's
* stack
* pthread_attr_getstacksize
* pthread_attr_setstacksize
*
* _POSIX_THREAD_ATTR_STACKADDR (== -1)
- * If == 200112L, you can allocate and control a thread's
+ * If == 200809L, you can allocate and control a thread's
* stack. If not supported, the following functions
* will return ENOSYS, indicating they are not
* supported:
@@ -383,13 +221,13 @@ extern "C"
* writers over readers when threads have equal priority.
*
* _POSIX_THREAD_PRIO_INHERIT (== -1)
- * If == 200112L, you can create priority inheritance
+ * If == 200809L, you can create priority inheritance
* mutexes.
* pthread_mutexattr_getprotocol +
* pthread_mutexattr_setprotocol +
*
* _POSIX_THREAD_PRIO_PROTECT (== -1)
- * If == 200112L, you can create priority ceiling mutexes
+ * If == 200809L, you can create priority ceiling mutexes
* Indicates the availability of:
* pthread_mutex_getprioceiling
* pthread_mutex_setprioceiling
@@ -408,22 +246,24 @@ extern "C"
* pthread_condattr_getpshared
* pthread_condattr_setpshared
*
- * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L)
- * If == 200112L you can use the special *_r library
+ * _POSIX_THREAD_SAFE_FUNCTIONS (== 200809L)
+ * If == 200809L you can use the special *_r library
* functions that provide thread-safe behaviour
*
- * _POSIX_READER_WRITER_LOCKS (== 200112L)
- * If == 200112L, you can use read/write locks
+ * _POSIX_READER_WRITER_LOCKS (== 200809L)
+ * If == 200809L, you can use read/write locks
*
- * _POSIX_SPIN_LOCKS (== 200112L)
- * If == 200112L, you can use spin locks
+ * _POSIX_SPIN_LOCKS (== 200809L)
+ * If == 200809L, you can use spin locks
*
- * _POSIX_BARRIERS (== 200112L)
- * If == 200112L, you can use barriers
+ * _POSIX_BARRIERS (== 200809L)
+ * If == 200809L, you can use barriers
*
- * + These functions provide both 'inherit' and/or
- * 'protect' protocol, based upon these macro
- * settings.
+ * _POSIX_ROBUST_MUTEXES (== 200809L)
+ * If == 200809L, you can use robust mutexes
+ * Officially this should also imply
+ * _POSIX_THREAD_PROCESS_SHARED != -1 however
+ * not here yet.
*
* -------------------------------------------------------------
*/
@@ -431,42 +271,45 @@ extern "C"
/*
* POSIX Options
*/
-#undef _POSIX_THREADS
-#define _POSIX_THREADS 200809L
+#undef _POSIX_THREADS
+#define _POSIX_THREADS 200809L
+
+#undef _POSIX_READER_WRITER_LOCKS
+#define _POSIX_READER_WRITER_LOCKS 200809L
-#undef _POSIX_READER_WRITER_LOCKS
-#define _POSIX_READER_WRITER_LOCKS 200809L
+#undef _POSIX_SPIN_LOCKS
+#define _POSIX_SPIN_LOCKS 200809L
-#undef _POSIX_SPIN_LOCKS
-#define _POSIX_SPIN_LOCKS 200809L
+#undef _POSIX_BARRIERS
+#define _POSIX_BARRIERS 200809L
-#undef _POSIX_BARRIERS
-#define _POSIX_BARRIERS 200809L
+#undef _POSIX_THREAD_SAFE_FUNCTIONS
+#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
-#undef _POSIX_THREAD_SAFE_FUNCTIONS
-#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
+#undef _POSIX_THREAD_ATTR_STACKSIZE
+#define _POSIX_THREAD_ATTR_STACKSIZE 200809L
-#undef _POSIX_THREAD_ATTR_STACKSIZE
-#define _POSIX_THREAD_ATTR_STACKSIZE 200809L
+#undef _POSIX_ROBUST_MUTEXES
+#define _POSIX_ROBUST_MUTEXES 200809L
/*
* The following options are not supported
*/
-#undef _POSIX_THREAD_ATTR_STACKADDR
-#define _POSIX_THREAD_ATTR_STACKADDR -1
+#undef _POSIX_THREAD_ATTR_STACKADDR
+#define _POSIX_THREAD_ATTR_STACKADDR -1
-#undef _POSIX_THREAD_PRIO_INHERIT
-#define _POSIX_THREAD_PRIO_INHERIT -1
+#undef _POSIX_THREAD_PRIO_INHERIT
+#define _POSIX_THREAD_PRIO_INHERIT -1
-#undef _POSIX_THREAD_PRIO_PROTECT
-#define _POSIX_THREAD_PRIO_PROTECT -1
+#undef _POSIX_THREAD_PRIO_PROTECT
+#define _POSIX_THREAD_PRIO_PROTECT -1
/* TPS is not fully supported. */
-#undef _POSIX_THREAD_PRIORITY_SCHEDULING
-#define _POSIX_THREAD_PRIORITY_SCHEDULING -1
+#undef _POSIX_THREAD_PRIORITY_SCHEDULING
+#define _POSIX_THREAD_PRIORITY_SCHEDULING -1
-#undef _POSIX_THREAD_PROCESS_SHARED
-#define _POSIX_THREAD_PROCESS_SHARED -1
+#undef _POSIX_THREAD_PROCESS_SHARED
+#define _POSIX_THREAD_PROCESS_SHARED -1
/*
@@ -474,7 +317,7 @@ extern "C"
* ===========================
*
* These limits are normally set in <limits.h>, which is not provided with
- * pthreads-win32.
+ * Pthreads4w.
*
* PTHREAD_DESTRUCTOR_ITERATIONS
* Maximum number of attempts to destroy
@@ -501,85 +344,64 @@ extern "C"
* (must be at least 32767)
*
*/
-#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
-#undef PTHREAD_DESTRUCTOR_ITERATIONS
+#undef PTHREAD_DESTRUCTOR_ITERATIONS
#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-#undef _POSIX_THREAD_KEYS_MAX
+#undef _POSIX_THREAD_KEYS_MAX
#define _POSIX_THREAD_KEYS_MAX 128
-#undef PTHREAD_KEYS_MAX
+#undef PTHREAD_KEYS_MAX
#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX
-#undef PTHREAD_STACK_MIN
+#undef PTHREAD_STACK_MIN
#define PTHREAD_STACK_MIN 0
-#undef _POSIX_THREAD_THREADS_MAX
+#undef _POSIX_THREAD_THREADS_MAX
#define _POSIX_THREAD_THREADS_MAX 64
- /* Arbitrary value */
-#undef PTHREAD_THREADS_MAX
+/* Arbitrary value */
+#undef PTHREAD_THREADS_MAX
#define PTHREAD_THREADS_MAX 2019
-#undef _POSIX_SEM_NSEMS_MAX
+#undef _POSIX_SEM_NSEMS_MAX
#define _POSIX_SEM_NSEMS_MAX 256
- /* Arbitrary value */
-#undef SEM_NSEMS_MAX
+/* Arbitrary value */
+#undef SEM_NSEMS_MAX
#define SEM_NSEMS_MAX 1024
-#undef _POSIX_SEM_VALUE_MAX
+#undef _POSIX_SEM_VALUE_MAX
#define _POSIX_SEM_VALUE_MAX 32767
-#undef SEM_VALUE_MAX
+#undef SEM_VALUE_MAX
#define SEM_VALUE_MAX INT_MAX
-#if defined(__GNUC__) && !defined(__declspec)
-# error Please upgrade your GNU compiler to one that supports __declspec.
-#endif
-
-/*
- * When building the library, you should define PTW32_BUILD so that
- * the variables/functions are exported correctly. When using the library,
- * do NOT define PTW32_BUILD, and then the variables/functions will
- * be imported correctly.
- */
-#if !defined(PTW32_STATIC_LIB)
-# if defined(PTW32_BUILD)
-# define PTW32_DLLPORT __declspec (dllexport)
-# else
-# define PTW32_DLLPORT __declspec (dllimport)
-# endif
+#if defined(_UWIN) && __PTW32_LEVEL >= __PTW32_LEVEL_MAX
+# include <sys/types.h>
#else
-# define PTW32_DLLPORT
-#endif
-
-/*
- * The Open Watcom C/C++ compiler uses a non-standard calling convention
- * that passes function args in registers unless __cdecl is explicitly specified
- * in exposed function prototypes.
+/* Generic handle type - intended to provide the lifetime-uniqueness that
+ * a simple pointer can't. It should scale for either
+ * 32 or 64 bit systems.
+ *
+ * The constraint with this approach is that applications must
+ * strictly comply with POSIX, e.g. not assume scalar type, only
+ * compare pthread_t using the API function pthread_equal(), etc.
*
- * 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 can probably define this as a null string.
- * Remember that pthread.h (this file) is used for both the DLL and application builds.
+ * Applications can use the element 'p' to compare, e.g. for sorting,
+ * but it will be up to the application to determine if handles are
+ * live or dead, or resurrected for an entirely new/different thread.
*/
-#define PTW32_CDECL __cdecl
-
-#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
-# include <sys/types.h>
+typedef struct
+{ void * p; /* Pointer to actual object */
+#if PTW32_VERSION_MAJOR > 2
+ size_t x; /* Extra information - reuse count etc */
#else
-/*
- * Generic handle type - intended to extend uniqueness beyond
- * that available with a simple pointer. It should scale for either
- * IA-32 or IA-64.
- */
-typedef struct {
- void * p; /* Pointer to actual object */
- unsigned int x; /* Extra information - reuse count etc */
+ unsigned int x; /* Extra information - reuse count etc */
+#endif
} ptw32_handle_t;
typedef ptw32_handle_t pthread_t;
@@ -591,6 +413,7 @@ 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;
typedef struct pthread_spinlock_t_ * pthread_spinlock_t;
@@ -605,60 +428,52 @@ typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;
* ====================
*/
-enum {
-/*
- * pthread_attr_{get,set}detachstate
- */
+enum
+{ /* pthread_attr_{get,set}detachstate
+ */
PTHREAD_CREATE_JOINABLE = 0, /* Default */
PTHREAD_CREATE_DETACHED = 1,
-
-/*
- * pthread_attr_{get,set}inheritsched
- */
+ /*
+ * pthread_attr_{get,set}inheritsched
+ */
PTHREAD_INHERIT_SCHED = 0,
PTHREAD_EXPLICIT_SCHED = 1, /* Default */
-
-/*
- * pthread_{get,set}scope
- */
+ /*
+ * pthread_{get,set}scope
+ */
PTHREAD_SCOPE_PROCESS = 0,
PTHREAD_SCOPE_SYSTEM = 1, /* Default */
-
-/*
- * pthread_setcancelstate paramters
- */
+ /*
+ * pthread_setcancelstate paramters
+ */
PTHREAD_CANCEL_ENABLE = 0, /* Default */
PTHREAD_CANCEL_DISABLE = 1,
-
-/*
- * pthread_setcanceltype parameters
- */
+ /*
+ * pthread_setcanceltype parameters
+ */
PTHREAD_CANCEL_ASYNCHRONOUS = 0,
PTHREAD_CANCEL_DEFERRED = 1, /* Default */
-
-/*
- * pthread_mutexattr_{get,set}pshared
- * pthread_condattr_{get,set}pshared
- */
+ /*
+ * pthread_mutexattr_{get,set}pshared
+ * pthread_condattr_{get,set}pshared
+ */
PTHREAD_PROCESS_PRIVATE = 0,
PTHREAD_PROCESS_SHARED = 1,
-
-/*
- * pthread_mutexattr_{get,set}robust
- */
+ /*
+ * pthread_mutexattr_{get,set}robust
+ */
PTHREAD_MUTEX_STALLED = 0, /* Default */
PTHREAD_MUTEX_ROBUST = 1,
-
-/*
- * pthread_barrier_wait
- */
+ /*
+ * pthread_barrier_wait
+ */
PTHREAD_BARRIER_SERIAL_THREAD = -1
};
/*
* ====================
* ====================
- * Cancelation
+ * cancellation
* ====================
* ====================
*/
@@ -672,16 +487,30 @@ enum {
* ====================
* ====================
*/
-#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0}
+#if PTW32_VERSION_MAJOR > 2
+
+#define PTHREAD_ONCE_INIT { 0, PTW32_FALSE }
struct pthread_once_t_
{
- int done; /* indicates if user function has been executed */
- void * lock;
+ void * lock; /* MCS lock */
+ int done; /* indicates if user function has been executed */
+};
+
+#else
+
+#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0 }
+
+struct pthread_once_t_
+{
+ int done; /* indicates if user function has been executed */
+ void * lock; /* MCS lock */
int reserved1;
int reserved2;
};
+#endif
+
/*
* ====================
@@ -877,6 +706,7 @@ struct ptw32_cleanup_t
#endif /* __CLEANUP_SEH */
+
/*
* ===============
* ===============
@@ -885,6 +715,8 @@ struct ptw32_cleanup_t
* ===============
*/
+__PTW32_BEGIN_C_DECLS
+
/*
* PThread Attribute Functions
*/
@@ -892,6 +724,10 @@ PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr);
PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr);
+PTW32_DLLPORT int PTW32_CDECL pthread_attr_getaffinity_np (const pthread_attr_t * attr,
+ size_t cpusetsize,
+ cpu_set_t * cpuset);
+
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr,
int *detachstate);
@@ -901,6 +737,10 @@ PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t *
PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr,
size_t * stacksize);
+PTW32_DLLPORT int PTW32_CDECL pthread_attr_setaffinity_np (pthread_attr_t * attr,
+ size_t cpusetsize,
+ const cpu_set_t * cpuset);
+
PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr,
int detachstate);
@@ -967,13 +807,13 @@ PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void);
PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control,
void (PTW32_CDECL *init_routine) (void));
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
+#if __PTW32_LEVEL >= __PTW32_LEVEL_MAX
PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute);
PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
ptw32_cleanup_callback_t routine,
void *arg);
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
+#endif /* __PTW32_LEVEL >= __PTW32_LEVEL_MAX */
/*
* Thread Specific Data Functions
@@ -1114,7 +954,7 @@ PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread,
struct sched_param *param);
PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
-
+
PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
/*
@@ -1151,7 +991,7 @@ PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwloc
PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
int pshared);
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
+#if __PTW32_LEVEL >= __PTW32_LEVEL_MAX - 1
/*
* Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
@@ -1170,6 +1010,17 @@ PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t *
int kind);
PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
int *kind);
+PTW32_DLLPORT int PTW32_CDECL pthread_timedjoin_np(pthread_t thread,
+ void **value_ptr,
+ const struct timespec *abstime);
+PTW32_DLLPORT int PTW32_CDECL pthread_tryjoin_np(pthread_t thread,
+ void **value_ptr);
+PTW32_DLLPORT int PTW32_CDECL pthread_setaffinity_np(pthread_t thread,
+ size_t cpusetsize,
+ const cpu_set_t *cpuset);
+PTW32_DLLPORT int PTW32_CDECL pthread_getaffinity_np(pthread_t thread,
+ size_t cpusetsize,
+ cpu_set_t *cpuset);
/*
* Possibly supported by other POSIX threads implementations
@@ -1188,12 +1039,22 @@ PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
/*
+ * Returns the first parameter "abstime" modified to represent the current system time.
+ * If "relative" is not NULL it represents an interval to add to "abstime".
+ */
+
+PTW32_DLLPORT struct timespec * PTW32_CDECL pthread_win32_getabstime_np(
+ struct timespec * abstime,
+ const struct timespec * relative);
+
+/*
* 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. */
+enum ptw32_features
+{
+ PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
+ PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */
};
/*
@@ -1206,25 +1067,41 @@ enum ptw32_features {
*/
PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
-#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
+#endif /* __PTW32_LEVEL >= __PTW32_LEVEL_MAX - 1 */
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
+#if __PTW32_LEVEL >= __PTW32_LEVEL_MAX
/*
* Returns the Win32 HANDLE for the POSIX thread.
*/
-PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
+PTW32_DLLPORT void * PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
/*
* Returns the win32 thread ID for POSIX thread.
*/
-PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread);
+PTW32_DLLPORT unsigned long PTW32_CDECL pthread_getw32threadid_np (pthread_t thread);
+
+/*
+ * Sets the POSIX thread name. If _MSC_VER is defined the name should be displayed by
+ * the MSVS debugger.
+ */
+#if defined(PTW32_COMPATIBILITY_BSD) || defined(PTW32_COMPATIBILITY_TRU64)
+#define PTHREAD_MAX_NAMELEN_NP 16
+PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name, void * arg);
+PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name, void * arg);
+#else
+PTW32_DLLPORT int PTW32_CDECL pthread_setname_np (pthread_t thr, const char * name);
+PTW32_DLLPORT int PTW32_CDECL pthread_attr_setname_np (pthread_attr_t * attr, const char * name);
+#endif
+
+PTW32_DLLPORT int PTW32_CDECL pthread_getname_np (pthread_t thr, char * name, int len);
+PTW32_DLLPORT int PTW32_CDECL pthread_attr_getname_np (pthread_attr_t * attr, char * name, int len);
/*
* Protected Methods
*
* This function blocks until the given WIN32 handle
- * is signaled or pthread_cancel had been called.
+ * is signalled or pthread_cancel had been called.
* This function allows the caller to hook into the
* PThreads cancel mechanism. It is implemented using
*
@@ -1235,34 +1112,26 @@ PTW32_DLLPORT DWORD PTW32_CDECL pthread_getw32threadid_np (pthread_t thread);
* argument to TimedWait is simply passed to
* WaitForMultipleObjects.
*/
-PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
-PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
- DWORD timeout);
+PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (void *waitHandle);
+PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (void *waitHandle,
+ unsigned long timeout);
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
+#endif /* __PTW32_LEVEL >= __PTW32_LEVEL_MAX */
/*
- * Thread-Safe C Runtime Library Mappings.
+ * Declare a thread-safe errno for Open Watcom
+ * (note: this has not been tested in a long time)
*/
-#if !defined(_UWIN)
-# if defined(NEED_ERRNO)
- PTW32_DLLPORT int * PTW32_CDECL _errno( void );
-# else
-# if !defined(errno)
-# if (defined(_MT) || defined(_DLL))
- __declspec(dllimport) extern int * __cdecl _errno(void);
-# define errno (*_errno())
-# endif
-# endif
+#if defined(__WATCOMC__) && !defined(errno)
+# if defined(_MT) || defined(_DLL)
+ __declspec(dllimport) extern int * __cdecl _errno(void);
+# define errno (*_errno())
# endif
#endif
-/*
- * Some compiler environments don't define some things.
- */
-#if defined(__BORLANDC__)
-# define _ftime ftime
-# define _timeb timeb
+#if defined(PTW32_USES_SEPARATE_CRT) && (defined(__CLEANUP_CXX) || defined(__CLEANUP_SEH))
+typedef void (*ptw32_terminate_handler)();
+PTW32_DLLPORT ptw32_terminate_handler PTW32_CDECL pthread_win32_set_terminate_np(ptw32_terminate_handler termFunction);
#endif
#if defined(__cplusplus)
@@ -1276,15 +1145,15 @@ class ptw32_exception_exit : public ptw32_exception {};
#endif
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
+#if __PTW32_LEVEL >= __PTW32_LEVEL_MAX
/* FIXME: This is only required if the library was built using SEH */
/*
* Get internal SEH tag
*/
-PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
+PTW32_DLLPORT unsigned long PTW32_CDECL ptw32_get_exception_services_code(void);
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
+#endif /* __PTW32_LEVEL >= __PTW32_LEVEL_MAX */
#if !defined(PTW32_BUILD)
@@ -1309,7 +1178,7 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
#if defined(_MSC_VER)
/*
* WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
- * if you want Pthread-Win32 cancelation and pthread_exit to work.
+ * if you want Pthread-Win32 cancellation and pthread_exit to work.
*/
#if !defined(PtW32NoCatchWarn)
@@ -1319,7 +1188,7 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
#pragma message("When compiling applications with MSVC++ and C++ exception handling:")
#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
-#pragma message(" cancelation and pthread_exit to work. For example:")
+#pragma message(" cancellation and pthread_exit to work. For example:")
#pragma message("")
#pragma message(" #if defined(PtW32CatchAll)")
#pragma message(" PtW32CatchAll")
@@ -1349,19 +1218,10 @@ PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
#endif /* ! PTW32_BUILD */
-#if defined(__cplusplus)
-} /* End of extern "C" */
-#endif /* __cplusplus */
-
-#if defined(PTW32__HANDLE_DEF)
-# undef HANDLE
-#endif
-#if defined(PTW32__DWORD_DEF)
-# undef DWORD
-#endif
+__PTW32_END_C_DECLS
-#undef PTW32_LEVEL
-#undef PTW32_LEVEL_MAX
+#undef __PTW32_LEVEL
+#undef __PTW32_LEVEL_MAX
#endif /* ! RC_INVOKED */