Skip to content

Commit

Permalink
Merge pull request #137 from basiliscos/no-pthread-headers
Browse files Browse the repository at this point in the history
Disable inclusion pthread-heaaders via #ifdef
  • Loading branch information
frankinshtein committed May 11, 2019
2 parents 35de442 + 2bb00d7 commit bf49a09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion oxygine/src/oxygine/core/Mutex.cpp
Expand Up @@ -6,6 +6,7 @@ namespace oxygine
{
Mutex::Mutex(bool recursive)
{
#ifndef OX_NO_MT
if (recursive)
{
pthread_mutexattr_t mta;
Expand All @@ -18,20 +19,27 @@ namespace oxygine
{
pthread_mutex_init(&_handle, 0);
}
#endif
}

Mutex::~Mutex()
{
#ifndef OX_NO_MT
pthread_mutex_destroy(&_handle);
#endif
}

void Mutex::lock()
{
#ifndef OX_NO_MT
pthread_mutex_lock(&_handle);
#endif
}

void Mutex::unlock()
{
#ifndef OX_NO_MT
pthread_mutex_unlock(&_handle);
#endif
}
}
}
14 changes: 11 additions & 3 deletions oxygine/src/oxygine/core/ThreadDispatcher.cpp
Expand Up @@ -19,15 +19,19 @@ namespace oxygine
#endif


#ifndef OX_NO_MT
MutexPthreadLock::MutexPthreadLock(pthread_mutex_t& m, bool lock) : _mutex(m), _locked(lock)
{
if (_locked)
pthread_mutex_lock(&_mutex);
}
#endif

MutexPthreadLock::~MutexPthreadLock()
{
#ifndef OX_NO_MT
pthread_mutex_unlock(&_mutex);
#endif
}

ThreadDispatcher::ThreadDispatcher(): _id(0), _result(0)
Expand Down Expand Up @@ -192,8 +196,8 @@ namespace oxygine
#ifndef OX_NO_MT
//pthread_cond_signal(&_cond);
pthread_cond_broadcast(&_cond);
#endif
pthread_cond_wait(&_cond, &_mutex);
#endif
}
}

Expand All @@ -206,8 +210,8 @@ namespace oxygine
LOGDN("ThreadMessages::waiting reply... _replyingTo=%d myid=%d", _replyingTo, id);
#ifndef OX_NO_MT
pthread_cond_signal(&_cond);
#endif
pthread_cond_wait(&_cond, &_mutex);
#endif
}
while (_replyingTo != id);

Expand Down Expand Up @@ -364,11 +368,15 @@ namespace oxygine

std::vector<ThreadDispatcher::message>& ThreadDispatcher::lockMessages()
{
#ifndef OX_NO_MT
pthread_mutex_lock(&_mutex);
#endif
return _events;
}
void ThreadDispatcher::unlockMessages()
{
#ifndef OX_NO_MT
pthread_mutex_unlock(&_mutex);
#endif
}
}
}
6 changes: 5 additions & 1 deletion oxygine/src/oxygine/core/ThreadDispatcher.h
Expand Up @@ -15,11 +15,15 @@ namespace oxygine
class MutexPthreadLock
{
public:
#ifndef OX_NO_MT
MutexPthreadLock(pthread_mutex_t& m, bool lock = true);
#endif
~MutexPthreadLock();

protected:
#ifndef OX_NO_MT
pthread_mutex_t& _mutex;
#endif
bool _locked;
};
/*
Expand Down Expand Up @@ -144,4 +148,4 @@ namespace oxygine


typedef ThreadDispatcher ThreadMessages;
}
}

0 comments on commit bf49a09

Please sign in to comment.