remove picout
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
#ifndef PIPROTECTEDVARIABLE_H
|
#ifndef PIPROTECTEDVARIABLE_H
|
||||||
#define PIPROTECTEDVARIABLE_H
|
#define PIPROTECTEDVARIABLE_H
|
||||||
|
|
||||||
#include "picout.h"
|
|
||||||
#include "pimutex.h"
|
#include "pimutex.h"
|
||||||
|
|
||||||
//! \~\ingroup Thread
|
//! \~\ingroup Thread
|
||||||
@@ -35,6 +34,8 @@
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class PIP_EXPORT PIProtectedVariable {
|
class PIP_EXPORT PIProtectedVariable {
|
||||||
public:
|
public:
|
||||||
|
//! \~english Constructs %PIProtectedVariable and initialize variable by value `v`.
|
||||||
|
//! \~russian Создает %PIProtectedVariable и инициализирует переменную значением `v`.
|
||||||
PIProtectedVariable(T v = T()): var(std::move(v)) {}
|
PIProtectedVariable(T v = T()): var(std::move(v)) {}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
@@ -43,26 +44,18 @@ public:
|
|||||||
class PIP_EXPORT Pointer {
|
class PIP_EXPORT Pointer {
|
||||||
friend class PIProtectedVariable<T>;
|
friend class PIProtectedVariable<T>;
|
||||||
NO_COPY_CLASS(Pointer);
|
NO_COPY_CLASS(Pointer);
|
||||||
|
Pointer & operator=(Pointer && other) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \~\english Move constructor - transfers ownership of the lock.
|
//! \~english Move constructor - transfers ownership of the lock.
|
||||||
//! \~russian Конструктор перемещения - передает владение блокировкой.
|
//! \~russian Конструктор перемещения - передает владение блокировкой.
|
||||||
Pointer(Pointer && other): pv(other.pv) { other.can_unlock = false; };
|
Pointer(Pointer && other): pv(other.pv) { other.can_unlock = false; };
|
||||||
|
|
||||||
|
//! \~english Destroys wrapper and releases the mutex.
|
||||||
//! \~\english Move assignment - transfers ownership of the lock.
|
|
||||||
//! \~russian Оператор перемещения - передает владение блокировкой.
|
|
||||||
Pointer & operator=(Pointer && other) {
|
|
||||||
pv = other.pv;
|
|
||||||
other.can_unlock = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! \~\english Destroys wrapper and releases the mutex.
|
|
||||||
//! \~russian Уничтожает обертку и освобождает мьютекс.
|
//! \~russian Уничтожает обертку и освобождает мьютекс.
|
||||||
~Pointer() {
|
~Pointer() {
|
||||||
if (can_unlock) {
|
if (can_unlock) {
|
||||||
pv.mutex.unlock();
|
pv.mutex.unlock();
|
||||||
piCout << "mutex.unlock()" << &(pv.mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +69,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Pointer() = delete;
|
explicit Pointer() = delete;
|
||||||
explicit Pointer(PIProtectedVariable<T> & v): pv(v) {
|
explicit Pointer(PIProtectedVariable<T> & v): pv(v) { pv.mutex.lock(); }
|
||||||
pv.mutex.lock();
|
|
||||||
piCout << "mutex.lock()" << &(pv.mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
PIProtectedVariable<T> & pv;
|
PIProtectedVariable<T> & pv;
|
||||||
bool can_unlock = true;
|
bool can_unlock = true;
|
||||||
|
|||||||
4
main.cpp
4
main.cpp
@@ -23,9 +23,9 @@ int main(int argc, char * argv[]) {
|
|||||||
PIProtectedVariable<double> pv(3.0);
|
PIProtectedVariable<double> pv(3.0);
|
||||||
piCout << pv.get();
|
piCout << pv.get();
|
||||||
{
|
{
|
||||||
auto ref = pv.getRef();
|
auto ref = pv.getRef();
|
||||||
piCout << *ref;
|
piCout << *ref;
|
||||||
*ref = 11.;
|
*ref = 11.;
|
||||||
piCout << *ref;
|
piCout << *ref;
|
||||||
}
|
}
|
||||||
piCout << pv.get();
|
piCout << pv.get();
|
||||||
|
|||||||
Reference in New Issue
Block a user