Skip to content

Commit

Permalink
Switch to named semaphores for compatability
Browse files Browse the repository at this point in the history
Mac OS X has deprecated unnamed semaphores. This solves the problem and
maintains compatibility with all other POSIX implementations.
  • Loading branch information
SpamapS committed Dec 11, 2017
1 parent fb05e80 commit 8da9ee1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions libtest/signal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ shutdown_t SignalThread::get_shutdown()

void SignalThread::post()
{
sem_post(&lock);
sem_post(lock);
}

void SignalThread::test()
Expand Down Expand Up @@ -131,7 +131,7 @@ SignalThread::~SignalThread()
pthread_join(thread, &retval);
}
#endif
sem_destroy(&lock);
sem_close(lock);

unblock();
}
Expand Down Expand Up @@ -265,7 +265,7 @@ bool SignalThread::setup()
return false;
}

sem_wait(&lock);
sem_wait(lock);

return true;
}
3 changes: 2 additions & 1 deletion libtest/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace libtest {

class SignalThread {
sigset_t set;
sem_t lock;
char lock_name[10];
sem_t *lock;
uint64_t magic_memory;
volatile shutdown_t __shutdown;
pthread_mutex_t shutdown_mutex;
Expand Down
6 changes: 4 additions & 2 deletions util/signal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/

#include "gear_config.h"
#include <semaphore.h>
#include <unistd.h>

#include <cassert>
#include <cerrno>
Expand Down Expand Up @@ -88,7 +90,7 @@ shutdown_t SignalThread::get_shutdown()

void SignalThread::post()
{
sem_post(&lock);
sem_post(lock);
}

void SignalThread::test()
Expand Down Expand Up @@ -129,7 +131,7 @@ SignalThread::~SignalThread()
pthread_join(thread, &retval);
}
#endif
sem_destroy(&lock);
sem_close(lock);
}

extern "C" {
Expand Down

0 comments on commit 8da9ee1

Please sign in to comment.