Pol  Revision:cb584c9
polsem.h
Go to the documentation of this file.
1 
7 #ifndef POLSEM_H
8 #define POLSEM_H
9 
10 // TODO: encapsulate the "locker" variable to remove those includes from here. Would a size_t work?
11 #ifdef _WIN32
12 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h>
14 #else
15 #include <pthread.h>
16 #include <unistd.h>
17 #endif
18 #include <atomic>
19 
20 namespace Pol
21 {
22 namespace Core
23 {
24 void init_ipc_vars();
25 void deinit_ipc_vars();
26 
27 void send_pulse();
28 void wait_for_pulse( unsigned int millis );
29 
30 void wake_tasks_thread();
31 void tasks_thread_sleep( unsigned int millis );
32 
34 void wait_for_ClientTransmit_pulse( unsigned int millis );
35 
36 extern size_t locker;
37 #ifdef _WIN32
38 extern CRITICAL_SECTION cs;
39 #else
40 extern pthread_mutex_t polsem;
41 #endif // not _WIN32
42 
43 void polsem_lock();
44 void polsem_unlock();
45 
46 class PolLock
47 {
48 public:
51 };
52 
53 class PolLock2
54 {
55 public:
56  PolLock2() : locked_( true ) { polsem_lock(); }
58  {
59  if ( locked_ )
60  polsem_unlock();
61  locked_ = false;
62  }
63 
64  void unlock()
65  {
66  polsem_unlock();
67  locked_ = false;
68  }
69  void lock()
70  {
71  polsem_lock();
72  locked_ = true;
73  }
74 
75 private:
76  bool locked_;
77 };
78 }
79 }
80 #endif // POLSEM_H
pthread_mutex_t polsem
Definition: polsem.cpp:142
void polsem_unlock()
Definition: polsem.cpp:57
void send_pulse()
Definition: polsem.cpp:188
void wake_tasks_thread()
Definition: polsem.cpp:230
void send_ClientTransmit_pulse()
Definition: polsem.cpp:250
void init_ipc_vars()
Definition: polsem.cpp:165
void wait_for_ClientTransmit_pulse(unsigned int millis)
Definition: polsem.cpp:257
size_t locker
Definition: polsem.cpp:27
void polsem_lock()
Definition: polsem.cpp:45
void deinit_ipc_vars()
Definition: polsem.cpp:186
void tasks_thread_sleep(unsigned int millis)
Definition: polsem.cpp:237
Definition: berror.cpp:12
void wait_for_pulse(unsigned int millis)
Definition: polsem.cpp:217