CPN
Computational Process Networks
PthreadDefs.h
Go to the documentation of this file.
1 //=============================================================================
2 // Definitions used throughout the Pthread class library
3 //-----------------------------------------------------------------------------
4 // POSIX Pthread class library
5 // Copyright (C) 1997-1999 The University of Texas
6 //
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // The GNU Public License is available in the file LICENSE, or you
18 // can write to the Free Software Foundation, Inc., 59 Temple Place -
19 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
20 // World Wide Web at http://www.fsf.org.
21 //=============================================================================
22 
23 
24 #ifndef PthreadDefs_h
25 #define PthreadDefs_h
26 #pragma once
27 #include <cpn/common.h>
28 
29 #ifdef MERCURY
30  // Mercury's pthread support is unmaintained and broken in several ways...
31  #include <mcos.h>
32  #include <unistd.h>
33  #include <pthread.h>
34  #define POSIX_PRIO_NONE NO_PRIO_INHERIT
35  #define POSIX_PRIO_INHERIT PRIO_INHERIT
36  #define POSIX_PRIO_PROTECT PRIO_PROTECT
37  #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED
38 
39 #elif defined(OS_HPUX_1100) || defined(OS_HPUX_1111)
40  // HP's pthread support isn't standard...need to define _POSIX_THREADS
41  #define _POSIX_THREADS 1
42  #include <unistd.h>
43  #include <pthread.h>
44 
45 #elif defined(OS_HPUX_1020)
46  // HP's pthread support is non-existent.
47  // (may be able to use GNU pth library instead)
48  #include <sched.h>
49 #else
50 
51  #include <unistd.h>
52  #ifdef _POSIX_THREADS
53 
54  #include <pthread.h>
55 
56  #if defined(_POSIX_THREAD_PRIO_INHERIT) && (_POSIX_THREAD_PRIO_INHERIT < 0)
57  #undef _POSIX_THREAD_PRIO_INHERIT
58  #endif
59 
60  #if defined(_POSIX_THREAD_PRIO_PROTECT) && (_POSIX_THREAD_PRIO_PROTECT < 0)
61  #undef _POSIX_THREAD_PRIO_PROTECT
62  #endif
63 
64  #if !defined POSIX_PRIO_NONE
65  #define POSIX_PRIO_NONE PTHREAD_PRIO_NONE
66  #define POSIX_PRIO_INHERIT PTHREAD_PRIO_INHERIT
67  #define POSIX_PRIO_PROTECT PTHREAD_PRIO_PROTECT
68  #endif
69 
70 
71  // AIX has some bad ones, too
72  #if defined(OS_AIX)
73  #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED
74  inline int pthread_sigmask(int operation, const sigset_t *set,
75  sigset_t *old_set)
76  { return sigthreadmask(operation, set, old_set); }
77  inline int sched_yield (void)
78  { pthread_yield(); return 0; }
79  #endif
80 
81  // Darwin (MacOS X) had problems prior to gcc-3.3
82  #if defined(__APPLE__) && !( ((__GNUC__==3) && (__GNUC_MINOR__>=3)) || (__GNUC__>3) )
83  inline int pthread_kill(pthread_t thread, int sig)
84  { return -1; }
85  inline int pthread_sigmask(int operation, const sigset_t *set, sigset_t *old_set)
86  { return -1; }
87  #define POSIX_PRIO_NONE PTHREAD_PRIO_NONE
88  #define POSIX_PRIO_INHERIT PTHREAD_PRIO_INHERIT
89  #define POSIX_PRIO_PROTECT PTHREAD_PRIO_PROTECT
90  #undef pthread_cleanup_push
91  #undef pthread_cleanup_pop
92  #define pthread_cleanup_push(routine, args)
93  #define pthread_cleanup_pop(execute)
94  inline int pthread_condattr_init(pthread_condattr_t *attr)
95  { return -1; }
96  inline int pthread_condattr_destroy(pthread_condattr_t *attr)
97  { return -1; }
98  #endif
99 
100  #endif
101 #endif
102 
103 #endif