1 /*          Package : omnithread
  2    omnithread/pthread_nt.h Created : Steven Brenneis <brennes1@rjrt.com>
  3   
  4       Copyright (C) 1998 Steven Brennes
  5   
  6       This file is part of the omnithread library
  7   
  8       The omnithread library is free software; you can redistribute it and/or
  9       modify it under the terms of the GNU Library General Public
 10       License as published by the Free Software Foundation; either
 11       version 2 of the License, or (at your option) any later version.
 12   
 13       This library is distributed in the hope that it will be useful,
 14       but WITHOUT ANY WARRANTY; without even the implied warranty of
 15       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16       Library General Public License for more details.
 17   
 18       You should have received a copy of the GNU Library General Public
 19       License along with this library; if not, write to the Free
 20       Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 21       02111-1307, USA
 22   
 23       Posix Threads implementation for Windows NT, version 4.0
 24 */
 25 
 26 #ifndef PTHREAD_NT_H_INCLUDED
 27 #define PTHREAD_NT_H_INCLUDED
 28 
 29 #include <errno.h>
 30 
 31 #ifndef ETIMEDOUT
 32 // May have to be changed if NT starts supporting more errno values
 33 #define ETIMEDOUT 60
 34 #endif
 35 
 36 #undef PthreadDraftVersion
 37 #define PthreadDraftVersion 10
 38 
 39 #define NoNanoSleep
 40 
 41 #define PthreadSupportThreadPriority
 42 
 43 #ifdef __cplusplus
 44 extern "C" {
 45 #endif
 46 
 47 #ifndef _TIMERS_T_
 48 #define _TIMERS_T_
 49    typedef struct timespec {
 50       unsigned long tv_sec;
 51       long tv_nsec;
 52    } timespec_t;
 53 #endif
 54 
 55 typedef char* __pthreadLongString_t;
 56 typedef void* __pthreadLongAddr_t;
 57 typedef __pthreadLongAddr_t* __pthreadLongAddr_p;
 58 typedef long __pthreadLongInt_t;
 59 typedef unsigned long __pthreadLongUint_t;
 60 typedef __pthreadLongAddr_p __pthreadTsd_t;
 61 
 62 typedef struct __pthread_mutex_t {
 63    unsigned int lock;           /* LOCK, SLOW, TYPE, RECURSIVE  */
 64    unsigned int valid;          /* Validation info */
 65    __pthreadLongString_t name;   /* Name of mutex */
 66    unsigned int arg;            /* printf argument for  name */
 67    unsigned int depth;          /* Recursive lock depth */
 68    unsigned long sequence;       /* Mutex sequence number */
 69    unsigned long owner;          /* Current owner (if known */
 70    __pthreadLongAddr_t block;          /* Pointer to blocking struct */
 71 } pthread_mutex_t;
 72 
 73 typedef struct __pthread_mutexattr_t {
 74    long valid;
 75    __pthreadLongUint_t reserved[15];
 76 } pthread_mutexattr_t;
 77 
 78 typedef struct __pthread_cond_t {
 79    unsigned int state;          /* EVENT, SLOW, REFCNT */
 80    unsigned int valid;          /* Validation info */
 81    __pthreadLongString_t name;   /* Name of condition variable */
 82    unsigned int arg;            /* printf argument for name */
 83    unsigned long sequence;       /* Condition variable seq # */
 84    __pthreadLongAddr_t block;          /* Pointer to blocking struct */
 85 } pthread_cond_t ;
 86 
 87 typedef struct __pthread_condattr_t {
 88    long valid;
 89    __pthreadLongUint_t reserved[13];
 90 } pthread_condattr_t ;
 91 
 92 typedef struct __pthread_transp_t {
 93    __pthreadLongAddr_t reserved1;      /* Reserved to posix_nt */
 94    __pthreadLongAddr_t reserved2;      /* Reserved to posix_nt */
 95    unsigned short size;           /* Size of data structure */
 96    unsigned char reserved3[2];   /* Reserved to posix_nt */
 97    __pthreadLongAddr_t reserved4;   /* Reserved to posix_nt */
 98    __pthreadLongUint_t sequence;       /* Thread sequence number */
 99    __pthreadLongUint_t reserved5[2];   /* Reserved to posix_nt */
100    __pthreadLongAddr_t per_kt_area;    /* Pointer to kernel context */
101    __pthreadLongAddr_t stack_base;     /* Current stack base */
102    __pthreadLongAddr_t stack_reserve; /* Current stack reserve zone */
103    __pthreadLongAddr_t stack_yellow;   /* Current stack yellow zone */
104    __pthreadLongAddr_t stack_guard;    /* Current stack guard zone */
105    __pthreadLongUint_t stack_size;     /* Size of stack */
106    __pthreadTsd_t tsd_values;     /* TSD array (indexed by key) */
107    unsigned long tsd_count;      /* Number of TSD cells */
108    __pthreadLongAddr_t reserved6;      /* Reserved to posix_nt */
109    __pthreadLongAddr_t reserved7;      /* Reserved to posix_nt */
110    unsigned int thread_flags;   /* Dynamic external state */
111 } pthread_transp_t, *pthread_transp_p;
112 
113 typedef pthread_transp_p pthread_t;
114 
115 typedef struct __pthread_attr_t {
116    long valid;
117    __pthreadLongString_t name;
118    __pthreadLongUint_t arg;
119    __pthreadLongUint_t reserved[19];
120 } pthread_attr_t ;
121 
122 typedef unsigned int pthread_key_t;
123 
124 typedef struct sched_param {
125    int sched_priority;
126 } sched_param_t;
127     
128 /* Function Prototypes */
129 
130 int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
131                         void *(*start_routine)(void*), void *arg);
132 int pthread_detach(pthread_t thread);
133 int pthread_join(pthread_t thread, void **value_ptr);
134 void pthread_exit(void *value_ptr);
135 int pthread_attr_init(pthread_attr_t *attr);
136 int pthread_attr_destroy(pthread_attr_t *attr);
137 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
138 int pthread_attr_getstacksize(const pthread_attr_t *attr, 
139                                  size_t *stacksize);
140 int pthread_cond_init(pthread_cond_t *cond,
141                         const pthread_condattr_t *attr);
142 int pthread_cond_destroy(pthread_cond_t *cond);
143 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
144 int pthread_cond_timedwait(pthread_cond_t *cond, 
145                                  pthread_mutex_t *mutex,
146                                  const struct timespec *abstime);
147 int pthread_cond_signal(pthread_cond_t *cond);
148 int pthread_cond_broadcast(pthread_cond_t *cond);
149 int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
150 int pthread_key_delete(pthread_key_t key);
151 int pthread_mutex_destroy(pthread_mutex_t *mutex);
152 int pthread_mutex_init(pthread_mutex_t *mutex, 
153                            const pthread_mutexattr_t *attr);
154 int pthread_mutex_lock(pthread_mutex_t *mutex);
155 int pthread_mutex_trylock(pthread_mutex_t *mutex);
156 int pthread_mutex_unlock(pthread_mutex_t *mutex);
157 pthread_t pthread_self();
158 int pthread_setspecific(pthread_key_t key, const void *value);
159 void *pthread_getspecific(pthread_key_t key);
160 int pthread_getschedparam(pthread_t thread, int *policy,
161                                  struct sched_param *param);
162 int pthread_setschedparam(pthread_t thread, int policy,
163                               const struct sched_param *param);
164 int pthread_attr_setschedparam(pthread_attr_t *attr, 
165                                     const struct sched_param *param);
166 int pthread_attr_getschedparam(const pthread_attr_t *attr, 
167                                     struct sched_param *param);
168 
169 int pthread_delay_np(const struct timespec *interval);
170 int pthread_get_expiration_np(const struct timespec *delta,
171                                     struct timespec *abstime);
172 
173 # define SCHED_FIFO 1
174 # define SCHED_RR 2
175 # define SCHED_OTHER 3
176 
177 int sched_yield();
178 int sched_get_priority_max(int policy);
179 int sched_get_priority_min(int policy);
180 
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #endif   // PTHREAD_NT_H_INCLUDED


syntax highlighted by Code2HTML, v. 0.9.1