Imported Upstream version 3.2.2
[debian/gnuradio] / omnithread / gnuradio / ot_posix.h
1 //                              Package : omnithread
2 // omnithread/posix.h           Created : 7/94 tjr
3 //
4 //    Copyright (C) 2006 Free Software Foundation, Inc.
5 //    Copyright (C) 1994,1995,1996, 1997 Olivetti & Oracle Research Laboratory
6 //
7 //    This file is part of the omnithread library
8 //
9 //    The omnithread library is free software; you can redistribute it and/or
10 //    modify it under the terms of the GNU Library General Public
11 //    License as published by the Free Software Foundation; either
12 //    version 2 of the License, or (at your option) any later version.
13 //
14 //    This library is distributed in the hope that it will be useful,
15 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //    Library General Public License for more details.
18 //
19 //    You should have received a copy of the GNU Library General Public
20 //    License along with this library; if not, write to the Free
21 //    Software Foundation, Inc., 51 Franklin Street, Boston, MA  
22 //    02110-1301, USA
23 //
24 //
25 // OMNI thread implementation classes for posix threads
26 //
27
28 #ifndef __omnithread_posix_h_
29 #define __omnithread_posix_h_
30
31 #if defined(__alpha__) && defined(__osf1__) || defined(__hpux__)
32 // stop unnecessary definitions of TRY, etc on OSF
33 #ifndef EXC_HANDLING
34 #define EXC_HANDLING
35 #endif
36 #endif
37
38 #ifndef __POSIX_NT__
39 #  include <pthread.h>
40 #else
41 #  ifndef WIN32_LEAN_AND_MEAN
42 #    define WIN32_LEAN_AND_MEAN
43 #    define OMNI_DEFINED_WIN32_LEAN_AND_MEAN
44 #  endif
45 #  include <windows.h>
46 #  include "pthread_nt.h"
47 #  ifdef OMNI_DEFINED_WIN32_LEAN_AND_MEAN
48 #    undef WIN32_LEAN_AND_MEAN
49 #    undef OMNI_DEFINED_WIN32_LEAN_AND_MEAN
50 #  endif
51 #endif
52
53 extern "C" void* omni_thread_wrapper(void* ptr);
54
55 #define OMNI_MUTEX_IMPLEMENTATION                       \
56     pthread_mutex_t posix_mutex;
57
58 #define OMNI_MUTEX_LOCK_IMPLEMENTATION                  \
59     pthread_mutex_lock(&posix_mutex);
60
61 #define OMNI_MUTEX_TRYLOCK_IMPLEMENTATION               \
62     (pthread_mutex_trylock(&posix_mutex)==0);
63
64 #define OMNI_MUTEX_UNLOCK_IMPLEMENTATION                \
65     pthread_mutex_unlock(&posix_mutex);
66
67 #define OMNI_CONDITION_IMPLEMENTATION                   \
68     pthread_cond_t posix_cond;
69
70 #define OMNI_SEMAPHORE_IMPLEMENTATION                   \
71     omni_mutex m;                                       \
72     omni_condition c;                                   \
73     int value;                                          \
74     int max_count;
75
76 #define OMNI_THREAD_IMPLEMENTATION                      \
77     pthread_t posix_thread;                             \
78     static int posix_priority(priority_t);              \
79     friend void* omni_thread_wrapper(void* ptr);
80
81 #endif