QTrk
Classes | Public Types | Static Public Member Functions | List of all members
Threads Struct Reference

Thread OS related code is abstracted into a simple "Threads" struct. More...

#include <threads.h>

Classes

struct  Handle
 
struct  Mutex
 

Public Types

typedef void(* ThreadEntryPoint) (void *param)
 

Static Public Member Functions

static DWORD WINAPI ThreadCaller (void *param)
 
static HandleCreate (ThreadEntryPoint method, void *param)
 
static bool RunningVistaOrBetter ()
 
static void SetBackgroundPriority (Handle *thread, bool bg)
 
static void WaitAndClose (Handle *h)
 
static void Sleep (int ms)
 
static int GetCPUCount ()
 

Detailed Description

Thread OS related code is abstracted into a simple "Threads" struct.

Definition at line 51 of file threads.h.

Member Typedef Documentation

§ ThreadEntryPoint

typedef void(* Threads::ThreadEntryPoint) (void *param)

Definition at line 53 of file threads.h.

Member Function Documentation

§ Create()

static Handle* Threads::Create ( ThreadEntryPoint  method,
void *  param 
)
inlinestatic

Definition at line 99 of file threads.h.

99  {
100  Handle* hdl = new Handle;
101  hdl->param = param;
102  hdl->callback = method;
103  hdl->winhdl = CreateThread(0, 0, ThreadCaller, hdl, 0, &hdl->threadID);
104 
105  if (!hdl->winhdl) {
106  throw std::runtime_error("Failed to create processing thread.");
107  }
108  return hdl;
109  }
static DWORD WINAPI ThreadCaller(void *param)
Definition: threads.h:93

§ GetCPUCount()

static int Threads::GetCPUCount ( )
inlinestatic

Definition at line 138 of file threads.h.

138  {
139  // preferably
140  #ifdef WIN32
141  SYSTEM_INFO sysInfo;
142  GetSystemInfo(&sysInfo);
143  return sysInfo.dwNumberOfProcessors;
144  #else
145  return 4;
146  #endif
147  }

§ RunningVistaOrBetter()

static bool Threads::RunningVistaOrBetter ( )
inlinestatic

Definition at line 111 of file threads.h.

112  {
113  OSVERSIONINFO v;
114  GetVersionEx(&v);
115  return v.dwMajorVersion >= 6;
116  }

§ SetBackgroundPriority()

static void Threads::SetBackgroundPriority ( Handle thread,
bool  bg 
)
inlinestatic

Definition at line 118 of file threads.h.

119  {
120  HANDLE h = (HANDLE)thread;
121  // >= Windows Vista
122  if (RunningVistaOrBetter())
123  SetThreadPriority(h, bg ? THREAD_MODE_BACKGROUND_BEGIN : THREAD_MODE_BACKGROUND_END);
124  else
125  SetThreadPriority(h, bg ? THREAD_PRIORITY_BELOW_NORMAL : THREAD_PRIORITY_NORMAL);
126  }
static bool RunningVistaOrBetter()
Definition: threads.h:111

§ Sleep()

static void Threads::Sleep ( int  ms)
inlinestatic

Definition at line 134 of file threads.h.

134  {
135  ::Sleep(ms);
136  }
static void Sleep(int ms)
Definition: threads.h:134

§ ThreadCaller()

static DWORD WINAPI Threads::ThreadCaller ( void *  param)
inlinestatic

Definition at line 93 of file threads.h.

93  {
94  Handle* hdl = (Handle*)param;
95  hdl->callback (hdl->param);
96  return 0;
97  }

§ WaitAndClose()

static void Threads::WaitAndClose ( Handle h)
inlinestatic

Definition at line 128 of file threads.h.

128  {
129  WaitForSingleObject(h->winhdl, INFINITE);
130  CloseHandle(h->winhdl);
131  delete h;
132  }

The documentation for this struct was generated from the following file: