Loading...
Searching...
No Matches
detachedTask.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_WORK_DETACHED_TASK_H
8#define PXR_BASE_WORK_DETACHED_TASK_H
9
11
12#include "pxr/pxr.h"
14#include "pxr/base/work/api.h"
16#include "pxr/base/work/impl.h"
17
18#include <type_traits>
19#include <utility>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23template <class Fn>
24struct Work_DetachedTask
25{
26 explicit Work_DetachedTask(Fn &&fn) : _fn(std::move(fn)) {}
27 explicit Work_DetachedTask(Fn const &fn) : _fn(fn) {}
28 void operator()() const {
30 _fn();
31 m.Clear();
32 }
33private:
34 Fn _fn;
35};
36
39template <class Fn>
41{
42 using FnType = typename std::remove_reference<Fn>::type;
43 Work_DetachedTask<FnType> task(std::forward<Fn>(fn));
44 if (WorkHasConcurrency()) {
45 PXR_WORK_IMPL_NAMESPACE_USING_DIRECTIVE;
46 WorkImpl_RunDetachedTask<Work_DetachedTask<FnType>>(std::move(task));
47 }
48 else {
49 task();
50 }
51}
52
53PXR_NAMESPACE_CLOSE_SCOPE
54
55#endif // PXR_BASE_WORK_DETACHED_TASK_H
Class used to record the end of the error-list.
Definition: errorMark.h:48
bool Clear() const
Remove all errors in this mark from the error system.
Definition: errorMark.h:92
void WorkRunDetachedTask(Fn &&fn)
Invoke fn asynchronously, discard any errors it produces, and provide no way to wait for it to comple...
Definition: detachedTask.h:40
STL namespace.
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...