mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 04:33:35 +08:00
Simulator: Move to semaphore abstraction
This commit is contained in:
@@ -125,7 +125,7 @@ public:
|
|||||||
_max_readers(readers),
|
_max_readers(readers),
|
||||||
_report_len(sizeof(RType))
|
_report_len(sizeof(RType))
|
||||||
{
|
{
|
||||||
sem_init(&_lock, 0, _max_readers);
|
px4_sem_init(&_lock, 0, _max_readers);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Report() {};
|
~Report() {};
|
||||||
@@ -149,23 +149,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void read_lock() { sem_wait(&_lock); }
|
void read_lock() { px4_sem_wait(&_lock); }
|
||||||
void read_unlock() { sem_post(&_lock); }
|
void read_unlock() { px4_sem_post(&_lock); }
|
||||||
void write_lock()
|
void write_lock()
|
||||||
{
|
{
|
||||||
for (int i=0; i<_max_readers; i++) {
|
for (int i=0; i<_max_readers; i++) {
|
||||||
sem_wait(&_lock);
|
px4_sem_wait(&_lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void write_unlock()
|
void write_unlock()
|
||||||
{
|
{
|
||||||
for (int i=0; i<_max_readers; i++) {
|
for (int i=0; i<_max_readers; i++) {
|
||||||
sem_post(&_lock);
|
px4_sem_post(&_lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _readidx;
|
int _readidx;
|
||||||
sem_t _lock;
|
px4_sem_t _lock;
|
||||||
const int _max_readers;
|
const int _max_readers;
|
||||||
const int _report_len;
|
const int _report_len;
|
||||||
RType _buf[2];
|
RType _buf[2];
|
||||||
|
|||||||
Reference in New Issue
Block a user