From: Amos Jeffries Date: Mon, 21 Sep 2015 14:26:03 +0000 (-0700) Subject: Add assigment and move operators to LockingPointer X-Git-Tag: SQUID_4_0_1~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89deb18612969e240f7d00be83eb6ce5961ff322;p=thirdparty%2Fsquid.git Add assigment and move operators to LockingPointer These operators are required to use LockingPointer instances in STL containers and unlike TidyPointer the LockingPointer can do them safely due to the lock preventing premature deletions. --- diff --git a/src/security/LockingPointer.h b/src/security/LockingPointer.h index 02935432b7..49c1a297fd 100644 --- a/src/security/LockingPointer.h +++ b/src/security/LockingPointer.h @@ -1,3 +1,11 @@ +/* + * Copyright (C) 1996-2015 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + #ifndef SQUID_SRC_SECURITY_LOCKINGPOINTER_H #define SQUID_SRC_SECURITY_LOCKINGPOINTER_H @@ -7,15 +15,39 @@ namespace Security { /** - * Add SSL locking (a.k.a. reference counting) to TidyPointer - */ + * Add SSL locking (a.k.a. reference counting) and assignment to TidyPointer + */ template class LockingPointer: public TidyPointer { public: typedef TidyPointer Parent; + typedef LockingPointer SelfType; + + explicit LockingPointer(T *t = nullptr): Parent(t) {} + + explicit LockingPointer(const SelfType &o): Parent() { + resetAndLock(o.get()); + } + + SelfType &operator =(const SelfType & o) { + resetAndLock(o.get()); + return *this; + } - LockingPointer(T *t = nullptr): Parent(t) {} +#if __cplusplus >= 201103L + explicit LockingPointer(LockingPointer &&o): Parent(o.get()) { + *o.addr() = nullptr; + } + + LockingPointer &operator =(LockingPointer &&o) { + if (o.get() != this->get()) { + this->reset(o.get()); + *o.addr() = nullptr; + } + return *this; + } +#endif void resetAndLock(T *t) { if (t != this->get()) {