Blender V4.3
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#include "util/system.h"
8#include "util/windows.h"
9
10#include <system_error>
11
13
14thread::thread(function<void()> run_cb) : run_cb_(run_cb), joined_(false)
15{
16#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
17 /* Set the stack size to 2MB to match GLIBC. The default 512KB on macOS is
18 * too small for Embree, and consistent stack size also makes things more
19 * predictable in general. */
20 pthread_attr_t attribute;
21 pthread_attr_init(&attribute);
22 pthread_attr_setstacksize(&attribute, 1024 * 1024 * 2);
23 pthread_create(&pthread_id, &attribute, run, (void *)this);
24#else
25 std_thread = std::thread(&thread::run, this);
26#endif
27}
28
30{
31 if (!joined_) {
32 join();
33 }
34}
35
36void *thread::run(void *arg)
37{
38 thread *self = (thread *)(arg);
39 self->run_cb_();
40 return NULL;
41}
42
44{
45 joined_ = true;
46#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
47 return pthread_join(pthread_id, NULL) == 0;
48#else
49 try {
50 std_thread.join();
51 return true;
52 }
53 catch (const std::system_error &) {
54 return false;
55 }
56#endif
57}
58
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
PyObject * self
~thread()
Definition thread.cpp:29
static void * run(void *arg)
Definition thread.cpp:36
bool joined_
Definition thread.h:52
bool join()
Definition thread.cpp:43
function< void()> run_cb_
Definition thread.h:46
std::thread std_thread
Definition thread.h:50
thread(function< void()> run_cb)
Definition thread.cpp:14
#define CCL_NAMESPACE_END
#define NULL