forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename MavLinkSemaphore to just Semaphore and add Apple OSX implement…
…aiton.
- Loading branch information
1 parent
a34d47c
commit 878b70f
Showing
11 changed files
with
308 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 43 additions & 46 deletions
89
MavLinkCom/include/MavLinkSemaphore.hpp → MavLinkCom/include/Semaphore.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#ifndef MavLinkCom_Semaphore_hpp | ||
#define MavLinkCom_Semaphore_hpp | ||
#include <memory> | ||
|
||
#ifdef __APPLE__ | ||
#include <semaphore.h> | ||
#endif | ||
|
||
namespace mavlinkcom | ||
{ | ||
/* | ||
A semaphore is used to signal an event across threads. One thread blocks on Wait() until | ||
the other thread calls Signal. It is a counting semaphore so if the thread calls Signal | ||
before the Wait() then the Wait() does not block. | ||
*/ | ||
class MavLinkSemaphore | ||
{ | ||
public: | ||
MavLinkSemaphore(); | ||
~MavLinkSemaphore(); | ||
|
||
// Increment the semaphore count to unblock the next waiter (the next wait caller will return). | ||
// Throws exception if an error occurs. | ||
void post(); | ||
|
||
// wait indefinitely for one call to post. If post has already been called then wait returns immediately | ||
// decrementing the count so the next wait in the queue will block. Throws exception if an error occurs. | ||
void wait(); | ||
|
||
// wait for a given number of milliseconds for one call to post. Returns false if a timeout or EINTR occurs. | ||
// If post has already been called then timed_wait returns immediately decrementing the count so the next | ||
// wait will block. Throws exception if an error occurs. | ||
bool timed_wait(int milliseconds); | ||
private: | ||
class semaphore_impl; | ||
std::unique_ptr<semaphore_impl> impl_; | ||
}; | ||
} | ||
|
||
#endif | ||
#ifdef __APPLE__ | ||
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); | ||
#endif | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#ifndef common_utils_Semaphore_hpp | ||
#define common_utils_Semaphore_hpp | ||
#include <memory> | ||
|
||
#ifdef __APPLE__ | ||
#include <semaphore.h> | ||
#endif | ||
|
||
namespace mavlink_utils | ||
{ | ||
/* | ||
A semaphore is used to signal an event across threads. One thread blocks on Wait() until | ||
the other thread calls Signal. It is a counting semaphore so if the thread calls Signal | ||
before the Wait() then the Wait() does not block. | ||
*/ | ||
class Semaphore | ||
{ | ||
public: | ||
Semaphore(); | ||
~Semaphore(); | ||
|
||
// Increment the semaphore count to unblock the next waiter (the next wait caller will return). | ||
// Throws exception if an error occurs. | ||
void post(); | ||
|
||
// wait indefinitely for one call to post. If post has already been called then wait returns immediately | ||
// decrementing the count so the next wait in the queue will block. Throws exception if an error occurs. | ||
void wait(); | ||
|
||
// wait for a given number of milliseconds for one call to post. Returns false if a timeout or EINTR occurs. | ||
// If post has already been called then timed_wait returns immediately decrementing the count so the next | ||
// wait will block. Throws exception if an error occurs. | ||
bool timed_wait(int milliseconds); | ||
private: | ||
class semaphore_impl; | ||
std::unique_ptr<semaphore_impl> impl_; | ||
}; | ||
} | ||
|
||
#endif |
Oops, something went wrong.