home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pthrd004.zip / emx / include / pthread.h < prev    next >
Text File  |  1998-12-12  |  12KB  |  330 lines

  1. /*
  2.  * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu
  3.  * Copyright (c) 1995 by John Birrell <jb@cimlogic.com.au>
  4.  * All rights reserved
  5.  *
  6.  * Modified and extended by Antony T Curtis <antony.curtis@olcs.net>
  7.  * for use with OS/2.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *  This product includes software developed by Chris Provenzano.
  20.  * 4. The name of Chris Provenzano may not be used to endorse or promote 
  21.  *      products derived from this software without specific prior written
  22.  *      permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY 
  28.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
  34.  * SUCH DAMAGE.
  35.  *
  36.  */
  37. #ifndef _PTHREAD_H_
  38. #define _PTHREAD_H_
  39.  
  40. #define EMX_PTHREAD_REV 4
  41.  
  42. #ifdef __MT__
  43.  
  44. /*
  45.  * Header files.
  46.  */
  47. #include <sys/cdefs.h>
  48. #include <sys/types.h>
  49. #include <sys/time.h>
  50. #include <sys/signal.h>
  51. #include <sys/select.h>
  52. #include <limits.h>
  53. #include <unistd.h>
  54.  
  55. #if defined (__cplusplus)
  56. extern "C" {
  57. #endif
  58.  
  59.  
  60. /*
  61.  * Run-time invariant values:
  62.  */
  63. #define PTHREAD_DESTRUCTOR_ITERATIONS        4
  64. #define PTHREAD_KEYS_MAX            256
  65. #define PTHREAD_STACK_MIN            1024
  66. #define PTHREAD_THREADS_MAX            ULONG_MAX
  67.  
  68. /*
  69.  * Compile time symbolic constants for portability specifications:
  70.  *
  71.  * Note that those commented out are not currently supported by the
  72.  * implementation.
  73.  */
  74. #define _POSIX_THREADS
  75. /* #define _POSIX_THREAD_ATTR_STACKADDR */
  76. /* #define _POSIX_THREAD_ATTR_STACKSIZE */
  77. /* #define _POSIX_THREAD_PRIORITY_SCHEDULING */
  78. /* #define _POSIX_THREAD_PRIO_INHERIT   */
  79. /* #define _POSIX_THREAD_PRIO_PROTECT   */
  80. /* #define _POSIX_THREAD_PROCESS_SHARED */
  81. /* #define _POSIX_THREAD_SAFE_FUNCTIONS */
  82.  
  83. /*
  84.  * Flags for threads and thread attributes.
  85.  */
  86. #define PTHREAD_DETACHED            0x1
  87. #define PTHREAD_SCOPE_SYSTEM        0x2
  88. #define PTHREAD_INHERIT_SCHED       0x4
  89. #define PTHREAD_NOFLOAT             0x8
  90.  
  91. #define PTHREAD_CREATE_DETACHED     PTHREAD_DETACHED
  92. #define PTHREAD_CREATE_JOINABLE     0
  93. #define PTHREAD_SCOPE_PROCESS       0
  94. #define PTHREAD_EXPLICIT_SCHED      0
  95.  
  96. /*
  97.  * New pthread attribute types.
  98.  */
  99. enum schedparam_policy {
  100.     SCHED_RR,
  101.     SCHED_IO,
  102.     SCHED_FIFO,
  103.     SCHED_OTHER
  104. };
  105.  
  106. /*
  107.  * Forward structure definitions.
  108.  *
  109.  * These are mostly opaque to the user.
  110.  */
  111. struct pthread;
  112. struct pthread_attr;
  113. struct pthread_cond;
  114. struct pthread_cond_attr;
  115. struct pthread_mutex;
  116. struct pthread_mutex_attr;
  117. struct pthread_once;
  118. struct sched_param;
  119.  
  120. /*
  121.  * Primitive system data type definitions required by P1003.1c.
  122.  *
  123.  * Note that P1003.1c specifies that there are no defined comparison
  124.  * or assignment operators for the types pthread_attr_t, pthread_cond_t,
  125.  * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
  126.  */
  127. typedef struct    pthread            *pthread_t;
  128. typedef struct    pthread_attr        *pthread_attr_t;
  129. typedef struct    pthread_mutex        *pthread_mutex_t; 
  130. typedef struct    pthread_mutex_attr    *pthread_mutexattr_t;
  131. typedef struct    pthread_cond        *pthread_cond_t;
  132. typedef struct    pthread_cond_attr    *pthread_condattr_t;
  133. typedef int                 pthread_key_t;
  134. typedef struct    pthread_once        pthread_once_t;
  135.  
  136. /*
  137.  * Additional type definitions:
  138.  *
  139.  * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
  140.  * use in header symbols.
  141.  */
  142. typedef void    *pthread_addr_t;
  143. typedef void    *(*pthread_startroutine_t) (void *);
  144. typedef struct timespec timespec_t;
  145.  
  146. /*
  147.  * Once definitions.
  148.  */
  149. struct pthread_once {
  150.     int        state;
  151.     pthread_mutex_t    mutex;
  152. };
  153.  
  154. /*
  155.  * Flags for once initialization.
  156.  */
  157. #define PTHREAD_NEEDS_INIT  0
  158. #define PTHREAD_DONE_INIT   1
  159.  
  160. /*
  161.  * Static once initialization values. 
  162.  */
  163. #define PTHREAD_ONCE_INIT   { PTHREAD_NEEDS_INIT, NULL }
  164.  
  165. /*
  166.  * Default attribute arguments.
  167.  */
  168. #ifndef PTHREAD_KERNEL
  169. #define pthread_condattr_default    NULL
  170. #define pthread_mutexattr_default   NULL
  171. #define pthread_attr_default        NULL
  172. #endif
  173.  
  174. #ifndef PTHREAD_KERNEL
  175. #define sigprocmask(A,B,C)    pthread_sigmask((A),(B),(C))
  176. #define signal(A,B)        pthread_signal((A),(B))
  177. #define raise(A)        pthread_raise(A)
  178. #define    sigaction(A,B,C)    pthread_sigaction((A),(B),(C))
  179. #define sigpending(A)        pthread_sigpending(A)
  180. #define sigsuspend(A)        pthread_sigsuspend(A)
  181. #define pause()            pthread_pause()
  182. #define alarm(A)        pthread_alarm(A)
  183. #define    select(A,B,C,D,E)    pthread_select((A),(B),(C),(D),(E))
  184. #define    sleep(A)        pthread_sleep(A)
  185. #define read(A,B,C)        pthread_read((A),(B),(C))
  186. #define write(A,B,C)        pthread_write((A),(B),(C))
  187. #endif
  188.  
  189. enum pthread_mutextype {
  190.     MUTEX_TYPE_FAST            = 1,
  191.     MUTEX_TYPE_COUNTING_FAST    = 2,    /* Recursive */
  192.     MUTEX_TYPE_MAX
  193. };
  194.  
  195. /*
  196.  * Thread function prototype definitions:
  197.  */
  198. /* __BEGIN_DECLS */
  199. unsigned    pthread_alarm(unsigned);
  200. int        pthread_attr_destroy (pthread_attr_t *);
  201. int        pthread_attr_getinheritsched (pthread_attr_t *, int *);
  202. int        pthread_attr_getschedparam (pthread_attr_t *,
  203.             struct sched_param *);
  204. int        pthread_attr_getschedpolicy (pthread_attr_t *, int *);
  205. int        pthread_attr_getscope (pthread_attr_t *, int *);
  206. int        pthread_attr_getstacksize (pthread_attr_t *, size_t *);
  207. int        pthread_attr_getstackaddr (pthread_attr_t *, void **);
  208. int        pthread_attr_getdetachstate (pthread_attr_t *, int *);
  209. int        pthread_attr_init (pthread_attr_t *);
  210. int        pthread_attr_setinheritsched (pthread_attr_t *, int);
  211. int        pthread_attr_setprio(pthread_attr_t *, int);
  212. int        pthread_attr_setschedparam (pthread_attr_t *,
  213.             struct sched_param *);
  214. int        pthread_attr_setschedpolicy (pthread_attr_t *, int);
  215. int        pthread_attr_setscope (pthread_attr_t *, int);
  216. int        pthread_attr_setstacksize (pthread_attr_t *, size_t);
  217. int        pthread_attr_setstackaddr (pthread_attr_t *, void *);
  218. int        pthread_attr_setdetachstate (pthread_attr_t *, int);
  219. void        pthread_cleanup_pop (int execute);
  220. void        pthread_cleanup_push (void (*routine) (void *),
  221.             void *routine_arg);
  222. int        pthread_condattr_destroy (pthread_condattr_t *attr);
  223. int        pthread_condattr_init (pthread_condattr_t *attr);
  224. int        pthread_condattr_getpshared (pthread_condattr_t *attr,
  225.             int *pshared);
  226. int        pthread_condattr_setpshared (pthread_condattr_t *attr,
  227.             int pshared);
  228. int        pthread_cond_broadcast (pthread_cond_t *);
  229. int        pthread_cond_destroy (pthread_cond_t *);
  230. int        pthread_cond_init (pthread_cond_t *,
  231.             const pthread_condattr_t *);
  232. int        pthread_cond_signal (pthread_cond_t *);
  233. int        pthread_cond_timedwait (pthread_cond_t *,
  234.             pthread_mutex_t *, const timespec_t * abstime);
  235. int        pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
  236. int        pthread_create (pthread_t *, const pthread_attr_t *,
  237.             pthread_startroutine_t start_routine, void *);
  238. int        pthread_detach (pthread_t *);
  239. int        pthread_equal (pthread_t, pthread_t);
  240. void        pthread_exit (void *);
  241. void        *pthread_getspecific (pthread_key_t);
  242. void        pthread_init (void);
  243. int        pthread_join (pthread_t, void **);
  244. int        pthread_key_create (pthread_key_t *,
  245.             void (*routine) (void *));
  246. int        pthread_key_delete (pthread_key_t);
  247. int        pthread_kill (struct pthread *, int);
  248. int        pthread_mutexattr_destroy (pthread_mutexattr_t *);
  249. int        pthread_mutexattr_getprioceiling (pthread_mutexattr_t *,
  250.             int *prioceiling);
  251. int        pthread_mutexattr_getprotocol (pthread_mutexattr_t *,
  252.             int *protocol);
  253. int        pthread_mutexattr_getpshared (pthread_mutexattr_t *,
  254.             int *pshared);
  255. int        pthread_mutexattr_init (pthread_mutexattr_t *);
  256. int        pthread_mutexattr_setprioceiling (pthread_mutexattr_t *,
  257.             int prioceiling);
  258. int        pthread_mutexattr_setprotocol (pthread_mutexattr_t *,
  259.             int protocol);
  260. int        pthread_mutexattr_setpshared (pthread_mutexattr_t *,
  261.             int pshared);
  262. int        pthread_mutex_destroy (pthread_mutex_t *);
  263. int        pthread_mutex_getprioceiling (pthread_mutex_t *);
  264. int        pthread_mutex_init (pthread_mutex_t *,
  265.             const pthread_mutexattr_t *);
  266. int        pthread_mutex_lock (pthread_mutex_t *);
  267. int        pthread_mutex_setprioceiling (pthread_mutex_t *);
  268. int        pthread_mutex_trylock (pthread_mutex_t *);
  269. int        pthread_mutex_unlock (pthread_mutex_t *);
  270. int        pthread_once (pthread_once_t *,
  271.             void (*init_routine) (void));
  272. int        pthread_pause(void);
  273. int        pthread_raise(int);
  274. pthread_t    pthread_self (void);
  275. int        pthread_setcancelstate (int, int *);
  276. int        pthread_setcanceltype (int, int *);
  277. int        pthread_setspecific (pthread_key_t, const void *);
  278. void (*        pthread_signal(int, void (*)(int)))(int);
  279. int        pthread_sigaction(int, const struct sigaction *, struct sigaction *);
  280. int        pthread_sigmask (int, const sigset_t *, sigset_t *);
  281. int        pthread_sigpending(sigset_t *);
  282. int        pthread_sigsuspend(const sigset_t *);
  283. int        pthread_testcancel (void);
  284.  
  285.  
  286. int        pthread_getprio (pthread_t);
  287. int        pthread_setprio (pthread_t, int);
  288. void        pthread_yield (void);
  289. /* int        pthread_setschedparam (pthread_t pthread, int policy,
  290.             struct sched_param * param);                */
  291. /* int        pthread_getschedparam (pthread_t pthread, int *policy,
  292.             struct sched_param * param);                */
  293. int        pthread_attr_setfloatstate (pthread_attr_t *, int);
  294. int        pthread_attr_getfloatstate (pthread_attr_t *, int *);
  295. int        pthread_attr_setcleanup (pthread_attr_t *,
  296.             void (*routine) (void *), void *);
  297.  
  298. int        pthread_suspend_np(pthread_t);
  299. int        pthread_resume_np(pthread_t);
  300. int        pthread_attr_setcreatesuspend_np(pthread_attr_t *);
  301. int        pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
  302. int        pthread_mutexattr_getkind_np(pthread_mutexattr_t);
  303.  
  304. int        pthread_select(int, struct _fd_set *, struct _fd_set *, struct _fd_set *,struct timeval *);
  305. unsigned    pthread_sleep(unsigned);
  306. int        pthread_read(int, void *, size_t);
  307. int        pthread_write(int, const void *, size_t);
  308.  
  309. /* __END_DECLS */
  310.  
  311. #if defined (__cplusplus)
  312. }
  313. #endif
  314. #endif
  315. #endif
  316. #ifndef PTHREAD_KERNEL
  317. #define sigprocmask(A,B,C)    pthread_sigmask((A),(B),(C))
  318. #define signal(A,B)        pthread_signal((A),(B))
  319. #define raise(A)        pthread_raise(A)
  320. #define    sigaction(A,B,C)    pthread_sigaction((A),(B),(C))
  321. #define sigpending(A)        pthread_sigpending(A)
  322. #define sigsuspend(A)        pthread_sigsuspend(A)
  323. #define pause()            pthread_pause()
  324. #define alarm(A)        pthread_alarm(A)
  325. #define    select(A,B,C,D,E)    pthread_select((A),(B),(C),(D),(E))
  326. #define    sleep(A)        pthread_sleep(A)
  327. #define read(A,B,C)        pthread_read((A),(B),(C))
  328. #define write(A,B,C)        pthread_write((A),(B),(C))
  329. #endif
  330.