Build Nazara on macos up to Nazara_network (not included
This commit is contained in:
@@ -31,8 +31,8 @@ namespace Nz
|
||||
{
|
||||
if (!m_endOfFileUpdated)
|
||||
{
|
||||
struct stat64 fileSize;
|
||||
if (fstat64(m_fileDescriptor, &fileSize) == -1)
|
||||
struct Stat fileSize;
|
||||
if (Fstat(m_fileDescriptor, &fileSize) == -1)
|
||||
fileSize.st_size = 0;
|
||||
|
||||
m_endOfFile = (GetCursorPos() >= static_cast<UInt64>(fileSize.st_size));
|
||||
@@ -50,7 +50,7 @@ namespace Nz
|
||||
|
||||
UInt64 FileImpl::GetCursorPos() const
|
||||
{
|
||||
off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR);
|
||||
Off_t position = Lseek(m_fileDescriptor, 0, SEEK_CUR);
|
||||
return static_cast<UInt64>(position);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Nz
|
||||
if (mode & OpenMode_Truncate)
|
||||
flags |= O_TRUNC;
|
||||
|
||||
int fileDescriptor = open64(filePath.generic_u8string().data(), flags, permissions);
|
||||
int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions);
|
||||
if (fileDescriptor == -1)
|
||||
{
|
||||
NazaraError("Failed to open \"" + filePath.generic_u8string() + "\" : " + Error::GetLastSystemError());
|
||||
@@ -166,12 +166,12 @@ namespace Nz
|
||||
|
||||
m_endOfFileUpdated = false;
|
||||
|
||||
return lseek64(m_fileDescriptor, offset, moveMethod) != -1;
|
||||
return Lseek(m_fileDescriptor, offset, moveMethod) != -1;
|
||||
}
|
||||
|
||||
bool FileImpl::SetSize(UInt64 size)
|
||||
{
|
||||
return ftruncate64(m_fileDescriptor, size) != 0;
|
||||
return Ftruncate(m_fileDescriptor, size) != 0;
|
||||
}
|
||||
|
||||
std::size_t FileImpl::Write(const void* buffer, std::size_t size)
|
||||
|
||||
@@ -16,6 +16,24 @@
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_MACOSX)
|
||||
#define Stat stat
|
||||
#define Fstat fstat
|
||||
#define Off_t off_t
|
||||
#define Lseek lseek
|
||||
#define Open_def open
|
||||
#define Ftruncate ftruncate
|
||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
||||
#define Stat stat64
|
||||
#define Fstat fstat64
|
||||
#define Off_t off64_t
|
||||
#define Lseek lseek64
|
||||
#define Open_def open64
|
||||
#define Ftruncate ftruncate64
|
||||
#else
|
||||
#error This operating system is not fully supported by the Nazara Engine
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class 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
|
||||
}
|
||||
|
||||
@@ -13,6 +13,17 @@
|
||||
#include <pthread.h>
|
||||
#include <queue>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_MACOSX)
|
||||
typedef int pthread_barrierattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int count;
|
||||
int tripCount;
|
||||
} pthread_barrier_t;
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct Functor;
|
||||
@@ -45,6 +56,12 @@ namespace Nz
|
||||
static pthread_cond_t s_cvEmpty;
|
||||
static pthread_cond_t s_cvNotEmpty;
|
||||
static pthread_barrier_t s_barrier;
|
||||
|
||||
#if defined(NAZARA_PLATFORM_MACOSX)
|
||||
static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count);
|
||||
static int pthread_barrier_destroy(pthread_barrier_t *barrier);
|
||||
static int pthread_barrier_wait(pthread_barrier_t *barrier);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Nz
|
||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
||||
std::string_view temp(string);
|
||||
// Nothing to do
|
||||
#elif defined(NAZARA_PLATFORM_MACOS)
|
||||
#elif defined(NAZARA_PLATFORM_MACOSX)
|
||||
std::string temp(string);
|
||||
ReplaceStr(temp, "\n", "\r");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user