Now you can download a copy of these docs so you can use them offline! Download now
Synchronized.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef SYNCHRONIZED_H
8 #define SYNCHRONIZED_H
9 
10 #include <semLib.h>
11 
12 #include "Base.h"
13 
14 #define CRITICAL_REGION(s) { Synchronized _sync(s);
15 #define END_REGION }
16 
17 class Synchronized;
18 
32 {
33 public:
34  explicit ReentrantSemaphore() {
35  m_semaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE);
36  }
38  semDelete(m_semaphore);
39  }
40 
45  int take() {
46  return semTake(m_semaphore, WAIT_FOREVER);
47  }
48 
53  int give() {
54  return semGive(m_semaphore);
55  }
56 
57 private:
58  SEM_ID m_semaphore;
59 
60  friend class Synchronized;
61  DISALLOW_COPY_AND_ASSIGN(ReentrantSemaphore);
62 };
63 
83 {
84 public:
85  explicit Synchronized(SEM_ID);
87  virtual ~Synchronized();
88 private:
89  SEM_ID m_semaphore;
90 
91  DISALLOW_COPY_AND_ASSIGN(Synchronized);
92 };
93 
94 #endif
Synchronized(SEM_ID)
virtual ~Synchronized()

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6