24 # include <sys/timeb.h>
26 #elif defined(__APPLE__)
27 # include <sys/sysctl.h>
28 # include <sys/types.h>
30 # include <sys/time.h>
35 # include <tbb/spin_mutex.h>
40 #if defined(__APPLE__) && defined(_OPENMP) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) && \
42 # define USE_APPLE_OMP_FIX
45 #ifdef USE_APPLE_OMP_FIX
47 extern pthread_key_t gomp_tls_key;
48 static void *thread_tls_data;
108 static pthread_mutex_t
_fftw_lock = PTHREAD_MUTEX_INITIALIZER;
115 #define RE_MAX_THREAD BLENDER_MAX_THREADS
119 void *(*do_thread)(
void *);
138 if (threadbase !=
nullptr && tot > 0) {
148 for (
a = 0;
a < tot;
a++) {
158 #ifdef USE_APPLE_OMP_FIX
162 thread_tls_data = pthread_getspecific(gomp_tls_key);
198 #ifdef USE_APPLE_OMP_FIX
201 pthread_setspecific(gomp_tls_key, thread_tls_data);
209 return pthread_equal(pthread_self(),
mainid);
222 printf(
"ERROR: could not insert thread slot\n");
229 pthread_join(tslot->pthread,
nullptr);
230 tslot->callerdata =
nullptr;
241 if (
counter == index && tslot->avail == 0) {
242 pthread_join(tslot->pthread,
nullptr);
243 tslot->callerdata =
nullptr;
254 if (tslot->avail == 0) {
255 pthread_join(tslot->pthread,
nullptr);
256 tslot->callerdata =
nullptr;
272 if (tslot->avail == 0) {
273 pthread_join(tslot->pthread,
nullptr);
295 GetSystemInfo(&info);
296 t = (int)info.dwNumberOfProcessors;
305 sysctl(mib, 2, &
t, &
len,
nullptr, 0);
307 t = (int)sysconf(_SC_NPROCESSORS_ONLN);
370 pthread_mutex_init(
mutex,
nullptr);
375 pthread_mutex_lock(
mutex);
380 pthread_mutex_unlock(
mutex);
385 return (pthread_mutex_trylock(
mutex) == 0);
390 pthread_mutex_destroy(
mutex);
409 static tbb::spin_mutex *tbb_spin_mutex_cast(
SpinLock *
spin)
411 static_assert(
sizeof(
SpinLock) >=
sizeof(tbb::spin_mutex),
412 "SpinLock must match tbb::spin_mutex");
413 static_assert(
alignof(
SpinLock) %
alignof(tbb::spin_mutex) == 0,
414 "SpinLock must be aligned same as tbb::spin_mutex");
415 return reinterpret_cast<tbb::spin_mutex *
>(
spin);
422 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(
spin);
423 new (spin_mutex) tbb::spin_mutex();
424 #elif defined(__APPLE__)
426 #elif defined(_MSC_VER)
429 pthread_spin_init(
spin, 0);
436 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(
spin);
438 #elif defined(__APPLE__)
440 #elif defined(_MSC_VER)
441 while (InterlockedExchangeAcquire(
spin, 1)) {
448 pthread_spin_lock(
spin);
455 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(
spin);
456 spin_mutex->unlock();
457 #elif defined(__APPLE__)
459 #elif defined(_MSC_VER)
463 pthread_spin_unlock(
spin);
470 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(
spin);
471 spin_mutex->~spin_mutex();
472 #elif defined(__APPLE__)
474 #elif defined(_MSC_VER)
477 pthread_spin_destroy(
spin);
485 pthread_rwlock_init(
mutex,
nullptr);
491 pthread_rwlock_rdlock(
mutex);
494 pthread_rwlock_wrlock(
mutex);
500 pthread_rwlock_unlock(
mutex);
505 pthread_rwlock_destroy(
mutex);
535 pthread_cond_init(&ticket->
cond,
nullptr);
536 pthread_mutex_init(&ticket->
mutex,
nullptr);
543 pthread_mutex_destroy(&ticket->
mutex);
544 pthread_cond_destroy(&ticket->
cond);
550 unsigned int queue_me;
552 pthread_mutex_lock(&ticket->
mutex);
556 pthread_cond_wait(&ticket->
cond, &ticket->
mutex);
559 pthread_mutex_unlock(&ticket->
mutex);
564 pthread_mutex_lock(&ticket->
mutex);
566 pthread_cond_broadcast(&ticket->
cond);
567 pthread_mutex_unlock(&ticket->
mutex);
576 pthread_cond_init(cond,
nullptr);
581 pthread_cond_wait(cond,
mutex);
591 pthread_cond_signal(cond);
596 pthread_cond_broadcast(cond);
601 pthread_cond_destroy(cond);
622 pthread_mutex_init(&
queue->mutex,
nullptr);
623 pthread_cond_init(&
queue->push_cond,
nullptr);
624 pthread_cond_init(&
queue->finish_cond,
nullptr);
632 pthread_cond_destroy(&
queue->finish_cond);
633 pthread_cond_destroy(&
queue->push_cond);
634 pthread_mutex_destroy(&
queue->mutex);
643 pthread_mutex_lock(&
queue->mutex);
648 pthread_cond_signal(&
queue->push_cond);
649 pthread_mutex_unlock(&
queue->mutex);
654 void *work =
nullptr;
657 pthread_mutex_lock(&
queue->mutex);
659 pthread_cond_wait(&
queue->push_cond, &
queue->mutex);
667 pthread_cond_broadcast(&
queue->finish_cond);
671 pthread_mutex_unlock(&
queue->mutex);
686 usec = now.millitm * 1000;
691 gettimeofday(&now,
nullptr);
698 div_result = ldiv(ms, 1000);
699 timeout->tv_sec = sec + div_result.quot;
701 x = usec + (div_result.rem * 1000);
708 timeout->tv_nsec =
x * 1000;
714 void *work =
nullptr;
715 struct timespec timeout;
721 pthread_mutex_lock(&
queue->mutex);
723 if (pthread_cond_timedwait(&
queue->push_cond, &
queue->mutex, &timeout) == ETIMEDOUT) {
736 pthread_cond_broadcast(&
queue->finish_cond);
740 pthread_mutex_unlock(&
queue->mutex);
749 pthread_mutex_lock(&
queue->mutex);
751 pthread_mutex_unlock(&
queue->mutex);
760 pthread_mutex_lock(&
queue->mutex);
762 pthread_mutex_unlock(&
queue->mutex);
769 pthread_mutex_lock(&
queue->mutex);
774 pthread_cond_broadcast(&
queue->push_cond);
775 pthread_mutex_unlock(&
queue->mutex);
781 pthread_mutex_lock(&
queue->mutex);
784 pthread_cond_wait(&
queue->finish_cond, &
queue->mutex);
787 pthread_mutex_unlock(&
queue->mutex);
#define BLI_assert_unreachable()
void BLI_gsqueue_free(GSQueue *queue)
GSQueue * BLI_gsqueue_new(size_t elem_size)
void BLI_gsqueue_push(GSQueue *queue, const void *item)
void BLI_gsqueue_pop(GSQueue *queue, void *r_item)
bool BLI_gsqueue_is_empty(const GSQueue *queue)
size_t BLI_gsqueue_len(const GSQueue *queue)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
pthread_spinlock_t SpinLock
pthread_rwlock_t ThreadRWMutex
pthread_cond_t ThreadCondition
pthread_mutex_t ThreadMutex
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
Platform independent time functions.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE unsigned int atomic_fetch_and_add_u(unsigned int *p, unsigned int x)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
ccl_gpu_kernel_postfix ccl_global int * counter
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
pthread_cond_t finish_cond
void *(* do_thread)(void *)
void BLI_condition_notify_all(ThreadCondition *cond)
bool BLI_mutex_trylock(ThreadMutex *mutex)
void BLI_rw_mutex_end(ThreadRWMutex *mutex)
void BLI_thread_queue_push(ThreadQueue *queue, void *work)
void BLI_threadapi_init()
void BLI_thread_unlock(int type)
void BLI_ticket_mutex_unlock(TicketMutex *ticket)
static pthread_mutex_t _image_lock
void BLI_mutex_end(ThreadMutex *mutex)
void BLI_threadapi_exit()
void BLI_mutex_free(ThreadMutex *mutex)
static pthread_mutex_t _custom1_lock
void BLI_threadpool_clear(ListBase *threadbase)
void BLI_threadpool_init(ListBase *threadbase, void *(*do_thread)(void *), int tot)
void BLI_thread_lock(int type)
void BLI_threadpool_remove(ListBase *threadbase, void *callerdata)
static pthread_mutex_t _view3d_lock
ThreadMutex * BLI_mutex_alloc()
void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *mutex)
static unsigned int thread_levels
int BLI_system_num_threads_override_get()
static int threads_override_num
int BLI_threadpool_available_thread_index(ListBase *threadbase)
void * BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms)
void BLI_mutex_init(ThreadMutex *mutex)
static pthread_mutex_t _viewer_lock
void BLI_system_num_threads_override_set(int num)
void BLI_condition_end(ThreadCondition *cond)
void BLI_thread_queue_free(ThreadQueue *queue)
static pthread_mutex_t _colormanage_lock
static pthread_mutex_t _fftw_lock
void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode)
void BLI_ticket_mutex_lock(TicketMutex *ticket)
static void * tslot_thread_start(void *tslot_p)
void BLI_condition_notify_one(ThreadCondition *cond)
bool BLI_thread_queue_is_empty(ThreadQueue *queue)
void BLI_ticket_mutex_free(TicketMutex *ticket)
void BLI_condition_wait_global_mutex(ThreadCondition *cond, const int type)
static pthread_mutex_t _image_draw_lock
void BLI_threadpool_end(ListBase *threadbase)
void BLI_condition_init(ThreadCondition *cond)
void BLI_mutex_lock(ThreadMutex *mutex)
void BLI_thread_queue_nowait(ThreadQueue *queue)
int BLI_system_thread_count()
void BLI_thread_queue_wait_finish(ThreadQueue *queue)
void BLI_mutex_unlock(ThreadMutex *mutex)
void BLI_rw_mutex_init(ThreadRWMutex *mutex)
ThreadQueue * BLI_thread_queue_init()
static pthread_mutex_t _nodes_lock
static void wait_timeout(struct timespec *timeout, int ms)
ThreadRWMutex * BLI_rw_mutex_alloc()
void BLI_threadpool_insert(ListBase *threadbase, void *callerdata)
static pthread_mutex_t _movieclip_lock
void BLI_spin_init(SpinLock *spin)
void BLI_spin_unlock(SpinLock *spin)
void BLI_threadpool_remove_index(ListBase *threadbase, int index)
int BLI_available_threads(ListBase *threadbase)
void * BLI_thread_queue_pop(ThreadQueue *queue)
void BLI_spin_lock(SpinLock *spin)
void BLI_rw_mutex_free(ThreadRWMutex *mutex)
TicketMutex * BLI_ticket_mutex_alloc()
void BLI_rw_mutex_unlock(ThreadRWMutex *mutex)
void BLI_spin_end(SpinLock *spin)
int BLI_thread_queue_len(ThreadQueue *queue)
static ThreadMutex * global_mutex_from_type(const int type)
double PIL_check_seconds_timer(void)