mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
waiter_impl -> waiter_wrapper
This commit is contained in:
parent
e8dda2c1d4
commit
a4b93f60cf
@ -4,8 +4,6 @@ TARGET = ipc
|
|||||||
CONFIG -= qt
|
CONFIG -= qt
|
||||||
CONFIG += c++14 c++1z # may be useless
|
CONFIG += c++14 c++1z # may be useless
|
||||||
|
|
||||||
!msvc:QMAKE_CXXFLAGS += -Wno-attributes -Wno-missing-field-initializers
|
|
||||||
|
|
||||||
DEFINES += __IPC_LIBRARY__
|
DEFINES += __IPC_LIBRARY__
|
||||||
DESTDIR = ../output
|
DESTDIR = ../output
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ HEADERS += \
|
|||||||
../src/memory/wrapper.h \
|
../src/memory/wrapper.h \
|
||||||
../src/memory/resource.h \
|
../src/memory/resource.h \
|
||||||
../src/platform/detail.h \
|
../src/platform/detail.h \
|
||||||
../src/platform/waiter.h \
|
../src/platform/waiter_wrapper.h \
|
||||||
../src/circ/elem_def.h \
|
../src/circ/elem_def.h \
|
||||||
../src/circ/elem_array.h \
|
../src/circ/elem_array.h \
|
||||||
../src/prod_cons.h \
|
../src/prod_cons.h \
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "rw_lock.h"
|
#include "rw_lock.h"
|
||||||
|
|
||||||
#include "platform/waiter.h"
|
#include "platform/waiter_wrapper.h"
|
||||||
#include "platform/detail.h"
|
#include "platform/detail.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|||||||
@ -68,8 +68,8 @@ public:
|
|||||||
|
|
||||||
void close(handle_t h) {
|
void close(handle_t h) {
|
||||||
if (h == invalid()) return;
|
if (h == invalid()) return;
|
||||||
|
::printf("closing...\n");
|
||||||
if (counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) {
|
if (counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) {
|
||||||
::printf("destroy...\n");
|
|
||||||
::pthread_cond_destroy(&cond_);
|
::pthread_cond_destroy(&cond_);
|
||||||
::pthread_mutex_destroy(&mutex_);
|
::pthread_mutex_destroy(&mutex_);
|
||||||
::printf("destroy end...\n");
|
::printf("destroy end...\n");
|
||||||
@ -78,6 +78,7 @@ public:
|
|||||||
|
|
||||||
bool wait(handle_t h) {
|
bool wait(handle_t h) {
|
||||||
if (h == invalid()) return false;
|
if (h == invalid()) return false;
|
||||||
|
::printf("wait...\n");
|
||||||
if (::pthread_mutex_lock(&mutex_) != 0) {
|
if (::pthread_mutex_lock(&mutex_) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -90,11 +91,13 @@ public:
|
|||||||
|
|
||||||
void notify(handle_t h) {
|
void notify(handle_t h) {
|
||||||
if (h == invalid()) return;
|
if (h == invalid()) return;
|
||||||
|
::printf("notify...\n");
|
||||||
::pthread_cond_signal(&cond_);
|
::pthread_cond_signal(&cond_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(handle_t h) {
|
void broadcast(handle_t h) {
|
||||||
if (h == invalid()) return;
|
if (h == invalid()) return;
|
||||||
|
::printf("broadcast...\n");
|
||||||
::pthread_cond_broadcast(&cond_);
|
::pthread_cond_broadcast(&cond_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
namespace ipc {
|
namespace ipc {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class waiter_impl {
|
class waiter_wrapper {
|
||||||
public:
|
public:
|
||||||
using waiter_t = detail::waiter;
|
using waiter_t = detail::waiter;
|
||||||
|
|
||||||
@ -20,12 +20,12 @@ private:
|
|||||||
waiter_t::handle_t h_ = waiter_t::invalid();
|
waiter_t::handle_t h_ = waiter_t::invalid();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
waiter_impl() = default;
|
waiter_wrapper() = default;
|
||||||
explicit waiter_impl(waiter_t* w) {
|
explicit waiter_wrapper(waiter_t* w) {
|
||||||
attach(w);
|
attach(w);
|
||||||
}
|
}
|
||||||
waiter_impl(const waiter_impl&) = delete;
|
waiter_wrapper(const waiter_wrapper&) = delete;
|
||||||
waiter_impl& operator=(const waiter_impl&) = delete;
|
waiter_wrapper& operator=(const waiter_wrapper&) = delete;
|
||||||
|
|
||||||
waiter_t * waiter() { return w_; }
|
waiter_t * waiter() { return w_; }
|
||||||
waiter_t const * waiter() const { return w_; }
|
waiter_t const * waiter() const { return w_; }
|
||||||
@ -15,15 +15,15 @@
|
|||||||
#include "shm.h"
|
#include "shm.h"
|
||||||
#include "rw_lock.h"
|
#include "rw_lock.h"
|
||||||
|
|
||||||
#include "platform/waiter.h"
|
#include "platform/waiter_wrapper.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class queue_waiter {
|
class queue_waiter {
|
||||||
protected:
|
protected:
|
||||||
ipc::detail::waiter_impl waiter_;
|
ipc::detail::waiter_wrapper waiter_;
|
||||||
ipc::detail::waiter_impl cc_waiter_;
|
ipc::detail::waiter_wrapper cc_waiter_;
|
||||||
|
|
||||||
bool connected_ = false;
|
bool connected_ = false;
|
||||||
bool dismiss_ = true;
|
bool dismiss_ = true;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "platform/waiter.h"
|
#include "platform/waiter_wrapper.h"
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ class waiter::waiter_ : public pimpl<waiter_> {
|
|||||||
public:
|
public:
|
||||||
std::string n_;
|
std::string n_;
|
||||||
|
|
||||||
detail::waiter_impl w_ { new detail::waiter };
|
detail::waiter_wrapper w_ { new detail::waiter };
|
||||||
~waiter_() { delete w_.waiter(); }
|
~waiter_() { delete w_.waiter(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user