]> git.ipfire.org Git - thirdparty/squid.git/blame - src/security/LockingPointer.h
Crypto-NG: replace Ssl::X509_Pointer with Security::CertPointer
[thirdparty/squid.git] / src / security / LockingPointer.h
CommitLineData
f97700a0
AJ
1#ifndef SQUID_SRC_SECURITY_LOCKINGPOINTER_H
2#define SQUID_SRC_SECURITY_LOCKINGPOINTER_H
3
4#include "base/TidyPointer.h"
5
6namespace Security
7{
8
9/**
10 * Add SSL locking (a.k.a. reference counting) to TidyPointer
11 */
12template <typename T, void (*DeAllocator)(T *t), int lock>
13class LockingPointer: public TidyPointer<T, DeAllocator>
14{
15public:
16 typedef TidyPointer<T, DeAllocator> Parent;
17
18 LockingPointer(T *t = nullptr): Parent(t) {}
19
20 void resetAndLock(T *t) {
21 if (t != this->get()) {
22 this->reset(t);
23#if USE_OPENSSL
24 if (t)
25 CRYPTO_add(&t->references, 1, lock);
26#elif USE_GNUTLS
27 // XXX: GnuTLS does not provide locking ?
28#else
29 assert(false);
30#endif
31 }
32 }
33};
34
35} // namespace Security
36
37#endif /* SQUID_SRC_SECURITY_LOCKINGPOINTER_H */