summaryrefslogtreecommitdiff
path: root/pthread.h
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-05 11:57:32 +0000
committerrpj <rpj>2001-07-05 11:57:32 +0000
commit99e8ecc5759668fd3af379eaddd70b4ae50ecd7f (patch)
tree8b824cc1eb8de6fd15a4b5636f5f62fa95541105 /pthread.h
parent861a8bb5523f257b474f68334c2c5300e52c5371 (diff)
Added new routines from POSIX 1003.1j. This is alpha level code.
* spin.c: New module implementing spin locks. * barrier.c: New module implementing barriers. * pthread.h (_POSIX_SPIN_LOCKS): defined. (_POSIX_BARRIERS): Defined. (pthread_spin_*): Defined. (pthread_barrier*): Defined. (PTHREAD_BARRIER_SERIAL_THREAD): Defined. * implement.h (pthread_spinlock_t_): Defined. (pthread_barrier_t_): Defined. (pthread_barrierattr_t_): Defined. * mutex.c (pthread_mutex_lock): Return with the error if an auto-initialiser initialisation fails. * nonportable.c (pthread_getprocessors_np): New; gets the number of available processors for the current process.
Diffstat (limited to 'pthread.h')
-rw-r--r--pthread.h89
1 files changed, 87 insertions, 2 deletions
diff --git a/pthread.h b/pthread.h
index 8675c56..ca36b8b 100644
--- a/pthread.h
+++ b/pthread.h
@@ -265,6 +265,19 @@ extern "C"
* Maximum number of threads supported per
* process (must be at least 64).
*
+ *
+ * POSIX 1003.1j/D10-1999 Options
+ * ==============================
+ *
+ * _POSIX_READER_WRITER_LOCKS (set)
+ * If set, you can use read/write locks
+ *
+ * _POSIX_SPIN_LOCKS (set)
+ * If set, you can use spin locks
+ *
+ * _POSIX_BARRIERS (set)
+ * If set, you can use barriers
+ *
* -------------------------------------------------------------
*/
@@ -275,6 +288,18 @@ extern "C"
#define _POSIX_THREADS
#endif
+#ifndef _POSIX_READER_WRITER_LOCKS
+#define _POSIX_READER_WRITER_LOCKS
+#endif
+
+#ifndef _POSIX_SPIN_LOCKS
+#define _POSIX_SPIN_LOCKS
+#endif
+
+#ifndef _POSIX_BARRIERS
+#define _POSIX_BARRIERS
+#endif
+
#define _POSIX_THREAD_SAFE_FUNCTIONS
#define _POSIX_THREAD_ATTR_STACKSIZE
#define _POSIX_THREAD_PRIORITY_SCHEDULING
@@ -336,7 +361,8 @@ 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;
+typedef struct pthread_barrier_t_ *pthread_barrier_t;
/*
* ====================
@@ -382,7 +408,12 @@ enum {
* pthread_condattr_{get,set}pshared
*/
PTHREAD_PROCESS_PRIVATE = 0,
- PTHREAD_PROCESS_SHARED = 1
+ PTHREAD_PROCESS_SHARED = 1,
+
+/*
+ * pthread_barrier_wait
+ */
+ PTHREAD_BARRIER_SERIAL_THREAD = -1
};
/*
@@ -412,12 +443,23 @@ struct pthread_once_t_
};
+/*
+ * ====================
+ * ====================
+ * Object initialisers
+ * ====================
+ * ====================
+ */
#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
+#define PTHREAD_SPINLOCK_INITIALIZER {1}
+
+#define PTHREAD_BARRIER_INITIALIZER ((pthread_barrier_t) -1)
+
enum
{
PTHREAD_MUTEX_FAST_NP,
@@ -743,6 +785,20 @@ int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
int pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
/*
+ * Barrier Attribute Functions
+ */
+int pthread_barrierattr_init (pthread_barrierattr_t * attr);
+
+int pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
+
+int pthread_barrierattr_getpshared (const pthread_barrierattr_t
+ * attr,
+ int *pshared);
+
+int pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
+ int pshared);
+
+/*
* Mutex Functions
*/
int pthread_mutex_init (pthread_mutex_t * mutex,
@@ -757,6 +813,30 @@ int pthread_mutex_trylock (pthread_mutex_t * mutex);
int pthread_mutex_unlock (pthread_mutex_t * mutex);
/*
+ * Spinlock Functions
+ */
+int pthread_spin_init (pthread_spinlock_t * lock);
+
+int pthread_spin_destroy (pthread_spinlock_t * lock);
+
+int pthread_spin_lock (pthread_spinlock_t * lock);
+
+int pthread_spin_trylock (pthread_spinlock_t * lock);
+
+int pthread_spin_unlock (pthread_spinlock_t * lock);
+
+/*
+ * Barrier Functions
+ */
+int pthread_barrier_init (pthread_barrier_t * barrier,
+ const pthread_barrierattr_t * attr,
+ int count);
+
+int pthread_barrier_destroy (pthread_barrier_t * barrier);
+
+int pthread_barrier_wait (pthread_barrier_t * barrier);
+
+/*
* Condition Variable Attribute Functions
*/
int pthread_condattr_init (pthread_condattr_t * attr);
@@ -843,6 +923,11 @@ int pthread_delay_np (struct timespec * interval);
HANDLE pthread_getw32threadhandle_np(pthread_t thread);
/*
+ * Returns the number of CPUs available to the process.
+ */
+int pthread_getprocessors_np(int * count);
+
+/*
* Useful if an application wants to statically link
* the lib rather than load the DLL at run-time.
*/