NO_COPY_CLASS c++11

This commit is contained in:
2020-07-17 11:46:21 +03:00
parent 1a3096c48b
commit 33a6382f4d
8 changed files with 24 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
/*! \file pimutex.h
* \brief Mutex
* \brief PIMutexLocker
*/
/*
PIP - Platform Independent Primitives
Mutex
PIMutexLocker
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
@@ -25,15 +25,19 @@
#include "piinit.h"
//! \brief PIMutexLocker
//! \details Same as std::lock_guard<std::mutex>.
//! When a PIMutexLocker object is created, it attempts to lock the mutex it is given, if "condition" true.
//! When control leaves the scope in which the PIMutexLocker object was created,
//! the PIMutexLocker is destructed and the mutex is released, if "condition" true.
//! If "condition" false this class do nothing.
//! The PIMutexLocker class is non-copyable.
class PIP_EXPORT PIMutexLocker
{
public:
NO_COPY_CLASS(PIMutexLocker)
PIMutexLocker(PIMutex & m, bool condition = true): mutex(m), cond(condition) {if (cond) mutex.lock();}
~PIMutexLocker() {if (cond) mutex.unlock();}
PIMutexLocker(const PIMutexLocker&) = delete;
PIMutexLocker& operator=(const PIMutexLocker&) = delete;
private:
PIMutex & mutex;
std::atomic_bool cond;

View File

@@ -71,7 +71,8 @@ class PIP_EXPORT PIThread: public PIObject
PIOBJECT_SUBCLASS(PIThread, PIObject)
friend class PIIntrospectionThreads;
public:
NO_COPY_CLASS(PIThread)
//! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".
PIThread(void * data, ThreadFunc func, bool startNow = false, int loop_delay = -1);
@@ -257,8 +258,6 @@ protected:
PRIVATE_DECLARATION
private:
NO_COPY_CLASS(PIThread)
bool _startThread(void * func);
void _beginThread();
void _runThread();

View File

@@ -78,7 +78,8 @@ protected:
class PIP_EXPORT PITimer: public PIObject {
PIOBJECT_SUBCLASS(PITimer, PIObject)
public:
NO_COPY_CLASS(PITimer)
//! \brief Constructs timer with PITimer::Thread implementation
explicit PITimer();
@@ -254,17 +255,13 @@ protected:
virtual void tick(void * data_, int delimiter) {}
void * data_t;
volatile bool lockRun, callEvents;
std::atomic_bool lockRun, callEvents;
PIMutex mutex_;
TimerEvent ret_func;
TimerImplementation imp_mode;
PIVector<Delimiter> delims;
mutable _PITimerBase * imp;
private:
NO_COPY_CLASS(PITimer)
};