call_with_lock.hh
author Volker Birk <vb@pep-project.org>
Thu, 14 Nov 2019 23:22:05 +0100
changeset 134 b6e70c7067b3
parent 108 52a3ec390f8b
permissions -rw-r--r--
merging
     1 // this file is under GNU GPL 3.0, see LICENSE.txt
     2 
     3 #ifndef PEP_CALL_WITH_LOCK_HH
     4 #define PEP_CALL_WITH_LOCK_HH
     5 
     6 #include <mutex>
     7 
     8 namespace pEp
     9 {
    10 	extern std::mutex call_with_lock_mutex;
    11 
    12 	// TODO: use && and std::forward<> to avoid copying of the arguments.
    13 	// It is not relevant, yet, because at the moment we use this function template only
    14 	// for init() and release() which have cheap-to-copy pointer parameters only
    15 	template<class R, class... Args>
    16 	R call_with_lock( R(*fn)(Args...), Args... args)
    17 	{
    18 		std::lock_guard<std::mutex> L(call_with_lock_mutex);
    19 		return fn(args...);
    20 	}
    21 
    22 
    23 }
    24 
    25 #endif // PEP_CALL_WITH_LOCK_HH