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
17#include <type_traits>
18#include <utility>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22template <class Fn>
23struct Work_DetachedTask
24{
25 explicit Work_DetachedTask(Fn &&fn) : _fn(std::move(fn)) {}
26 explicit Work_DetachedTask(Fn const &fn) : _fn(fn) {}
27 void operator()() const {
29 _fn();
30 m.Clear();
31 }
32private:
33 Fn _fn;
34};
35
36WORK_API
37WorkDispatcher &Work_GetDetachedDispatcher();
38
39WORK_API
40void Work_EnsureDetachedTaskProgress();
41
44template <class Fn>
46{
47 using FnType = typename std::remove_reference<Fn>::type;
48 Work_DetachedTask<FnType> task(std::forward<Fn>(fn));
49 if (WorkHasConcurrency()) {
50 Work_GetDetachedDispatcher().Run(std::move(task));
51 Work_EnsureDetachedTaskProgress();
52 }
53 else {
54 task();
55 }
56}
57
58PXR_NAMESPACE_CLOSE_SCOPE
59
60#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
A work dispatcher runs concurrent tasks.
Definition: dispatcher.h:66
void Run(Callable &&c, A1 &&a1, A2 &&a2,... AN &&aN)
Add work for the dispatcher to run.
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:45
STL namespace.
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...