Build Nazara on macos up to Nazara_network (not included

This commit is contained in:
ImperatorS79
2020-11-21 20:05:19 +01:00
parent d243e7bcd2
commit 4bf49876c6
13 changed files with 158 additions and 18 deletions

View File

@@ -6,6 +6,10 @@
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/Debug.hpp>
#if defined(NAZARA_PLATFORM_MACOSX)
#include <errno.h>
#endif
namespace Nz
{
bool TaskSchedulerImpl::Initialize(unsigned int workerCount)
@@ -191,4 +195,55 @@ namespace Nz
pthread_cond_t TaskSchedulerImpl::s_cvEmpty;
pthread_cond_t TaskSchedulerImpl::s_cvNotEmpty;
pthread_barrier_t TaskSchedulerImpl::s_barrier;
#if defined(NAZARA_PLATFORM_MACOSX)
//Code from https://blog.albertarmea.com/post/47089939939/using-pthreadbarrier-on-mac-os-x
int TaskSchedulerImpl::pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
{
if(count == 0)
{
errno = EINVAL;
return -1;
}
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
{
return -1;
}
if(pthread_cond_init(&barrier->cond, 0) < 0)
{
pthread_mutex_destroy(&barrier->mutex);
return -1;
}
barrier->tripCount = count;
barrier->count = 0;
return 0;
}
int TaskSchedulerImpl::pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_cond_destroy(&barrier->cond);
pthread_mutex_destroy(&barrier->mutex);
return 0;
}
int TaskSchedulerImpl::pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->tripCount)
{
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
pthread_mutex_unlock(&barrier->mutex);
return 0;
}
}
#endif
}