1 #ifndef THREADS_HEADER_GUARD
2 #define THREADS_HEADER_GUARD
135 std::thread internal_thread;
139 pthread_t internal_thread;
163 static void *mainRun_(
void *p);
A thread-safe combination of a fifo (first-in-first-out) queue and an associated stack.
Definition: framefifo.h:83
A demo thread for testing the producer/consumer module for fifos.
Definition: thread.h:223
void preRun()
Called before entering the main execution loop, but after creating the thread.
Definition: thread.cpp:269
void run()
Main execution loop is defined here.
Definition: thread.cpp:271
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: thread.cpp:270
FrameFifo * framefifo
Consume frames from here.
Definition: thread.h:234
A demo thread for testing the producer/consumer module for fifos.
Definition: thread.h:199
FrameFifo * framefifo
Feed frames here.
Definition: thread.h:210
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: thread.cpp:249
void run()
Main execution loop is defined here.
Definition: thread.cpp:250
void preRun()
Called before entering the main execution loop, but after creating the thread.
Definition: thread.cpp:248
A class for multithreading with a signaling system.
Definition: thread.h:87
virtual void requestStopCall()
API method: stops the thread.
Definition: thread.cpp:200
std::condition_variable condition
Condition variable for the signal queue (triggered when all signals processed). Not necessarily used ...
Definition: thread.h:125
virtual void waitStopCall()
API method: waits until the thread is joined.
Definition: thread.cpp:213
void operator=(const Thread &)
Void copy-constructor: this class is non-copyable.
Thread(const Thread &)
Void copy-constructor: this class is non-copyable.
virtual void sendSignal(SignalContext signal_ctx)
Send a signal to the thread.
Definition: thread.cpp:218
std::string name
Name of the thread.
Definition: thread.h:116
~Thread()
Destructor:not virtual.
Definition: thread.cpp:45
std::mutex loop_mutex
Protects thread's main execution loop (if necessary)
Definition: thread.h:127
std::mutex start_mutex
Mutex protecting start_condition.
Definition: thread.h:121
void setAffinity(int i)
API method for setting the thread affinity.
Definition: thread.cpp:58
virtual void postRun()=0
Called after the main execution loop exits, but before joining the thread.
void closeThread()
Sends exit signal to the thread, calls join. This method blocks until thread has exited....
Definition: thread.cpp:91
virtual void preJoin()
Called before the thread is joined.
Definition: thread.cpp:126
std::mutex mutex
Mutex protecting the condition variable and signal queue.
Definition: thread.h:124
void startCall()
API method: starts the thread.
Definition: thread.cpp:134
pthread_attr_t thread_attr
Thread attributes, pthread_* way.
Definition: thread.h:137
std::condition_variable start_condition
Notified when the thread has been started.
Definition: thread.h:122
Thread(const char *name)
Default constructor.
Definition: thread.cpp:41
virtual void stopCall()
API method: stops the thread.
Definition: thread.cpp:184
bool has_thread
true if thread has been started
Definition: thread.h:117
virtual void run()=0
Main execution loop is defined here.
virtual void waitReady()
Wait until thread has processed all its signals.
Definition: thread.cpp:234
std::deque< SignalContext > signal_fifo
Signal queue (fifo). Redefine in child classes.
Definition: thread.h:129
virtual void preRun()=0
Called before entering the main execution loop, but after creating the thread.
virtual void sendSignalAndWait(SignalContext signal_ctx)
Send a signal to the thread and wait for all signals to be executed.
Definition: thread.cpp:225
bool loop
Use this boolean to control if the main loop in Thread:run should exit.
Definition: thread.h:130
void mainRun()
Does the preRun, run, postRun sequence.
Definition: thread.cpp:68
virtual void postJoin()
Called after the thread has been joined.
Definition: thread.cpp:129
Thread safe system of fifo and a stack.
Signal
List of possible signals for the thread.
Definition: thread.h:60
Encapsulates data sent by the signal.
Definition: thread.h:74
An example of information context sent to the Thread inside Thread::SignalContext.
Definition: thread.h:49
@ none
undefined (initial value)
Definition: usbthread.h:143