Browse Source

add call_with_lock(). Moved from Json Adapter.

sync
Roker 3 years ago
parent
commit
68a2f88903
2 changed files with 33 additions and 0 deletions
  1. +8
    -0
      call_with_lock.cc
  2. +25
    -0
      call_with_lock.hh

+ 8
- 0
call_with_lock.cc View File

@ -0,0 +1,8 @@
// this file is under GNU GPL 3.0, see LICENSE.txt
#include "call_with_lock.hh"
namespace pEp
{
std::mutex call_with_lock_mutex;
}

+ 25
- 0
call_with_lock.hh View File

@ -0,0 +1,25 @@
// this file is under GNU GPL 3.0, see LICENSE.txt
#ifndef PEP_CALL_WITH_LOCK_HH
#define PEP_CALL_WITH_LOCK_HH
#include <mutex>
namespace pEp
{
extern std::mutex call_with_lock_mutex;
// TODO: use && and std::forward<> to avoid copying of the arguments.
// It is not relevant, yet, because at the moment we use this function template only
// for init() and release() which have cheap-to-copy pointer parameters only
template<class R, class... Args>
R call_with_lock( R(*fn)(Args...), Args... args)
{
std::lock_guard<std::mutex> L(call_with_lock_mutex);
return fn(args...);
}
}
#endif // PEP_CALL_WITH_LOCK_HH

Loading…
Cancel
Save