-
Notifications
You must be signed in to change notification settings - Fork 49
macOS support (using compatibility libraries) #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
electricalgrade
wants to merge
6
commits into
OCEAN-xyz:master
Choose a base branch
from
electricalgrade:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59fb210
Update datum_protocol.c
electricalgrade c14b746
Update CMakeLists.txt
electricalgrade 6382187
Update datum_protocol.c
electricalgrade 4b7ea4b
Fix the epoll in a clean way
3aba2c9
Added clean way to handle apple platform. Remove nano sleep loop.
15eb38c
use consistant mutex lock and unlock
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include "portable_mutex.h" | ||
|
|
||
| #ifdef __APPLE__ | ||
| void apple_timed_mutex_init(timed_mutex_state_t *state) { | ||
| pthread_cond_init(&state->cond, NULL); | ||
| state->locked = 0; | ||
| } | ||
|
|
||
| int apple_mutex_timedlock(pthread_mutex_t *mutex, timed_mutex_state_t *state, const struct timespec *abstime) { | ||
| int rc; | ||
| pthread_mutex_lock(mutex); | ||
| while (state->locked) { | ||
| rc = pthread_cond_timedwait(&state->cond, mutex, abstime); | ||
| if (rc == ETIMEDOUT) { | ||
| pthread_mutex_unlock(mutex); | ||
| return ETIMEDOUT; | ||
| } | ||
| if (rc != 0) { | ||
| pthread_mutex_unlock(mutex); | ||
| return rc; | ||
| } | ||
| } | ||
| state->locked = 1; | ||
| pthread_mutex_unlock(mutex); | ||
| return 0; | ||
| } | ||
|
|
||
| void apple_mutex_lock(pthread_mutex_t *mutex, timed_mutex_state_t *state) { | ||
| pthread_mutex_lock(mutex); | ||
| while (state->locked) { | ||
| pthread_cond_wait(&state->cond, mutex); | ||
| } | ||
| state->locked = 1; | ||
| pthread_mutex_unlock(mutex); | ||
| } | ||
|
|
||
| void apple_mutex_unlock(pthread_mutex_t *mutex, timed_mutex_state_t *state) { | ||
| pthread_mutex_lock(mutex); | ||
| state->locked = 0; | ||
| pthread_cond_signal(&state->cond); | ||
| pthread_mutex_unlock(mutex); | ||
| } | ||
|
|
||
| void apple_timed_mutex_destroy(timed_mutex_state_t *state) { | ||
| pthread_cond_destroy(&state->cond); | ||
| } | ||
| #endif // __APPLE__ | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef PORTABLE_MUTEX_H | ||
| #define PORTABLE_MUTEX_H | ||
|
|
||
| #ifdef __APPLE__ | ||
| #include <pthread.h> | ||
| #include <time.h> | ||
| #include <errno.h> | ||
|
|
||
| // A struct to manage the state for a timed mutex on Apple | ||
| typedef struct { | ||
| pthread_cond_t cond; | ||
| int locked; | ||
| } timed_mutex_state_t; | ||
|
|
||
| // State management functions for timed mutexes on Apple | ||
| void apple_timed_mutex_init(timed_mutex_state_t *state); | ||
| int apple_mutex_timedlock(pthread_mutex_t *mutex, timed_mutex_state_t *state, const struct timespec *abstime); | ||
| void apple_mutex_lock(pthread_mutex_t *mutex, timed_mutex_state_t *state); | ||
| void apple_mutex_unlock(pthread_mutex_t *mutex, timed_mutex_state_t *state); | ||
| void apple_timed_mutex_destroy(timed_mutex_state_t *state); | ||
| #endif // __APPLE__ | ||
|
|
||
| #endif // PORTABLE_MUTEX_H | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.