home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / pthread.h < prev    next >
C/C++ Source or Header  |  1999-11-02  |  12KB  |  335 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. #define THREAD_SPECIFIC_SIGPIPE
  84.  
  85. /*
  86.  * Flags for threads and thread attributes.
  87.  */
  88. #define PTHREAD_DETACHED            0x1
  89. #define PTHREAD_SCOPE_SYSTEM        0x2
  90. #define PTHREAD_INHERIT_SCHED       0x4
  91. #define PTHREAD_NOFLOAT             0x8
  92.  
  93. #define PTHREAD_CREATE_DETACHED     PTHREAD_DETACHED
  94. #define PTHREAD_CREATE_JOINABLE     0
  95. #define PTHREAD_SCOPE_PROCESS       0
  96. #define PTHREAD_EXPLICIT_SCHED      0
  97.  
  98. /*
  99.  * New pthread attribute types.
  100.  */
  101. enum schedparam_policy {
  102.     SCHED_RR,
  103.     SCHED_IO,
  104.     SCHED_FIFO,
  105.     SCHED_OTHER
  106. };
  107.  
  108. /*
  109.  * Forward structure definitions.
  110.  *
  111.  * These are mostly opaque to the user.
  112.  */
  113. struct pthread;
  114. struct pthread_attr;
  115. struct pthread_cond;
  116. struct pthread_cond_attr;
  117. struct pthread_mutex;
  118. struct pthread_mutex_attr;
  119. struct pthread_once;
  120. struct sched_param;
  121.  
  122. /*
  123.  * Primitive system data type definitions required by P1003.1c.
  124.  *
  125.  * Note that P1003.1c specifies that there are no defined comparison
  126.  * or assignment operators for the types pthread_attr_t, pthread_cond_t,
  127.  * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
  128.  */
  129. typedef struct    pthread            *pthread_t;
  130. typedef struct    pthread_attr        *pthread_attr_t;
  131. typedef struct    pthread_mutex        *pthread_mutex_t; 
  132. typedef struct    pthread_mutex_attr    *pthread_mutexattr_t;
  133. typedef struct    pthread_cond        *pthread_cond_t;
  134. typedef struct    pthread_cond_attr    *pthread_condattr_t;
  135. typedef int                 pthread_key_t;
  136. typedef struct    pthread_once        pthread_once_t;
  137.  
  138. /*
  139.  * Additional type definitions:
  140.  *
  141.  * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
  142.  * use in header symbols.
  143.  */
  144. typedef void    *pthread_addr_t;
  145. typedef void    *(*pthread_startroutine_t) (void *);
  146. typedef struct timespec timespec_t;
  147.  
  148. /*
  149.  * Once definitions.
  150.  */
  151. struct pthread_once {
  152.     int        state;
  153.     pthread_mutex_t    mutex;
  154. };
  155.  
  156. /*
  157.  * Flags for once initialization.
  158.  */
  159. #define PTHREAD_NEEDS_INIT  0
  160. #define PTHREAD_DONE_INIT   1
  161.  
  162. /*
  163.  * Static once initialization values. 
  164.  */
  165. #define PTHREAD_ONCE_INIT   { PTHREAD_NEEDS_INIT, NULL }
  166.  
  167. /*
  168.  * Default attribute arguments.
  169.  */
  170. #ifndef PTHREAD_KERNEL
  171. #define pthread_condattr_default    NULL
  172. #define pthread_mutexattr_default   NULL
  173. #define pthread_attr_default        NULL
  174. #endif
  175.  
  176. #if !defined(PTHREAD_KERNEL) && !defined(PTHREAD_RTL)
  177. #define sigprocmask(A,B,C)    pthread_sigmask((A),(B),(C))
  178. #define signal(A,B)        pthread_signal((A),(B))
  179. #define raise(A)        pthread_raise(A)
  180. #define    sigaction(A,B,C)    pthread_sigaction((A),(B),(C))
  181. #define sigpending(A)        pthread_sigpending(A)
  182. #define sigsuspend(A)        pthread_sigsuspend(A)
  183. #define pause()            pthread_pause()
  184. #define alarm(A)        pthread_alarm(A)
  185. #define    select(A,B,C,D,E)    pthread_select((A),(B),(C),(D),(E))
  186. #define    sleep(A)        pthread_sleep(A)
  187. #define read(A,B,C)        pthread_read((A),(B),(C))
  188. #define write(A,B,C)        pthread_write((A),(B),(C))
  189. #endif
  190.  
  191. enum pthread_mutextype {
  192.     MUTEX_TYPE_FAST            = 1,
  193.     MUTEX_TYPE_COUNTING_FAST    = 2,    /* Recursive */
  194.     MUTEX_TYPE_MAX
  195. };
  196.  
  197. /*
  198.  * Thread function prototype definitions:
  199.  */
  200. /* __BEGIN_DECLS */
  201. int        pthread_attr_destroy (pthread_attr_t *);
  202. int        pthread_attr_getinheritsched (pthread_attr_t *, int *);
  203. int        pthread_attr_getschedparam (pthread_attr_t *,
  204.             struct sched_param *);
  205. int        pthread_attr_getschedpolicy (pthread_attr_t *, int *);
  206. int        pthread_attr_getscope (pthread_attr_t *, int *);
  207. int        pthread_attr_getstacksize (pthread_attr_t *, size_t *);
  208. int        pthread_attr_getstackaddr (pthread_attr_t *, void **);
  209. int        pthread_attr_getdetachstate (pthread_attr_t *, int *);
  210. int        pthread_attr_init (pthread_attr_t *);
  211. int        pthread_attr_setinheritsched (pthread_attr_t *, int);
  212. int        pthread_attr_setprio(pthread_attr_t *, int);
  213. int        pthread_attr_setschedparam (pthread_attr_t *,
  214.             struct sched_param *);
  215. int        pthread_attr_setschedpolicy (pthread_attr_t *, int);
  216. int        pthread_attr_setscope (pthread_attr_t *, int);
  217. int        pthread_attr_setstacksize (pthread_attr_t *, size_t);
  218. int        pthread_attr_setstackaddr (pthread_attr_t *, void *);
  219. int        pthread_attr_setdetachstate (pthread_attr_t *, int);
  220. void        pthread_cleanup_pop (int execute);
  221. void        pthread_cleanup_push (void (*routine) (void *),
  222.             void *routine_arg);
  223. int        pthread_condattr_destroy (pthread_condattr_t *attr);
  224. int        pthread_condattr_init (pthread_condattr_t *attr);
  225. int        pthread_condattr_getpshared (pthread_condattr_t *attr,
  226.             int *pshared);
  227. int        pthread_condattr_setpshared (pthread_condattr_t *attr,
  228.             int pshared);
  229. int        pthread_cond_broadcast (pthread_cond_t *);
  230. int        pthread_cond_destroy (pthread_cond_t *);
  231. int        pthread_cond_init (pthread_cond_t *,
  232.             const pthread_condattr_t *);
  233. int        pthread_cond_signal (pthread_cond_t *);
  234. int        pthread_cond_timedwait (pthread_cond_t *,
  235.             pthread_mutex_t *, const timespec_t * abstime);
  236. int        pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
  237. int        pthread_create (pthread_t *, const pthread_attr_t *,
  238.             pthread_startroutine_t start_routine, void *);
  239. int        pthread_detach (pthread_t *);
  240. int        pthread_equal (pthread_t, pthread_t);
  241. void        pthread_exit (void *);
  242. void        *pthread_getspecific (pthread_key_t);
  243. void        pthread_init (void);
  244. int        pthread_join (pthread_t, void **);
  245. int        pthread_key_create (pthread_key_t *,
  246.             void (*routine) (void *));
  247. int        pthread_key_delete (pthread_key_t);
  248. int        pthread_kill (struct pthread *, int);
  249. int        pthread_mutexattr_destroy (pthread_mutexattr_t *);
  250. int        pthread_mutexattr_getprioceiling (pthread_mutexattr_t *,
  251.             int *prioceiling);
  252. int        pthread_mutexattr_getprotocol (pthread_mutexattr_t *,
  253.             int *protocol);
  254. int        pthread_mutexattr_getpshared (pthread_mutexattr_t *,
  255.             int *pshared);
  256. int        pthread_mutexattr_init (pthread_mutexattr_t *);
  257. int        pthread_mutexattr_setprioceiling (pthread_mutexattr_t *,
  258.             int prioceiling);
  259. int        pthread_mutexattr_setprotocol (pthread_mutexattr_t *,
  260.             int protocol);
  261. int        pthread_mutexattr_setpshared (pthread_mutexattr_t *,
  262.             int pshared);
  263. int        pthread_mutex_destroy (pthread_mutex_t *);
  264. int        pthread_mutex_getprioceiling (pthread_mutex_t *);
  265. int        pthread_mutex_init (pthread_mutex_t *,
  266.             const pthread_mutexattr_t *);
  267. int        pthread_mutex_lock (pthread_mutex_t *);
  268. int        pthread_mutex_setprioceiling (pthread_mutex_t *);
  269. int        pthread_mutex_trylock (pthread_mutex_t *);
  270. int        pthread_mutex_unlock (pthread_mutex_t *);
  271. int        pthread_once (pthread_once_t *,
  272.             void (*init_routine) (void));
  273. pthread_t    pthread_self (void);
  274. int        pthread_setcancelstate (int, int *);
  275. int        pthread_setcanceltype (int, int *);
  276. int        pthread_setspecific (pthread_key_t, const void *);
  277. int        pthread_testcancel (void);
  278.  
  279.  
  280. int        pthread_getprio (pthread_t);
  281. int        pthread_setprio (pthread_t, int);
  282. void        pthread_yield (void);
  283. /* int        pthread_setschedparam (pthread_t pthread, int policy,
  284.             struct sched_param * param);                */
  285. /* int        pthread_getschedparam (pthread_t pthread, int *policy,
  286.             struct sched_param * param);                */
  287. int        pthread_attr_setfloatstate (pthread_attr_t *, int);
  288. int        pthread_attr_getfloatstate (pthread_attr_t *, int *);
  289. int        pthread_attr_setcleanup (pthread_attr_t *,
  290.             void (*routine) (void *), void *);
  291.  
  292. int        pthread_suspend_np(pthread_t);
  293. int        pthread_resume_np(pthread_t);
  294. int        pthread_attr_setcreatesuspend_np(pthread_attr_t *);
  295. int        pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
  296. int        pthread_mutexattr_getkind_np(pthread_mutexattr_t);
  297.  
  298. int        pthread_sigmask (int, const sigset_t *, sigset_t *);
  299.  
  300. #ifndef PTHREAD_RTL
  301. unsigned    pthread_alarm(unsigned);
  302. int        pthread_pause(void);
  303. int        pthread_raise(int);
  304. int        pthread_select(int, struct _fd_set *, struct _fd_set *, struct _fd_set *,struct timeval *);
  305. void (*        pthread_signal(int, void (*)(int)))(int);
  306. int        pthread_sigaction(int, const struct sigaction *, struct sigaction *);
  307. int        pthread_sigpending(sigset_t *);
  308. int        pthread_sigsuspend(const sigset_t *);
  309. unsigned    pthread_sleep(unsigned);
  310. int        pthread_read(int, void *, size_t);
  311. int        pthread_write(int, const void *, size_t);
  312. #endif
  313.  
  314. /* __END_DECLS */
  315.  
  316. #if defined (__cplusplus)
  317. }
  318. #endif
  319. #endif
  320. #endif
  321. #if !defined(PTHREAD_KERNEL) && !defined(PTHREAD_RTL)
  322. #define sigprocmask(A,B,C)    pthread_sigmask((A),(B),(C))
  323. #define signal(A,B)        pthread_signal((A),(B))
  324. #define raise(A)        pthread_raise(A)
  325. #define    sigaction(A,B,C)    pthread_sigaction((A),(B),(C))
  326. #define sigpending(A)        pthread_sigpending(A)
  327. #define sigsuspend(A)        pthread_sigsuspend(A)
  328. #define pause()            pthread_pause()
  329. #define alarm(A)        pthread_alarm(A)
  330. #define    select(A,B,C,D,E)    pthread_select((A),(B),(C),(D),(E))
  331. #define    sleep(A)        pthread_sleep(A)
  332. #define read(A,B,C)        pthread_read((A),(B),(C))
  333. #define write(A,B,C)        pthread_write((A),(B),(C))
  334. #endif
  335.