Blender
V5.3
intern
cycles
util
thread.cpp
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "
util/thread.h
"
6
7
#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
8
#else
9
# include "
util/system.h
"
10
# ifdef _WIN32
11
# include "
util/windows.h
"
12
# endif
13
14
# include <system_error>
15
#endif
16
17
CCL_NAMESPACE_BEGIN
18
19
thread::thread
(std::function<
void
()> run_cb) :
run_cb_
(run_cb),
joined_
(false)
20
{
21
#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
22
/* Set the stack size to 2MB to match GLIBC. The default 512KB on macOS is
23
* too small for Embree, and consistent stack size also makes things more
24
* predictable in general. */
25
pthread_attr_t
attribute
;
26
pthread_attr_init(&
attribute
);
27
pthread_attr_setstacksize(&
attribute
, 1024 * 1024 * 2);
28
pthread_create(&pthread_id, &
attribute
,
run
, (
void
*)
this
);
29
#else
30
std_thread
= std::thread(&
thread::run
,
this
);
31
#endif
32
}
33
34
thread::~thread
()
35
{
36
if
(!
joined_
) {
37
join
();
38
}
39
}
40
41
void
*
thread::run
(
void
*arg)
42
{
43
thread
*self = (
thread
*)(arg);
44
self->
run_cb_
();
45
return
nullptr
;
46
}
47
48
bool
thread::join
()
49
{
50
joined_
=
true
;
51
#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
52
return
pthread_join(pthread_id,
nullptr
) == 0;
53
#else
54
try
{
55
std_thread
.join();
56
return
true
;
57
}
58
catch
(
const
std::system_error &) {
59
return
false
;
60
}
61
#endif
62
}
63
64
CCL_NAMESPACE_END
thread::~thread
~thread()
Definition
thread.cpp:34
thread::run_cb_
std::function< void()> run_cb_
Definition
thread.h:44
thread::run
static void * run(void *arg)
Definition
thread.cpp:41
thread::thread
thread(std::function< void()> run_cb)
Definition
thread.cpp:19
thread::joined_
bool joined_
Definition
thread.h:50
thread::join
bool join()
Definition
thread.cpp:48
thread::std_thread
std::thread std_thread
Definition
thread.h:48
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
attribute
#define attribute(slot)
Definition
gpu_shader_cxx_attribute.hh:56
CCL_NAMESPACE_BEGIN
Definition
python.cpp:41
system.h
thread.h
windows.h
Generated on
for Blender by
doxygen
1.18.0