Last change
on this file since 7533 was 7533, checked in by Christoph Mayer, 15 years ago |
-fix für löschen von timer objekten welche noch aktive messages in der queue haben
|
File size:
921 bytes
|
Line | |
---|
1 | #ifndef __INTERRUPTABLE_SLEEPER_H
|
---|
2 | #define __INTERRUPTABLE_SLEEPER_H
|
---|
3 |
|
---|
4 | #include <boost/thread/mutex.hpp>
|
---|
5 | #include <cassert>
|
---|
6 | #include <iostream>
|
---|
7 |
|
---|
8 | using std::cout;
|
---|
9 |
|
---|
10 | #ifdef WIN32
|
---|
11 | #define WIN32_LEAN_AND_MEAN
|
---|
12 | #include <windows.h>
|
---|
13 | #else
|
---|
14 | #include <pthread.h>
|
---|
15 | #include <time.h>
|
---|
16 | #include <stdio.h>
|
---|
17 | #include <stdlib.h>
|
---|
18 | #include <sys/types.h>
|
---|
19 | #include <sys/timeb.h>
|
---|
20 | #include <unistd.h>
|
---|
21 | #include <errno.h>
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | namespace spovnet {
|
---|
25 | namespace common {
|
---|
26 |
|
---|
27 | class InterruptableSleeper {
|
---|
28 | public:
|
---|
29 | InterruptableSleeper();
|
---|
30 | ~InterruptableSleeper();
|
---|
31 |
|
---|
32 | void sleep(unsigned long millis);
|
---|
33 | void interrupt();
|
---|
34 |
|
---|
35 | private:
|
---|
36 |
|
---|
37 | #ifdef WIN32
|
---|
38 | HANDLE m_handle;
|
---|
39 | #else
|
---|
40 | typedef struct _MUTEX_COND {
|
---|
41 | pthread_cond_t cond;
|
---|
42 | pthread_mutex_t mutex;
|
---|
43 | } MUTEX_COND, *PMUTEX_COND;
|
---|
44 |
|
---|
45 | PMUTEX_COND m_handle;
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | boost::mutex m_mutex;
|
---|
49 | };
|
---|
50 |
|
---|
51 | }
|
---|
52 | } // namespace spovnet, common
|
---|
53 |
|
---|
54 | #endif // __INTERRUPTABLE_SLEEPER_H
|
---|
Note:
See
TracBrowser
for help on using the repository browser.