dbd39c5bada874424af2c0684ce6350c77e46015
[openafs.git] / src / WINNT / pthread / pthread.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef AFS_PTHREAD_H
11 #define AFS_PTHREAD_H
12
13 #include <windows.h>
14 #include <time.h>
15 #include <afs/errmap_nt.h>
16 #include <rx/rx_queue.h>
17
18 typedef struct {
19     int call_started;
20     int call_running;
21 } pthread_once_t;
22
23 #define PTHREAD_CREATE_JOINABLE 1
24 #define PTHREAD_CREATE_DETACHED 0
25
26 typedef struct {
27     int is_joinable;
28 } pthread_attr_t;
29
30 #define PTHREAD_KEYS_MAX 32
31
32 typedef int pthread_condattr_t;
33 typedef int pthread_mutexattr_t;
34 typedef int pthread_rwlockattr_t;
35 typedef int pthread_key_t;
36 typedef void *pthread_t;
37
38 typedef struct  timespec {
39     time_t          tv_sec;
40     long            tv_nsec;
41 } timespec_t;
42
43
44 typedef struct {
45     DWORD tid;
46     int isLocked;
47     CRITICAL_SECTION cs;
48 } pthread_mutex_t;
49
50 typedef struct cond_waiter {
51     struct rx_queue wait_queue;
52     HANDLE event;
53 } cond_waiters_t;
54  
55 typedef struct {
56     CRITICAL_SECTION cs;
57     struct rx_queue waiting_threads;
58 } pthread_cond_t;
59
60 typedef struct {
61     pthread_mutex_t write_access_mutex;
62     pthread_mutex_t read_access_completion_mutex;
63     pthread_cond_t  read_access_completion_wait;
64     int readers;
65 } pthread_rwlock_t;
66
67 #define PTHREAD_ONCE_INIT {0,1}
68
69 extern int pthread_cond_broadcast(pthread_cond_t *cond);
70 extern int pthread_cond_destroy(pthread_cond_t *cond);
71 extern int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
72 extern int pthread_cond_signal(pthread_cond_t *cond);
73 extern int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
74 extern int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
75 extern int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void *(*func)(void *), void *arg);
76 extern void *pthread_getspecific(pthread_key_t key);
77 extern int pthread_join(pthread_t target_thread, void **status);
78 extern int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value));
79 extern int pthread_key_delete(pthread_key_t key);
80
81 extern int pthread_mutex_destroy(pthread_mutex_t *mp);
82 extern int pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr);
83 extern int pthread_mutex_lock(pthread_mutex_t *mp);
84 extern int pthread_mutex_trylock(pthread_mutex_t *mp);
85 extern int pthread_mutex_unlock(pthread_mutex_t *mp);
86
87 extern int pthread_rwlock_destroy(pthread_rwlock_t *rwp);
88 extern int pthread_rwlock_init(pthread_rwlock_t *rwp, const pthread_rwlockattr_t *attr);
89 extern int pthread_rwlock_rdlock(pthread_rwlock_t *rwp);
90 extern int pthread_rwlock_wrlock(pthread_rwlock_t *rwp);
91 extern int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwp);
92 extern int pthread_rwlock_trywrlock(pthread_rwlock_t *rwp);
93 extern int pthread_rwlock_unlock(pthread_rwlock_t *rwp);
94
95 extern int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
96 extern int pthread_setspecific(pthread_key_t key, const void *value);
97 extern pthread_t pthread_self(void);
98 extern int pthread_equal(pthread_t t1, pthread_t t2);
99 extern int pthread_attr_destroy(pthread_attr_t *attr);
100 extern int pthread_attr_init(pthread_attr_t *attr);
101 extern int pthread_attr_getdetachstate(pthread_attr_t *attr, int *detachstate);
102 extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
103 extern void pthread_exit(void *status);
104
105 #endif