remove __has_include(<pthread.h>)

This commit is contained in:
mutouyun 2019-01-24 23:47:45 +08:00
parent 512de713f1
commit e8dda2c1d4
3 changed files with 11 additions and 23 deletions

View File

@ -1,7 +1,3 @@
#if __has_include(<pthread.h>)
#include "tls_pointer_linux.cpp"
#else /*!__has_include(<pthread.h>)*/
#include "tls_pointer.h" #include "tls_pointer.h"
#include <Windows.h> // ::Tls... #include <Windows.h> // ::Tls...
@ -183,5 +179,3 @@ extern "C" NX_CRTALLOC_(".tls") const IMAGE_TLS_DIRECTORY _tls_used = {
#endif/*_MSC_VER, __GNUC__*/ #endif/*_MSC_VER, __GNUC__*/
} // namespace ipc } // namespace ipc
#endif/*!__has_include(<pthread.h>)*/

View File

@ -18,11 +18,11 @@ class waiter {
std::atomic<unsigned> counter_ { 0 }; std::atomic<unsigned> counter_ { 0 };
public: public:
using handle_t = waiter*; using handle_t = bool;
public: public:
constexpr static handle_t invalid() { constexpr static handle_t invalid() {
return nullptr; return false;
} }
handle_t open(char const * name) { handle_t open(char const * name) {
@ -63,26 +63,26 @@ public:
// release guards // release guards
guard_mutex.release(); guard_mutex.release();
} }
return this; return true;
} }
void close(handle_t h) { void close(handle_t h) {
if (h == invalid()) return; if (h == invalid()) return;
if (h->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) { if (counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) {
::printf("destroy...\n"); ::printf("destroy...\n");
::pthread_cond_destroy (&(h->cond_ )); ::pthread_cond_destroy(&cond_);
::pthread_mutex_destroy(&(h->mutex_)); ::pthread_mutex_destroy(&mutex_);
::printf("destroy end...\n"); ::printf("destroy end...\n");
} }
} }
bool wait(handle_t h) { bool wait(handle_t h) {
if (h == invalid()) return false; if (h == invalid()) return false;
if (::pthread_mutex_lock(&(h->mutex_)) != 0) { if (::pthread_mutex_lock(&mutex_) != 0) {
return false; return false;
} }
IPC_UNUSED_ auto guard = unique_ptr(&(h->mutex_), ::pthread_mutex_unlock); IPC_UNUSED_ auto guard = unique_ptr(&mutex_, ::pthread_mutex_unlock);
if (::pthread_cond_wait(&(h->cond_), &(h->mutex_)) != 0) { if (::pthread_cond_wait(&cond_, &mutex_) != 0) {
return false; return false;
} }
return true; return true;
@ -90,12 +90,12 @@ public:
void notify(handle_t h) { void notify(handle_t h) {
if (h == invalid()) return; if (h == invalid()) return;
::pthread_cond_signal(&(h->cond_)); ::pthread_cond_signal(&cond_);
} }
void broadcast(handle_t h) { void broadcast(handle_t h) {
if (h == invalid()) return; if (h == invalid()) return;
::pthread_cond_broadcast(&(h->cond_)); ::pthread_cond_broadcast(&cond_);
} }
}; };

View File

@ -1,9 +1,5 @@
#pragma once #pragma once
#if __has_include(<pthread.h>)
#include "waiter_linux.h"
#else /*!__has_include(<pthread.h>)*/
#include <Windows.h> #include <Windows.h>
#include <algorithm> #include <algorithm>
@ -59,5 +55,3 @@ public:
} // namespace detail } // namespace detail
} // namespace ipc } // namespace ipc
#endif/*!__has_include(<pthread.h>)*/