Skip to content

Commit

Permalink
Some OSX build fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacu committed May 8, 2017
1 parent 41a0dc9 commit b81685e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/message.c
Expand Up @@ -50,16 +50,16 @@ static void initialize_sockets(void) {

#else

#ifdef _MAC_
#include <tcpd.h>
#else
#include <sys/socket.h>
#include <unistd.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#define closesocket close
#endif
//#ifdef __APPLE__
// #include <tcpd.h>
//#else
#include <sys/socket.h>
#include <unistd.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#define closesocket close
//#endif

#define __INLINE static inline

Expand Down
10 changes: 5 additions & 5 deletions support/client/client.cpp
Expand Up @@ -54,16 +54,16 @@ __inline void sleep(long time) {

#else

#ifdef _MAC_
#include <tcpd.h>
#else
//#ifdef __APPLE__
// #include <tcpd.h>
//#else
#include <sys/socket.h>
#include <unistd.h>
#include <sys/select.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#define closesocket close
#endif
//#endif

void sleepf(float seconds) {
usleep((long) (seconds * 1000000.0));
Expand Down
8 changes: 4 additions & 4 deletions support/client/threads.cpp
Expand Up @@ -108,7 +108,7 @@ void* simple_threads_join_thread(THREAD t) {
Mutex::Mutex() {
MUTEX_INIT(mutex);

owner = -1;
owner = THREAD_NONE;

counter = 0;

Expand All @@ -126,7 +126,7 @@ void Mutex::acquire() {
} else {
THREAD_IDENTIFIER tid = THREAD_GET_IDENTIFIER();

if (tid != owner) {
if (!THREAD_EQUALS(tid, owner)) {
MUTEX_LOCK(mutex);
owner = tid;
counter = 0;
Expand All @@ -145,11 +145,11 @@ void Mutex::release() {

THREAD_IDENTIFIER tid = THREAD_GET_IDENTIFIER();

if (tid == owner) {
if (THREAD_EQUALS(tid, owner)) {
counter--;

if (counter < 1) {
owner = -1;
owner = THREAD_NONE;
MUTEX_UNLOCK(mutex);
}
}
Expand Down
4 changes: 4 additions & 0 deletions support/client/threads.h
Expand Up @@ -40,6 +40,8 @@ extern "C" {
#define MUTEX_UNLOCK(M) ReleaseMutex(M)
#define MUTEX_INIT(M) (M = CreateMutex(NULL, FALSE, NULL))
#define MUTEX_DESTROY(M) WaitForSingleObject(M, INFINITE); CloseHandle(M)
#define THREAD_EQUALS(T1, T2) (T1 == T2)
#define THREAD_NONE -1

#define CONDITION_SIGNAL(C) SetEvent(C)
#define CONDITION_DESTROY(C) CloseHandle(C)
Expand Down Expand Up @@ -77,6 +79,8 @@ typedef struct pthread_wrapper {
#define MUTEX_UNLOCK(M) pthread_mutex_unlock(&M)
#define MUTEX_INIT(M) pthread_mutex_init(&M, NULL)
#define MUTEX_DESTROY(M) pthread_mutex_destroy(&M)
#define THREAD_EQUALS(T1, T2) (T1 == T2 || (T1 && T2 && pthread_equal(T1, T2)))
#define THREAD_NONE ((pthread_t) 0)

#define CONDITION_SIGNAL(C) pthread_cond_signal(&C)
#define CONDITION_DESTROY(C) pthread_cond_destroy(&C)
Expand Down
2 changes: 1 addition & 1 deletion support/client/timer.cpp
Expand Up @@ -4,7 +4,7 @@
#define WINDOWS
#include <windows.h>
#else
#ifdef _MAC_
#ifdef __APPLE__
#define OSX
#include <mach/mach.h>
#include <mach/mach_time.h>
Expand Down

0 comments on commit b81685e

Please sign in to comment.