Skip to content

Commit

Permalink
Merge b0bdfd5 into f6642ac
Browse files Browse the repository at this point in the history
  • Loading branch information
qaz734913414 committed Mar 23, 2020
2 parents f6642ac + b0bdfd5 commit 92377d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -268,6 +268,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC"
target_compile_definitions(ncnn
PRIVATE _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE)
else()
target_compile_definitions(ncnn
PRIVATE _MinGw)
target_compile_options(ncnn
PRIVATE -Wall -Wextra -Wno-unused-function)
if(NOT NCNN_DISABLE_PIC)
Expand Down
49 changes: 46 additions & 3 deletions src/platform.h.in
Expand Up @@ -26,9 +26,13 @@
#cmakedefine01 NCNN_AVX2

#ifdef _WIN32
#ifdef _MinGw
#include <pthread.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#endif
#else
#include <pthread.h>
#endif
Expand All @@ -40,6 +44,19 @@
namespace ncnn {

#ifdef _WIN32
#ifdef _MinGw
class Mutex
{
public:
Mutex() { pthread_mutex_init(&mutex, 0); }
~Mutex() { pthread_mutex_destroy(&mutex); }
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }
private:
friend class ConditionVariable;
pthread_mutex_t mutex;
};
#else
class Mutex
{
public:
Expand All @@ -52,6 +69,7 @@ private:
// NOTE SRWLock is available from windows vista
SRWLOCK srwlock;
};
#endif
#else // _WIN32
class Mutex
{
Expand All @@ -75,7 +93,20 @@ private:
Mutex& mutex;
};

#if _WIN32
#ifdef _WIN32
#ifdef _MinGw
class ConditionVariable
{
public:
ConditionVariable() { pthread_cond_init(&cond, 0); }
~ConditionVariable() { pthread_cond_destroy(&cond); }
void wait(Mutex& mutex) { pthread_cond_wait(&cond, &mutex.mutex); }
void broadcast() { pthread_cond_broadcast(&cond); }
void signal() { pthread_cond_signal(&cond); }
private:
pthread_cond_t cond;
};
#else
class ConditionVariable
{
public:
Expand All @@ -87,6 +118,7 @@ public:
private:
CONDITION_VARIABLE condvar;
};
#endif
#else // _WIN32
class ConditionVariable
{
Expand All @@ -101,7 +133,18 @@ private:
};
#endif // _WIN32

#if _WIN32
#ifdef _WIN32
#ifdef _MinGw
class Thread
{
public:
Thread(void* (*start)(void*), void* args = 0) { pthread_create(&t, 0, start, args); }
~Thread() {}
void join() { pthread_join(t, 0); }
private:
pthread_t t;
};
#else
static unsigned __stdcall start_wrapper(void* args);
class Thread
{
Expand All @@ -120,7 +163,7 @@ private:
void* (*_start)(void*);
void* _args;
};

#endif
#else // _WIN32
class Thread
{
Expand Down

0 comments on commit 92377d1

Please sign in to comment.