24 #ifndef PXR_BASE_WORK_SINGULAR_TASK_H
25 #define PXR_BASE_WORK_SINGULAR_TASK_H
33 #include <type_traits>
73 template <
class Callable,
class A1,
class A2, ...
class AN>
75 Callable &&
c, A1 &&a1, A2 &&a2, ... AN &&aN);
79 template <
class Callable,
class... Args>
81 : _waker(_MakeWaker(d, std::bind(std::forward<Callable>(
c),
82 std::forward<Args>(
args)...)))
96 template <
class Dispatcher,
class Fn>
98 explicit _Waker(Dispatcher &d, Fn &&fn)
99 : _dispatcher(d), _fn(std::move(fn)) {}
101 void operator()(std::atomic_size_t &
count)
const {
111 std::size_t old =
count;
112 do { _fn(); }
while (
113 !count.compare_exchange_strong(old, 0));
116 Dispatcher &_dispatcher;
120 template <
class Dispatcher,
class Fn>
121 static std::function<void (std::atomic_size_t &)>
122 _MakeWaker(Dispatcher &d, Fn &&fn) {
123 return std::function<void (std::atomic_size_t &)>(
125 d, std::forward<Fn>(fn)));
128 std::function<void (std::atomic_size_t &)> _waker;
129 std::atomic_size_t _count;
134 #endif // PXR_BASE_WORK_SINGULAR_TASK_H
WorkSingularTask(WorkDispatcher &d, Callable &&c, Args &&...args)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
WorkSingularTask & operator=(WorkSingularTask const &)=delete
WorkSingularTask(WorkSingularTask const &)=delete