Blender  V3.3
thread.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "util/thread.h"
5 
6 #include "util/system.h"
7 #include "util/windows.h"
8 
9 #include <system_error>
10 
12 
13 thread::thread(function<void()> run_cb) : run_cb_(run_cb), joined_(false)
14 {
15 #ifdef __APPLE__
16  /* Set the stack size to 2MB to match Linux. The default 512KB on macOS is
17  * too small for Embree, and consistent stack size also makes things more
18  * predictable in general. */
19  pthread_attr_t attribute;
20  pthread_attr_init(&attribute);
21  pthread_attr_setstacksize(&attribute, 1024 * 1024 * 2);
22  pthread_create(&pthread_id, &attribute, run, (void *)this);
23 #else
24  std_thread = std::thread(&thread::run, this);
25 #endif
26 }
27 
29 {
30  if (!joined_) {
31  join();
32  }
33 }
34 
35 void *thread::run(void *arg)
36 {
37  thread *self = (thread *)(arg);
38  self->run_cb_();
39  return NULL;
40 }
41 
43 {
44  joined_ = true;
45 #ifdef __APPLE__
46  return pthread_join(pthread_id, NULL) == 0;
47 #else
48  try {
49  std_thread.join();
50  return true;
51  }
52  catch (const std::system_error &) {
53  return false;
54  }
55 #endif
56 }
57 
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 Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise 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
Definition: thread.h:34
~thread()
Definition: thread.cpp:28
static void * run(void *arg)
Definition: thread.cpp:35
bool joined_
Definition: thread.h:49
bool join()
Definition: thread.cpp:42
function< void()> run_cb_
Definition: thread.h:43
std::thread std_thread
Definition: thread.h:47
thread(function< void()> run_cb)
Definition: thread.cpp:13
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9