1#ifndef FREE_TENSOR_SYNC_FUNC_H
2#define FREE_TENSOR_SYNC_FUNC_H
16template <
typename R,
typename... Params>
class SyncFunc;
21template <
typename R,
typename... Params>
class SyncFunc<R(Params...)> {
22 std::function<R(Params...)> f_;
23 bool synchronized_ =
true;
31 explicit SyncFunc(
const std::function<R(Params...)> &f,
bool sync)
32 : f_(f), synchronized_(sync) {}
33 explicit SyncFunc(std::function<R(Params...)> &&f,
bool sync)
34 : f_(
std::move(f)), synchronized_(sync) {}
48 : f_(other.f_), synchronized_(other.synchronized_), mutex_() {}
51 synchronized_ = other.synchronized_;
56 return self.f_ ==
nullptr;
59 return self.f_ ==
nullptr;
62 template <
typename... Args> R
operator()(Args &&...args)
const {
64 std::lock_guard lg(mutex_);
65 return f_(std::forward<Args>(args)...);
67 return f_(std::forward<Args>(args)...);
77 return {std::forward<T>(f)};
85 return {std::forward<T>(f)};
SyncFunc(detail::TaggedSyncFunc< T > &&f)
Definition: sync_func.h:39
SyncFunc & operator=(const SyncFunc &other)
Definition: sync_func.h:49
SyncFunc(const std::function< R(Params...)> &f, bool sync)
Definition: sync_func.h:31
friend bool operator==(std::nullptr_t, const SyncFunc &self)
Definition: sync_func.h:58
SyncFunc(const detail::TaggedUnsyncFunc< T > &f)
Definition: sync_func.h:42
SyncFunc()
Definition: sync_func.h:28
SyncFunc(std::function< R(Params...)> &&f, bool sync)
Definition: sync_func.h:33
friend bool operator==(const SyncFunc &self, std::nullptr_t)
Definition: sync_func.h:55
SyncFunc(std::nullptr_t)
Definition: sync_func.h:29
SyncFunc(const detail::TaggedSyncFunc< T > &f)
Definition: sync_func.h:37
SyncFunc(detail::TaggedUnsyncFunc< T > &&f)
Definition: sync_func.h:44
SyncFunc(const SyncFunc &other)
Definition: sync_func.h:47
R operator()(Args &&...args) const
Definition: sync_func.h:62
Definition: sync_func.h:16
Definition: allocator.h:9
detail::TaggedSyncFunc< std::remove_reference_t< T > > syncFunc(T &&f)
Definition: sync_func.h:76
detail::TaggedUnsyncFunc< std::remove_reference_t< T > > unsyncFunc(T &&f)
Definition: sync_func.h:84
Definition: sync_func.h:11
T f_
Definition: sync_func.h:11
Definition: sync_func.h:12
T f_
Definition: sync_func.h:12