]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add assigment and move operators to LockingPointer
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 21 Sep 2015 14:26:03 +0000 (07:26 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 21 Sep 2015 14:26:03 +0000 (07:26 -0700)
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.

src/security/LockingPointer.h

index 02935432b725a9ec6c974cfa75360195e85af375..49c1a297fde546e42909b7cfd68b5f4a67c82b26 100644 (file)
@@ -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 <typename T, void (*DeAllocator)(T *t), int lock>
 class LockingPointer: public TidyPointer<T, DeAllocator>
 {
 public:
     typedef TidyPointer<T, DeAllocator> Parent;
+    typedef LockingPointer<T, DeAllocator, lock> 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<T, DeAllocator, lock> &&o): Parent(o.get()) {
+        *o.addr() = nullptr;
+    }
+
+    LockingPointer<T, DeAllocator, lock> &operator =(LockingPointer<T, DeAllocator, lock> &&o) {
+        if (o.get() != this->get()) {
+            this->reset(o.get());
+            *o.addr() = nullptr;
+        }
+        return *this;
+    }
+#endif
 
     void resetAndLock(T *t) {
         if (t != this->get()) {