Imported Upstream version 3.2.2
[debian/gnuradio] / omnithread / gnuradio / ot_VxThread.h
1 #ifndef __VXTHREAD_H__
2 #define __VXTHREAD_H__
3 /*
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 %% Project:     omniORB
6 %% Filename:    $Filename$
7 %% Author:      Guillaume/Bill ARRECKX
8 %%              Copyright Wavetek Wandel & Goltermann, Plymouth.
9 %% Description: OMNI thread implementation classes for VxWorks threads
10 %% Notes:
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %% $Log$
13 %% Revision 1.1  2004/04/10 18:00:52  eb
14 %% Initial revision
15 %%
16 %% Revision 1.1.1.1  2004/03/01 00:20:27  eb
17 %% initial checkin
18 %%
19 %% Revision 1.1  2003/05/25 05:29:04  eb
20 %% see ChangeLog
21 %%
22 %% Revision 1.1.2.1  2003/02/17 02:03:07  dgrisby
23 %% vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH).
24 %%
25 %% Revision 1.1.1.1  2002/11/19 14:55:21  sokcevti
26 %% OmniOrb4.0.0 VxWorks port
27 %%
28 %% Revision 1.2  2002/06/14 12:45:50  engeln
29 %% unnecessary members in condition removed.
30 %% ---
31 %%
32 %% Revision 1.1.1.1  2002/04/02 10:08:49  sokcevti
33 %% omniORB4 initial realease
34 %%
35 %% Revision 1.1  2001/03/23 16:50:23  hartmut
36 %% Initial Version 2.8
37 %%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 */
40
41
42 ///////////////////////////////////////////////////////////////////////////
43 // Includes
44 ///////////////////////////////////////////////////////////////////////////
45 #include <vxWorks.h>
46 #include <semLib.h>
47 #include <taskLib.h>
48
49
50 ///////////////////////////////////////////////////////////////////////////
51 // Externs prototypes
52 ///////////////////////////////////////////////////////////////////////////
53 extern "C" void omni_thread_wrapper(void* ptr);
54
55
56 ///////////////////////////////////////////////////////////////////////////
57 // Exported macros
58 // Note: These are added as private members in each class implementation.
59 ///////////////////////////////////////////////////////////////////////////
60 #define OMNI_MUTEX_IMPLEMENTATION \
61    SEM_ID mutexID;      \
62    bool m_bConstructed;
63
64 #define OMNI_CONDITION_IMPLEMENTATION \
65    long waiters_; \
66    SEM_ID waiters_lock_; \
67    SEM_ID sema_;
68
69 #define OMNI_SEMAPHORE_IMPLEMENTATION \
70    SEM_ID semID;
71
72 #define OMNI_MUTEX_LOCK_IMPLEMENTATION                  \
73         if(semTake(mutexID, WAIT_FOREVER) != OK)        \
74         {       \
75                 throw omni_thread_fatal(errno); \
76         }
77
78 #define OMNI_MUTEX_UNLOCK_IMPLEMENTATION                \
79         if(semGive(mutexID) != OK)      \
80         {       \
81                 throw omni_thread_fatal(errno); \
82         }
83
84 #define OMNI_THREAD_IMPLEMENTATION \
85    friend void omni_thread_wrapper(void* ptr); \
86    static int vxworks_priority(priority_t); \
87    omni_condition *running_cond; \
88    void* return_val; \
89    int tid; \
90    public: \
91    static void attach(void); \
92    static void detach(void); \
93    static void show(void);
94
95
96 ///////////////////////////////////////////////////////////////////////////
97 // Porting macros
98 ///////////////////////////////////////////////////////////////////////////
99 // This is a wrapper function for the 'main' function which does not exists
100 //  as such in VxWorks. The wrapper creates a launch function instead,
101 //  which spawns the application wrapped in a omni_thread.
102 // Argc will always be null.
103 ///////////////////////////////////////////////////////////////////////////
104 #define main( discarded_argc, discarded_argv ) \
105         omni_discard_retval() \
106           { \
107           throw; \
108           } \
109         int omni_main( int argc, char **argv ); \
110         void launch( ) \
111           { \
112           omni_thread* th = new omni_thread( (void(*)(void*))omni_main );\
113           th->start();\
114           }\
115         int omni_main( int argc, char **argv )
116
117
118 #endif // ndef __VXTHREAD_H__