OverSim
XmlRpcThread.cc
Go to the documentation of this file.
1 
7 #if defined(XMLRPC_THREADS)
8 
9 #include "XmlRpcThread.h"
10 
11 #if defined(_WINDOWS)
12 # define WIN32_LEAN_AND_MEAN
13 # include <windows.h>
14 # include <process.h>
15 #else
16 # include <pthread.h>
17 #endif
18 
19 
20 using namespace XmlRpc;
21 
22 
25 {
26  if (_pThread)
27  {
28 #if defined(_WINDOWS)
29  ::CloseHandle((HANDLE)_pThread);
30 #else
31  ::pthread_detach((pthread_t)_pThread);
32 #endif
33  _pThread = 0;
34  }
35 }
36 
39 void
41 {
42  if ( ! _pThread)
43  {
44 #if defined(_WINDOWS)
45  unsigned threadID;
46  _pThread = (HANDLE)_beginthreadex(NULL, 0, &runInThread, this, 0, &threadID);
47 #else
48  ::pthread_create((pthread_t*) &_pThread, NULL, &runInThread, this);
49 #endif
50  }
51 }
52 
54 void
56 {
57  if (_pThread)
58  {
59 #if defined(_WINDOWS)
60  ::WaitForSingleObject(_pThread, INFINITE);
61  ::CloseHandle(_pThread);
62 #else
63  ::pthread_join((pthread_t)_pThread, 0);
64 #endif
65  _pThread = 0;
66  }
67 }
68 
70 unsigned int
71 XmlRpcThread::runInThread(void* pThread)
72 {
73  XmlRpcThread* t = (XmlRpcThread*)pThread;
74  t->getRunnable()->run();
75  return 0;
76 }
77 
78 #endif // XMLRPC_THREADS
79 
80