FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
OMEthreadCntrl.h
Go to the documentation of this file.
1 #ifndef _OME_THREAD_CNTRL_H
2 #define _OME_THREAD_CNTRL_H "$Id: OMEthreadCntrl.h 453 2020-07-23 20:20:44Z geoff $"
4 
6 #ifdef _WIN32
7 #include <winsock2.h>
8 //#include <windows.h>
9 #else
10 // POSIX Threads
11 #ifndef DONT_USE_PTHREADS
12 #include <pthread.h>
13 #endif
14 #endif
15 
23 public:
25  uint32_t exitStatus;
26 
28  exitStatus = ~0;
29  threadInfo = t;
30  }
31 
32  virtual ~OMEthreadController() {}
33 
35  virtual void releaseThread() = 0;
37  virtual void suspendThread() = 0;
39  virtual void terminateThread() = 0;
41  virtual void yieldSlice() = 0;
43  virtual void executeSlice() = 0;
44 
46  virtual const char *controllerType() const OME_CONST_FUNCTION = 0;
47 }; // end class OMEthreadController
48 
53 private:
54 public:
55  explicit OMEthreadNativeOIL2(OMEthread *t);
56 
58 
59  virtual void releaseThread() override;
60  virtual void suspendThread() override;
61  virtual void terminateThread() override;
62  virtual void yieldSlice() override;
63  virtual void executeSlice() override;
64  virtual const char *controllerType() const override;
65 }; // class OMEthreadNativeOIL2
66 
71 public:
72  explicit OMEthreadInterpretOIL2(OMEthread *t);
73 
75 
76 #ifdef PICK_UP_FROM_NATIVE
77  virtual void releaseThread() override;
78  virtual void suspendThread() override;
79  virtual void terminateThread() override;
80  virtual void yieldSlice() override;
81  virtual void executeSlice() override;
82 #endif
83  virtual const char *controllerType() const override;
84 }; // class OMEthreadInterpretOIL2
85 
89 class OMEthreadNative final : public OMEthreadController {
90 #ifdef _WIN32
91  HANDLE threadHandle;
92 #else
93 #ifndef DONT_USE_PTHREADS
94  static void *OMEpthreadPrologue(void *);
95  // POSIX Threads
96  pthread_mutex_t threadMutex;
97  pthread_cond_t suspendCondition;
98  pthread_t threadID;
99 #endif
100 #endif
101 public:
102  explicit OMEthreadNative(OMEthread *t);
103 
104  ~OMEthreadNative();
105 
106  virtual void releaseThread() override;
107  virtual void suspendThread() override;
108  virtual void terminateThread() override;
109  virtual void yieldSlice() override;
110  virtual void executeSlice() override {} // never called for this form...
111 
112  virtual const char *controllerType() const override;
113 }; // end class OMEthreadNative
114 
119 public:
120  int64_t startTick;
121  int64_t stopTick;
122  int64_t pendingTotal;
124 
125  explicit OMEtickInterval(class OMEthread *thread) NONNULL_CLASS_PARAMETERS(2);
126 
127  ~OMEtickInterval();
128 
130  startTick = OMEgetCPUticks();
131  }
132 
133 // void startIntervalForThread(OMEthread *thread);
134 
135  void stopInterval() {
136  stopTick = OMEgetCPUticks();
137  int64_t delta = stopTick - startTick;
138  pendingTotal += delta;
139  }
140 
141  void noteThreadDead(const class OMEthread *deadThread);
142 
143  int64_t intervalLength() const {
144  return (pendingTotal);
145  }
146 
147  void addIntervalCounts(const OMEinvocationData *method);
148 }; // class OMEtickInterval
149 
152 #endif
153 /* vim: set expandtab shiftwidth=4 tabstop=4: */
OMEprocInfo.h
OME process information implementation.
OME_THREAD_SUSPEND
@ OME_THREAD_SUSPEND
thread is suspended
Definition: OMEthread.h:20
OMEthreadController::OMEthreadController
OMEthreadController(OMEthread *t)
Definition: OMEthreadCntrl.h:27
OMEthreadNativeOIL2::yieldSlice
virtual void yieldSlice() override
Yield time slice currently being used by an active thread.
Definition: OMEthreadCntrl.cpp:319
OME_THREAD_RUNNING
@ OME_THREAD_RUNNING
thread is active
Definition: OMEthread.h:21
OMEthreadNativeOIL2::suspendThread
virtual void suspendThread() override
Suspend an active thread.
Definition: OMEthreadCntrl.cpp:291
OMEthreadNative::~OMEthreadNative
~OMEthreadNative()
Definition: OMEthreadCntrl.cpp:187
OMEinvocationData::function
NativeMethodFP function
Definition: OMEmethod.h:49
OMEthreadNativeOIL2::releaseThread
virtual void releaseThread() override
Release a suspended thread.
Definition: OMEthreadCntrl.cpp:285
OMEtickInterval
Statistics record to track amount of time used by an OMEthread.
Definition: OMEthreadCntrl.h:118
OMEthreadController::executeSlice
virtual void executeSlice()=0
Execute a time slice for an active thread.
OMEthreadNative::releaseThread
virtual void releaseThread() override
Release a suspended thread.
Definition: OMEthreadCntrl.cpp:213
OMEthreadNative::suspendThread
virtual void suspendThread() override
Suspend an active thread.
Definition: OMEthreadCntrl.cpp:226
OMEthreadController::threadInfo
class OMEthread * threadInfo
Definition: OMEthreadCntrl.h:24
OMEinvocationData::invocationMode
uint32_t invocationMode
Definition: OMEmethod.h:47
pthread_cleanup_pop
#define pthread_cleanup_pop(execute)
Definition: tmp.o.cpp:3105
OMEthread::getThreadState
OMEthreadStates getThreadState() const OME_ALWAYS_INLINE
Definition: OMEthread.h:119
OMEthreadNativeOIL2::terminateThread
virtual void terminateThread() override
Terminate a thread.
Definition: OMEthreadCntrl.cpp:296
OMEinvocationData::data
void * data
Definition: OMEmethod.h:50
pthread_cleanup_push
#define pthread_cleanup_push(func, val)
Definition: tmp.o.cpp:3106
OMEtickInterval::startTick
int64_t startTick
Definition: OMEthreadCntrl.h:120
OMEtickInterval::stopInterval
void stopInterval()
Definition: OMEthreadCntrl.h:135
OMEtype::value
union OMEtype::@26 value
OMEtype
Fundamental ANY type for FARGOS/VISTA Object Management Environment.
Definition: OMEbaseType.h:250
OMEobject
Base class and abstract interface for an object within a FARGOS/VISTA Object Management Environment.
Definition: OMEobject.h:22
OMEthreadNative::yieldSlice
virtual void yieldSlice() override
Yield time slice currently being used by an active thread.
Definition: OMEthreadCntrl.cpp:258
OMEtickInterval::activeThread
class OMEthread * activeThread
Definition: OMEthreadCntrl.h:123
OMEtickInterval::startInterval
void startInterval() OME_ALWAYS_INLINE
Definition: OMEthreadCntrl.h:129
OMEthreadInterpretOIL2::controllerType
virtual const char * controllerType() const override
Return label identifying the type of the thread controller.
Definition: OMEthreadCntrl.cpp:402
OMEthreadNative::executeSlice
virtual void executeSlice() override
Execute a time slice for an active thread.
Definition: OMEthreadCntrl.h:110
OMEtype::oid
class OMEoid * oid
Definition: OMEbaseType.h:297
LOG_COUT
#define LOG_COUT(lvl)
Convenience macro that uses LOG_INTO() to conditionally log a message to standard output.
Definition: logging_api.hpp:3007
NONNULL_CLASS_PARAMETERS
#define NONNULL_CLASS_PARAMETERS(...)
Mark a function as never returning a null pointer.
Definition: compiler_hints.h:337
OMEgetCPUticks
#define OMEgetCPUticks()
Definition: OMEprocInfo.h:80
OMEcore.h
OMEthreadNativeOIL2::~OMEthreadNativeOIL2
~OMEthreadNativeOIL2()
Definition: OMEthreadCntrl.cpp:276
NativeMethodFP
OME_CORE_CALL int(* NativeMethodFP)(class OMEthread *)
Typedef of a native method.
Definition: OMEmethod.h:20
OMEinvocationData::addTickCount
OME_FAST_CALL void addTickCount(const int64_t tickCount) const OME_ALWAYS_INLINE
Definition: OMEmethod.h:68
OMEobject::addTickCount
OME_FAST_CALL void addTickCount(const int64_t tickCount) const OME_ALWAYS_INLINE
Add tick counts to per-object statistics.
Definition: OMEobject.h:86
OME_INVOKE_OIL2_INTERPRET
#define OME_INVOKE_OIL2_INTERPRET
Definition: OMEmethod.h:11
OMEthreadController::suspendThread
virtual void suspendThread()=0
Suspend an active thread.
OME_THREAD_KILLED
@ OME_THREAD_KILLED
thread has been killed
Definition: OMEthread.h:22
OMEthread::noteThreadState
void noteThreadState(const OMEthreadStates s) OME_ALWAYS_INLINE
Definition: OMEthread.h:117
OMEthreadNativeOIL2::OMEthreadNativeOIL2
OMEthreadNativeOIL2(OMEthread *t)
Definition: OMEthreadCntrl.cpp:272
srcID
const char srcID[]
Definition: catSym.c:17
OMEoil2Interp.h
OMEtickInterval::pendingTotal
int64_t pendingTotal
Definition: OMEthreadCntrl.h:122
OMEthreadNative::OMEthreadNative
OMEthreadNative(OMEthread *t)
Definition: OMEthreadCntrl.cpp:149
OMEthreadNative::threadMutex
pthread_mutex_t threadMutex
Definition: OMEthreadCntrl.h:96
OMEthreadController::releaseThread
virtual void releaseThread()=0
Release a suspended thread.
OMEthread::threadNowTerminated
OME_FAST_CALL void threadNowTerminated(uint32_t exitStatus, bool dontDelete=false)
Definition: OMEthread.cpp:1051
OMEthreadNative::suspendCondition
pthread_cond_t suspendCondition
Definition: OMEthreadCntrl.h:97
OMEthread.h
OMEthread::setTickInterval
void setTickInterval(class OMEtickInterval *interval) OME_ALWAYS_INLINE
Definition: OMEthread.h:115
OME_EXPECT_TRUE
#define OME_EXPECT_TRUE(expr)
Annotation macro for conditional expression expected to be true.
Definition: compiler_hints.h:541
OMEthread::callStack
OMEcallStack * callStack
Definition: OMEthread.h:74
OMEexecQueue.h
NULL
#define NULL
Definition: tmp.o.cpp:327
OMEthreadController::terminateThread
virtual void terminateThread()=0
Terminate a thread.
OMEthreadNativeOIL2::executeSlice
virtual void executeSlice() override
Execute a time slice for an active thread.
Definition: OMEthreadCntrl.cpp:324
OMEtickInterval::noteThreadDead
void noteThreadDead(const class OMEthread *deadThread)
Definition: OMEthreadCntrl.cpp:52
OMEthreadNative::OMEpthreadPrologue
static void * OMEpthreadPrologue(void *)
Definition: OMEthreadCntrl.cpp:73
OMEthreadNative::controllerType
virtual const char * controllerType() const override
Return label identifying the type of the thread controller.
Definition: OMEthreadCntrl.cpp:200
OMEtickInterval::stopTick
int64_t stopTick
Definition: OMEthreadCntrl.h:121
OMEthreadController
Abstract interface for an OME thread controller.
Definition: OMEthreadCntrl.h:22
OME_USED
const char srcID[] OME_USED
Definition: tick_time.cpp:24
OMEthreadNativeOIL2
Implementation of OME threads for compiled OIL2 source.
Definition: OMEthreadCntrl.h:52
OME_CONST_FUNCTION
#define OME_CONST_FUNCTION
Mark as an idempotent function that only accesses arguments – no global data.
Definition: compiler_hints.h:390
OMEreferenceCount::addReadOnlyReference
void addReadOnlyReference()
Definition: OMErefCount.cpp:139
OMEtickInterval::addIntervalCounts
void addIntervalCounts(const OMEinvocationData *method)
Definition: OMEthreadCntrl.cpp:41
OMEthread::tickInterval
class OMEtickInterval * tickInterval
Definition: OMEthread.h:85
OME_EXPECT_FALSE
#define OME_EXPECT_FALSE(expr)
Annotation macro for conditional expression expected to be false.
Definition: compiler_hints.h:540
PTHREAD_SCOPE_SYSTEM
#define PTHREAD_SCOPE_SYSTEM
Definition: tmp.o.cpp:447
OME_ALWAYS_INLINE
#define OME_ALWAYS_INLINE
Tell the compiler to alway inline a function, regardless of optimization level.
Definition: compiler_hints.h:364
OMEinvocationData
Record to describe the implementation of the method of an OME class.
Definition: OMEmethod.h:35
OMEtickInterval::intervalLength
int64_t intervalLength() const
Definition: OMEthreadCntrl.h:143
OMEthreadNativeOIL2::controllerType
virtual const char * controllerType() const override
Return label identifying the type of the thread controller.
Definition: OMEthreadCntrl.cpp:280
OMEthreadNative
Implementation of OME thread controller for native threads.
Definition: OMEthreadCntrl.h:89
OMEthreadNative::threadID
pthread_t threadID
Definition: OMEthreadCntrl.h:98
OMEmutex.h
OME mutex and condition variable implementation.
OMEthreadInterpretOIL2::~OMEthreadInterpretOIL2
~OMEthreadInterpretOIL2()
Definition: OMEthreadCntrl.cpp:398
OMEreferenceCount::dropReference
int_fast32_t dropReference()
Definition: OMErefCount.cpp:144
OMEthreadController::controllerType
virtual const char * controllerType() const OME_CONST_FUNCTION=0
Return label identifying the type of the thread controller.
OMEthread
Public interface to an OME thread.
Definition: OMEthread.h:60
LOG_ENDLINE
#define LOG_ENDLINE
Closing clause for text line output using << operators.
Definition: logging_api.hpp:2956
OMEoid
Public interface to an OME Object Identifier.
Definition: OMEoid.h:196
OMEcallStack::getThisObject
const OME_FAST_CALL OMEtype & getThisObject() const
Definition: OMEthread.h:51
OMEthreadNative::terminateThread
virtual void terminateThread() override
Terminate a thread.
Definition: OMEthreadCntrl.cpp:239
OMEthreadController::exitStatus
uint32_t exitStatus
Definition: OMEthreadCntrl.h:25
OMEinvocationData::code
union OMEinvocationData::@30 code
OME_INVOKE_OIL2_NATIVE
#define OME_INVOKE_OIL2_NATIVE
Definition: OMEmethod.h:12
OMEoid::getInstanceInMemory
const class OMEobject * getInstanceInMemory() const
Return object information record.
Definition: OMEoid.h:280
OMEthreadInterpretOIL2
Specialization of OMEthreadNativeOIL2 for OIL2 source compiled to OIL2 Architecture Native Format.
Definition: OMEthreadCntrl.h:70
OMEcallStack::methodBody
const OMEinvocationData * methodBody
Definition: OMEthread.h:34
OMEtickInterval::OMEtickInterval
OMEtickInterval(class OMEthread *thread) NONNULL_CLASS_PARAMETERS(2)
Definition: OMEthreadCntrl.cpp:16
OMEthreadController::yieldSlice
virtual void yieldSlice()=0
Yield time slice currently being used by an active thread.
OMEthreadInterpretOIL2::OMEthreadInterpretOIL2
OMEthreadInterpretOIL2(OMEthread *t)
Definition: OMEthreadCntrl.cpp:394
OMEthreadController::~OMEthreadController
virtual ~OMEthreadController()
Definition: OMEthreadCntrl.h:32
LOG_CERR
#define LOG_CERR(lvl)
Convenience macro that uses LOG_INTO() to conditionally log a message to standard error.
Definition: logging_api.hpp:3014
OMEoil2Interpreter
int OMEoil2Interpreter(OMEthread *thread, const OMEtype &codeBody)
Entry point for the OIL2 Architecture Neutral Format interpreter.
Definition: copyIntrp.cpp:288
logging_api.hpp
FARGOS Logging API.
OMEtickInterval::~OMEtickInterval
~OMEtickInterval()
Definition: OMEthreadCntrl.cpp:24
OMEqueueOIL2thread
void OMEqueueOIL2thread(OMEthread *t)
Definition: OMEexecQueue.cpp:586
Generated: Fri Jul 31 2020 18:19:15
Support Information