1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#ifndef __VXTHREAD_H__
#define __VXTHREAD_H__
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Project: omniORB
%% Filename: $Filename$
%% Author: Guillaume/Bill ARRECKX
%% Copyright Wavetek Wandel & Goltermann, Plymouth.
%% Description: OMNI thread implementation classes for VxWorks threads
%% Notes:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
///////////////////////////////////////////////////////////////////////////
// Includes
///////////////////////////////////////////////////////////////////////////
#include <vxWorks.h>
#include <semLib.h>
#include <taskLib.h>
///////////////////////////////////////////////////////////////////////////
// Externs prototypes
///////////////////////////////////////////////////////////////////////////
extern "C" void omni_thread_wrapper(void* ptr);
///////////////////////////////////////////////////////////////////////////
// Exported macros
// Note: These are added as private members in each class implementation.
///////////////////////////////////////////////////////////////////////////
#define OMNI_MUTEX_IMPLEMENTATION \
SEM_ID mutexID; \
bool m_bConstructed;
#define OMNI_CONDITION_IMPLEMENTATION \
SEM_ID sema_;
#define OMNI_SEMAPHORE_IMPLEMENTATION \
SEM_ID semID;
#define OMNI_MUTEX_LOCK_IMPLEMENTATION \
if(semTake(mutexID, WAIT_FOREVER) != OK) \
{ \
throw omni_thread_fatal(errno); \
}
#define OMNI_MUTEX_TRYLOCK_IMPLEMENTATION \
return semTake(mutexID, NO_WAIT) == OK;
#define OMNI_MUTEX_UNLOCK_IMPLEMENTATION \
if(semGive(mutexID) != OK) \
{ \
throw omni_thread_fatal(errno); \
}
#define OMNI_THREAD_IMPLEMENTATION \
friend void omni_thread_wrapper(void* ptr); \
static int vxworks_priority(priority_t); \
omni_condition *running_cond; \
void* return_val; \
int tid; \
public: \
static void attach(void); \
static void detach(void); \
static void show(void);
///////////////////////////////////////////////////////////////////////////
// Porting macros
///////////////////////////////////////////////////////////////////////////
// This is a wrapper function for the 'main' function which does not exists
// as such in VxWorks. The wrapper creates a launch function instead,
// which spawns the application wrapped in a omni_thread.
// Argc will always be null.
///////////////////////////////////////////////////////////////////////////
#define main( discarded_argc, discarded_argv ) \
omni_discard_retval() \
{ \
throw; \
} \
int omni_main( int argc, char **argv ); \
void launch( ) \
{ \
omni_thread* th = new omni_thread( (void(*)(void*))omni_main );\
th->start();\
}\
int omni_main( int argc, char **argv )
#endif // ndef __VXTHREAD_H__
|