20 #ifndef LUNCHBOX_THREAD_H    21 #define LUNCHBOX_THREAD_H    24 #include <lunchbox/debug.h>        25 #include <lunchbox/threadID.h>     28 #include <boost/noncopyable.hpp>    63     LUNCHBOX_API 
virtual ~
Thread();
    73     LUNCHBOX_API 
virtual bool start();
    86     virtual bool init() { 
return true; }
    95     virtual void run() = 0;
   105     LUNCHBOX_API 
virtual void exit();
   113     LUNCHBOX_API 
void cancel();
   121     LUNCHBOX_API 
bool join();
   132     LUNCHBOX_API 
bool isStopped() 
const;
   143     LUNCHBOX_API 
bool isRunning() 
const;
   150     LUNCHBOX_API 
bool isCurrent() 
const;
   153     LUNCHBOX_API 
static ThreadID getSelfThreadID();
   156     LUNCHBOX_API 
static void yield();
   159     LUNCHBOX_API 
static void setName(
const std::string& name);
   171     LUNCHBOX_API 
static void setAffinity(
const int32_t affinity);
   174     detail::Thread* 
const _impl;
   177     static void* runChild(
void* arg);
   180     LUNCHBOX_API 
friend void abort(
bool);
   181     static void _dumpAll();
   193 #define LB_CHECK_THREADSAFETY   197 #define LB_TS_VAR(NAME)                      \   199     struct NAME##Struct                      \   205         mutable lunchbox::ThreadID id;       \   206         mutable std::string name;            \   208         mutable lunchbox::ThreadID inRegion; \   213 #ifdef LB_CHECK_THREADSAFETY   214 #define LB_TS_RESET(NAME) NAME.id = lunchbox::ThreadID();   216 #define LB_TS_THREAD(NAME)                                                    \   218         if (NAME.id == lunchbox::ThreadID())                                  \   220             NAME.id = lunchbox::Thread::getSelfThreadID();                    \   221             NAME.name = lunchbox::Log::instance().getThreadName();            \   222             LBVERB << "Functions for " << #NAME << " locked from"             \   223                    << lunchbox::backtrace << std::endl;                       \   225         if (!NAME.extMutex && NAME.id != lunchbox::Thread::getSelfThreadID()) \   227             LBERROR << "Threadsafety check for " << #NAME                     \   228                     << " failed on object of type "                           \   229                     << lunchbox::className(this) << ", thread "               \   230                     << lunchbox::Thread::getSelfThreadID() << " ("            \   231                     << lunchbox::Log::instance().getThreadName()              \   232                     << ") != " << NAME.id << " (" << NAME.name << ")"         \   234             LBABORT("Non-threadsafe code called from two threads");           \   238 #define LB_TS_NOT_THREAD(NAME)                                     \   240         if (!NAME.extMutex && NAME.id != lunchbox::ThreadID())     \   242             if (NAME.id == lunchbox::Thread::getSelfThreadID())    \   244                 LBERROR << "Threadsafety check for not " << #NAME  \   245                         << " failed on object of type "            \   246                         << lunchbox::className(this) << std::endl; \   247                 LBABORT("Code called from wrong thread");          \   253 template <
typename T>
   254 class ScopedThreadCheck : 
public boost::noncopyable
   257     explicit ScopedThreadCheck(
const T& data)
   262                      "Another thread already in critical region");
   270                      "Another thread entered critical region");
   279 #define LB_TS_SCOPED(NAME) \   280     lunchbox::ScopedThreadCheck<NAME##Struct> scoped##NAME##Check(NAME);   283 #define LB_TS_RESET(NAME) \   286 #define LB_TS_THREAD(NAME) \   289 #define LB_TS_NOT_THREAD(NAME) \   292 #define LB_TS_SCOPED(NAME) \   297 #endif // LUNCHBOX_THREAD_H static ThreadID getSelfThreadID()
 
Defines export visibility macros for library Lunchbox. 
 
Basic type definitions not provided by the operating system. 
 
bool exit()
De-initialize the Lunchbox base classes. 
 
Affinity
Enumeration values for thread affinity. 
 
Utility class to execute code in a separate execution thread. 
 
An utility class to wrap OS-specific thread identifiers. 
 
Abstraction layer and common utilities for multi-threaded programming. 
 
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array. 
 
virtual bool init()
The init function for the child thread.