HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
utils.h
Go to the documentation of this file.
1
//
2
// Copyright 2016 Pixar
3
//
4
// Licensed under the Apache License, Version 2.0 (the "Apache License")
5
// with the following modification; you may not use this file except in
6
// compliance with the Apache License and the following modification to it:
7
// Section 6. Trademarks. is deleted and replaced with:
8
//
9
// 6. Trademarks. This License does not grant permission to use the trade
10
// names, trademarks, service marks, or product names of the Licensor
11
// and its affiliates, except as required to comply with Section 4(c) of
12
// the License and to reproduce the content of the NOTICE file.
13
//
14
// You may obtain a copy of the Apache License at
15
//
16
// http://www.apache.org/licenses/LICENSE-2.0
17
//
18
// Unless required by applicable law or agreed to in writing, software
19
// distributed under the Apache License with the above modification is
20
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
// KIND, either express or implied. See the Apache License for the specific
22
// language governing permissions and limitations under the Apache License.
23
//
24
#ifndef PXR_BASE_WORK_UTILS_H
25
#define PXR_BASE_WORK_UTILS_H
26
27
///\file work/utils.h
28
29
#include "
pxr/pxr.h
"
30
#include "
pxr/base/work/api.h
"
31
#include "
pxr/base/work/detachedTask.h
"
32
33
#include <utility>
34
35
PXR_NAMESPACE_OPEN_SCOPE
36
37
WORK_API
38
bool
Work_ShouldSynchronizeAsyncDestroyCalls
();
39
40
template
<
class
T>
41
struct
Work_AsyncMoveDestroyHelper
{
42
void
operator()
()
const
{
/* do nothing */
}
43
T
obj
;
44
};
45
46
// Helper for swap-based asynchronous destruction that synthesizes move
47
// construction and assignment using swap.
48
template
<
class
T>
49
struct
Work_AsyncSwapDestroyHelper
{
50
Work_AsyncSwapDestroyHelper
() =
default
;
51
52
Work_AsyncSwapDestroyHelper
(
Work_AsyncSwapDestroyHelper
const
&) =
delete
;
53
Work_AsyncSwapDestroyHelper
&
operator=
(
54
Work_AsyncSwapDestroyHelper
const
&) =
delete
;
55
56
Work_AsyncSwapDestroyHelper
(
Work_AsyncSwapDestroyHelper
&&other)
57
:
obj
()
58
{
59
using
std::swap
;
60
swap
(
obj
, other.obj);
61
}
62
63
Work_AsyncSwapDestroyHelper
&
operator=
(
64
Work_AsyncSwapDestroyHelper
&&other)
65
{
66
using
std::swap
;
67
swap
(
obj
, other.obj);
68
return
*
this
;
69
}
70
71
void
operator()
()
const
{
/* do nothing */
}
72
T
obj
;
73
};
74
75
/// Swap \p obj with a default-constructed T instance, return and arrange
76
/// for the swapped-out instance to be destroyed asynchronously. This means
77
/// that any code that obj's destructor might invoke must be safe to run both
78
/// concurrently with other code and at any point in the future. This might not
79
/// be true, for example, if obj's destructor might try to update some other
80
/// data structure that could be destroyed by the time obj's destruction occurs.
81
/// Be careful.
82
template
<
class
T>
83
void
WorkSwapDestroyAsync
(T &obj)
84
{
85
using
std::swap
;
86
Work_AsyncSwapDestroyHelper<T>
helper;
87
swap
(helper.
obj
, obj);
88
if
(!
Work_ShouldSynchronizeAsyncDestroyCalls
())
89
WorkRunDetachedTask
(std::move(helper));
90
}
91
92
/// Like WorkSwapDestroyAsync() but instead, move from \p obj, leaving it
93
/// in a moved-from state instead of a default constructed state.
94
template
<
class
T>
95
void
WorkMoveDestroyAsync
(T &obj)
96
{
97
Work_AsyncMoveDestroyHelper<T>
helper { std::move(obj) };
98
if
(!
Work_ShouldSynchronizeAsyncDestroyCalls
())
99
WorkRunDetachedTask
(std::move(helper));
100
}
101
102
PXR_NAMESPACE_CLOSE_SCOPE
103
104
#endif // PXR_BASE_WORK_UTILS_H
ArAssetInfo::swap
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition:
assetInfo.h:74
Work_AsyncSwapDestroyHelper::operator=
Work_AsyncSwapDestroyHelper & operator=(Work_AsyncSwapDestroyHelper const &)=delete
Work_AsyncSwapDestroyHelper::operator()
void operator()() const
Definition:
utils.h:71
Work_AsyncMoveDestroyHelper
Definition:
utils.h:41
std::swap
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition:
UT_ArraySet.h:1639
Work_AsyncMoveDestroyHelper::operator()
void operator()() const
Definition:
utils.h:42
Work_AsyncSwapDestroyHelper
Definition:
utils.h:49
swap
void swap(T &lhs, T &rhs)
Definition:
pugixml.cpp:7172
WORK_API
#define WORK_API
Definition:
api.h:40
Work_AsyncSwapDestroyHelper::operator=
Work_AsyncSwapDestroyHelper & operator=(Work_AsyncSwapDestroyHelper &&other)
Definition:
utils.h:63
Work_ShouldSynchronizeAsyncDestroyCalls
PXR_NAMESPACE_OPEN_SCOPE WORK_API bool Work_ShouldSynchronizeAsyncDestroyCalls()
WorkRunDetachedTask
void WorkRunDetachedTask(Fn &&fn)
Definition:
detachedTask.h:62
api.h
pxr.h
Work_AsyncSwapDestroyHelper::Work_AsyncSwapDestroyHelper
Work_AsyncSwapDestroyHelper(Work_AsyncSwapDestroyHelper &&other)
Definition:
utils.h:56
Work_AsyncSwapDestroyHelper::obj
T obj
Definition:
utils.h:72
OBJ_MatchTransform::T
detachedTask.h
Work_AsyncSwapDestroyHelper::Work_AsyncSwapDestroyHelper
Work_AsyncSwapDestroyHelper()=default
PXR_NAMESPACE_OPEN_SCOPE
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition:
path.h:1432
PXR_NAMESPACE_CLOSE_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition:
pxr.h:91
WorkSwapDestroyAsync
void WorkSwapDestroyAsync(T &obj)
Definition:
utils.h:83
WorkMoveDestroyAsync
void WorkMoveDestroyAsync(T &obj)
Definition:
utils.h:95
Work_AsyncMoveDestroyHelper::obj
T obj
Definition:
utils.h:43
pxr
base
work
utils.h
Generated on Thu Nov 14 2024 02:54:41 for HDK by
1.8.6