Last active
August 9, 2021 15:58
-
-
Save picanumber/f95d5662c4dda9d1f992415518498fe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class U> class CallProxy | |
{ | |
U *_p; | |
std::recursive_mutex &_mtx; | |
mutable bool _own; | |
public: | |
CallProxy(U *pp, std::mutex &mtx) : _p(pp), _mtx(mtx), _own(true) | |
{ | |
} | |
CallProxy(CallProxy const &other) | |
: _p(other._p), _mtx(other._mtx), _own(true) | |
{ | |
other._own = false; | |
} | |
~CallProxy() | |
{ | |
if (_own) | |
{ | |
_mtx.unlock(); | |
} | |
} | |
CallProxy &operator=(CallProxy const &) = delete; | |
U *operator->() | |
{ | |
return _p; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment