Blender V5.3
threads.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cerrno>
11#include <cstdio> /* For `printf`. */
12#include <cstdlib>
13#include <deque>
14
15#include "MEM_guardedalloc.h"
16
17#include "BLI_listbase.hh"
18#include "BLI_simd.hh"
19#include "BLI_threads.hh"
20#include "BLI_time.hh"
21#include "BLI_utildefines.hh"
22
23/* for checking system threads - BLI_system_thread_count */
24#ifdef WIN32
25# include <sys/timeb.h>
26# include <windows.h>
27#elif defined(__APPLE__)
28# include <sys/sysctl.h>
29# include <sys/types.h>
30#else
31# include <sys/time.h>
32# include <unistd.h>
33#endif
34
35#ifdef WITH_TBB
36# include <tbb/spin_mutex.h>
37#endif
38
39#include "atomic_ops.h"
40
41namespace blender {
42
93static pthread_mutex_t _image_lock = PTHREAD_MUTEX_INITIALIZER;
94static pthread_mutex_t _image_draw_lock = PTHREAD_MUTEX_INITIALIZER;
95static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER;
96static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
97static pthread_mutex_t _nodes_lock = PTHREAD_MUTEX_INITIALIZER;
98static pthread_mutex_t _movieclip_lock = PTHREAD_MUTEX_INITIALIZER;
99static pthread_mutex_t _fftw_lock = PTHREAD_MUTEX_INITIALIZER;
100static pthread_mutex_t _view3d_lock = PTHREAD_MUTEX_INITIALIZER;
101static pthread_t mainid;
102static uint thread_levels = 0; /* threads can be invoked inside threads */
103static int threads_override_num = 0;
104
105/* just a max for security reasons */
106#define RE_MAX_THREAD BLENDER_MAX_THREADS
107
110 void *(*do_thread)(void *);
112 pthread_t pthread;
113 int avail;
114};
115
117{
118 mainid = pthread_self();
119}
120
122
123void BLI_threadpool_init(ListBaseT<ThreadSlot> *threadbase, void *(*do_thread)(void *), int tot)
124{
125 int a;
126
127 if (threadbase != nullptr && tot > 0) {
128 threadbase->clear_no_delete();
129
130 if (tot > RE_MAX_THREAD) {
131 tot = RE_MAX_THREAD;
132 }
133 else if (tot < 1) {
134 tot = 1;
135 }
136
137 for (a = 0; a < tot; a++) {
138 ThreadSlot *tslot = MEM_new_zeroed<ThreadSlot>("threadslot");
139 BLI_addtail(threadbase, tslot);
140 tslot->do_thread = do_thread;
141 tslot->avail = 1;
142 }
143 }
144
146}
147
148int BLI_available_threads(ListBaseT<ThreadSlot> *threadbase)
149{
150 int counter = 0;
151
152 for (ThreadSlot &tslot : *threadbase) {
153 if (tslot.avail) {
154 counter++;
155 }
156 }
157
158 return counter;
159}
160
161int BLI_threadpool_available_thread_index(ListBaseT<ThreadSlot> *threadbase)
162{
163 int counter = 0;
164
165 for (ThreadSlot &tslot : *threadbase) {
166 if (tslot.avail) {
167 return counter;
168 }
169 ++counter;
170 }
171
172 return 0;
173}
174
175static void *tslot_thread_start(void *tslot_p)
176{
177 /* Match the denormal handling of the task scheduler threads, see #BLI_task_scheduler_init. */
179
180 ThreadSlot *tslot = static_cast<ThreadSlot *>(tslot_p);
181 return tslot->do_thread(tslot->callerdata);
182}
183
185{
186 return pthread_equal(pthread_self(), mainid);
187}
188
189void BLI_threadpool_insert(ListBaseT<ThreadSlot> *threadbase, void *callerdata)
190{
191 for (ThreadSlot &tslot : *threadbase) {
192 if (tslot.avail) {
193 tslot.avail = 0;
194 tslot.callerdata = callerdata;
195 pthread_create(&tslot.pthread, nullptr, tslot_thread_start, &tslot);
196 return;
197 }
198 }
199 printf("ERROR: could not insert thread slot\n");
200}
201
202void BLI_threadpool_remove(ListBaseT<ThreadSlot> *threadbase, void *callerdata)
203{
204 for (ThreadSlot &tslot : *threadbase) {
205 if (tslot.callerdata == callerdata) {
206 pthread_join(tslot.pthread, nullptr);
207 tslot.callerdata = nullptr;
208 tslot.avail = 1;
209 }
210 }
211}
212
213void BLI_threadpool_remove_index(ListBaseT<ThreadSlot> *threadbase, int index)
214{
215 int counter = 0;
216
217 for (ThreadSlot &tslot : *threadbase) {
218 if (counter == index && tslot.avail == 0) {
219 pthread_join(tslot.pthread, nullptr);
220 tslot.callerdata = nullptr;
221 tslot.avail = 1;
222 break;
223 }
224 ++counter;
225 }
226}
227
228void BLI_threadpool_clear(ListBaseT<ThreadSlot> *threadbase)
229{
230 for (ThreadSlot &tslot : *threadbase) {
231 if (tslot.avail == 0) {
232 pthread_join(tslot.pthread, nullptr);
233 tslot.callerdata = nullptr;
234 tslot.avail = 1;
235 }
236 }
237}
238
239void BLI_threadpool_end(ListBaseT<ThreadSlot> *threadbase)
240{
241
242 /* Only needed if there's actually some stuff to end
243 * this way we don't end up decrementing thread_levels on an empty `threadbase`. */
244 if (threadbase == nullptr || threadbase->is_empty()) {
245 return;
246 }
247
248 for (ThreadSlot &tslot : *threadbase) {
249 if (tslot.avail == 0) {
250 pthread_join(tslot.pthread, nullptr);
251 }
252 }
253 threadbase->free_no_destruct();
254}
255
256/* System Information */
257
259{
260 static int t = -1;
261
262 if (threads_override_num != 0) {
264 }
265 if (t != -1) [[likely]] {
266 return t;
267 }
268
269 {
270#ifdef WIN32
271 SYSTEM_INFO info;
272 GetSystemInfo(&info);
273 t = int(info.dwNumberOfProcessors);
274#else
275# ifdef __APPLE__
276 int mib[2];
277 size_t len;
278
279 mib[0] = CTL_HW;
280 mib[1] = HW_NCPU;
281 len = sizeof(t);
282 sysctl(mib, 2, &t, &len, nullptr, 0);
283# else
284 t = int(sysconf(_SC_NPROCESSORS_ONLN));
285# endif
286#endif
287 }
288
289 CLAMP(t, 1, RE_MAX_THREAD);
290
291 return t;
292}
293
298
303
304/* Global Mutex Locks */
305
306static ThreadMutex *global_mutex_from_type(const int type)
307{
308 switch (type) {
309 case LOCK_IMAGE:
310 return &_image_lock;
311 case LOCK_DRAW_IMAGE:
312 return &_image_draw_lock;
313 case LOCK_VIEWER:
314 return &_viewer_lock;
315 case LOCK_CUSTOM1:
316 return &_custom1_lock;
317 case LOCK_NODES:
318 return &_nodes_lock;
319 case LOCK_MOVIECLIP:
320 return &_movieclip_lock;
321 case LOCK_FFTW:
322 return &_fftw_lock;
323 case LOCK_VIEW3D:
324 return &_view3d_lock;
325 default:
327 return nullptr;
328 }
329}
330
331void BLI_thread_lock(int type)
332{
333 pthread_mutex_lock(global_mutex_from_type(type));
334}
335
336void BLI_thread_unlock(int type)
337{
338 pthread_mutex_unlock(global_mutex_from_type(type));
339}
340
341/* Mutex Locks */
342
344{
345 pthread_mutex_init(mutex, nullptr);
346}
347
349{
350 pthread_mutex_lock(mutex);
351}
352
354{
355 pthread_mutex_unlock(mutex);
356}
357
359{
360 return (pthread_mutex_trylock(mutex) == 0);
361}
362
364{
365 pthread_mutex_destroy(mutex);
366}
367
369{
370 ThreadMutex *mutex = MEM_new_zeroed<ThreadMutex>("ThreadMutex");
371 BLI_mutex_init(mutex);
372 return mutex;
373}
374
376{
377 BLI_mutex_end(mutex);
378 MEM_delete(mutex);
379}
380
381/* Spin Locks */
382
383#ifdef WITH_TBB
384static tbb::spin_mutex *tbb_spin_mutex_cast(SpinLock *spin)
385{
386 static_assert(sizeof(SpinLock) >= sizeof(tbb::spin_mutex),
387 "SpinLock must match tbb::spin_mutex");
388 static_assert(alignof(SpinLock) % alignof(tbb::spin_mutex) == 0,
389 "SpinLock must be aligned same as tbb::spin_mutex");
390 return reinterpret_cast<tbb::spin_mutex *>(spin);
391}
392#endif
393
395{
396#ifdef WITH_TBB
397 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(spin);
398 new (spin_mutex) tbb::spin_mutex();
399#elif defined(__APPLE__)
400 BLI_mutex_init(spin);
401#elif defined(_MSC_VER)
402 *spin = 0;
403#else
404 pthread_spin_init(spin, 0);
405#endif
406}
407
409{
410#ifdef WITH_TBB
411 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(spin);
412 spin_mutex->lock();
413#elif defined(__APPLE__)
414 BLI_mutex_lock(spin);
415#elif defined(_MSC_VER)
416# if defined(_M_ARM64)
417 // InterlockedExchangeAcquire takes a long arg on MSVC ARM64
418 static_assert(sizeof(long) == sizeof(SpinLock));
419 while (InterlockedExchangeAcquire((volatile long *)spin, 1)) {
420# else
421 while (InterlockedExchangeAcquire(spin, 1)) {
422# endif
423 while (*spin) {
424 /* Spin-lock hint for processors with hyper-threading. */
425 YieldProcessor();
426 }
427 }
428#else
429 pthread_spin_lock(spin);
430#endif
431}
432
434{
435#ifdef WITH_TBB
436 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(spin);
437 spin_mutex->unlock();
438#elif defined(__APPLE__)
439 BLI_mutex_unlock(spin);
440#elif defined(_MSC_VER)
441 _ReadWriteBarrier();
442 *spin = 0;
443#else
444 pthread_spin_unlock(spin);
445#endif
446}
447
449{
450#ifdef WITH_TBB
451 tbb::spin_mutex *spin_mutex = tbb_spin_mutex_cast(spin);
452 spin_mutex->~spin_mutex();
453#elif defined(__APPLE__)
454 BLI_mutex_end(spin);
455#elif defined(_MSC_VER)
456 /* Nothing to do, spin is a simple integer type. */
457 UNUSED_VARS(spin);
458#else
459 pthread_spin_destroy(spin);
460#endif
461}
462
463/* Read/Write Mutex Lock */
464
466{
467 pthread_rwlock_init(mutex, nullptr);
468}
469
470void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode)
471{
472 if (mode == THREAD_LOCK_READ) {
473 pthread_rwlock_rdlock(mutex);
474 }
475 else {
476 pthread_rwlock_wrlock(mutex);
477 }
478}
479
481{
482 pthread_rwlock_unlock(mutex);
483}
484
486{
487 pthread_rwlock_destroy(mutex);
488}
489
491{
492 ThreadRWMutex *mutex = MEM_new_zeroed<ThreadRWMutex>("ThreadRWMutex");
493 BLI_rw_mutex_init(mutex);
494 return mutex;
495}
496
498{
499 BLI_rw_mutex_end(mutex);
500 MEM_delete(mutex);
501}
502
503/* Ticket Mutex Lock */
504
506 pthread_cond_t cond;
507 pthread_mutex_t mutex;
509 pthread_t owner;
511};
512
514{
515 TicketMutex *ticket = MEM_new_zeroed<TicketMutex>("TicketMutex");
516
517 pthread_cond_init(&ticket->cond, nullptr);
518 pthread_mutex_init(&ticket->mutex, nullptr);
519
520 return ticket;
521}
522
524{
525 pthread_mutex_destroy(&ticket->mutex);
526 pthread_cond_destroy(&ticket->cond);
527 MEM_delete(ticket);
528}
529
530static bool ticket_mutex_lock(TicketMutex *ticket, const bool check_recursive)
531{
532 uint queue_me;
533
534 pthread_mutex_lock(&ticket->mutex);
535
536 /* Check for recursive locks, for debugging only. */
537 if (check_recursive && ticket->has_owner && pthread_equal(pthread_self(), ticket->owner)) {
538 pthread_mutex_unlock(&ticket->mutex);
539 return false;
540 }
541
542 queue_me = ticket->queue_tail++;
543
544 while (queue_me != ticket->queue_head) {
545 pthread_cond_wait(&ticket->cond, &ticket->mutex);
546 }
547
548 ticket->owner = pthread_self();
549 ticket->has_owner = true;
550
551 pthread_mutex_unlock(&ticket->mutex);
552 return true;
553}
554
556{
557 ticket_mutex_lock(ticket, false);
558}
559
561{
562 return ticket_mutex_lock(ticket, true);
563}
564
566{
567 pthread_mutex_lock(&ticket->mutex);
568 ticket->queue_head++;
569 ticket->has_owner = false;
570 pthread_cond_broadcast(&ticket->cond);
571 pthread_mutex_unlock(&ticket->mutex);
572}
573
574/* ************************************************ */
575
576/* Condition */
577
579{
580 pthread_cond_init(cond, nullptr);
581}
582
584{
585 pthread_cond_wait(cond, mutex);
586}
587
589{
590 pthread_cond_wait(cond, global_mutex_from_type(type));
591}
592
594{
595 pthread_cond_signal(cond);
596}
597
599{
600 pthread_cond_broadcast(cond);
601}
602
604{
605 pthread_cond_destroy(cond);
606}
607
608/* ************************************************ */
609
614
617 std::deque<ThreadQueueWork> queue_low_priority;
618 std::deque<ThreadQueueWork> queue_normal_priority;
619 std::deque<ThreadQueueWork> queue_high_priority;
620 pthread_mutex_t mutex;
621 pthread_cond_t push_cond;
622 pthread_cond_t finish_cond;
623 volatile int nowait = 0;
624 volatile int canceled = 0;
625};
626
628{
629 ThreadQueue *queue = MEM_new<ThreadQueue>(__func__);
630
631 pthread_mutex_init(&queue->mutex, nullptr);
632 pthread_cond_init(&queue->push_cond, nullptr);
633 pthread_cond_init(&queue->finish_cond, nullptr);
634
635 return queue;
636}
637
639{
640 /* destroy everything, assumes no one is using queue anymore */
641 pthread_cond_destroy(&queue->finish_cond);
642 pthread_cond_destroy(&queue->push_cond);
643 pthread_mutex_destroy(&queue->mutex);
644
645 MEM_delete(queue);
646}
647
649{
650 BLI_assert(work);
651
652 pthread_mutex_lock(&queue->mutex);
653
654 ThreadQueueWork work_reference;
655 work_reference.work = work;
656 work_reference.id = ++queue->current_id;
657
658 switch (priority) {
660 queue->queue_low_priority.push_back(work_reference);
661 break;
663 queue->queue_normal_priority.push_back(work_reference);
664 break;
666 queue->queue_high_priority.push_back(work_reference);
667 break;
668 }
669
670 /* signal threads waiting to pop */
671 pthread_cond_signal(&queue->push_cond);
672 pthread_mutex_unlock(&queue->mutex);
673
674 return work_reference.id;
675}
676
679{
680 if (queue->queue_low_priority.empty() && queue->queue_normal_priority.empty() &&
681 queue->queue_high_priority.empty())
682 {
683 pthread_cond_signal(&queue->finish_cond);
684 }
685}
686
688{
689 pthread_mutex_lock(&queue->mutex);
690
691 bool found = false;
692 auto check = [&](const ThreadQueueWork &work) {
693 if (work.id == work_id) {
694 found = true;
695 return true;
696 }
697 return false;
698 };
699
700 auto cancel = [&](std::deque<ThreadQueueWork> &sub_queue) {
701 sub_queue.erase(std::remove_if(sub_queue.begin(), sub_queue.end(), check), sub_queue.end());
702 };
703
704 cancel(queue->queue_low_priority);
705 cancel(queue->queue_normal_priority);
706 cancel(queue->queue_high_priority);
707
708 if (found) {
709 check_finalization(queue);
710 }
711
712 pthread_mutex_unlock(&queue->mutex);
713
714 return found;
715}
716
718{
719 ThreadQueueWork work_reference = {nullptr};
720
721 /* wait until there is work */
722 pthread_mutex_lock(&queue->mutex);
723 while (!queue->nowait && queue->queue_low_priority.empty() &&
724 queue->queue_normal_priority.empty() && queue->queue_high_priority.empty())
725 {
726 pthread_cond_wait(&queue->push_cond, &queue->mutex);
727 }
728
729 /* if we have something, pop it */
730 for (std::deque<ThreadQueueWork> *sub_queue :
732 {
733 if (sub_queue->empty()) {
734 continue;
735 }
736 work_reference = sub_queue->front();
737 sub_queue->pop_front();
738
739 /* Don't pop more than one work. */
740 break;
741 }
742
743 if (work_reference.work) {
744 check_finalization(queue);
745 }
746
747 pthread_mutex_unlock(&queue->mutex);
748
749 return work_reference.work;
750}
751
752static void wait_timeout(timespec *timeout, int ms)
753{
754 ldiv_t div_result;
755 long sec, usec, x;
756
757#ifdef WIN32
758 {
759 struct _timeb now;
760 _ftime(&now);
761 sec = now.time;
762 usec = now.millitm * 1000; /* microsecond precision would be better */
763 }
764#else
765 {
766 timeval now;
767 gettimeofday(&now, nullptr);
768 sec = now.tv_sec;
769 usec = now.tv_usec;
770 }
771#endif
772
773 /* add current time + millisecond offset */
774 div_result = ldiv(ms, 1000);
775 timeout->tv_sec = sec + div_result.quot;
776
777 x = usec + (div_result.rem * 1000);
778
779 if (x >= 1000000) {
780 timeout->tv_sec++;
781 x -= 1000000;
782 }
783
784 timeout->tv_nsec = x * 1000;
785}
786
788{
789 double t;
790 ThreadQueueWork work_reference = {nullptr};
791 timespec timeout;
792
794 wait_timeout(&timeout, ms);
795
796 /* wait until there is work */
797 pthread_mutex_lock(&queue->mutex);
798 while (!queue->nowait && queue->queue_low_priority.empty() &&
799 queue->queue_normal_priority.empty() && queue->queue_high_priority.empty())
800 {
801 if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) {
802 break;
803 }
804 if (BLI_time_now_seconds() - t >= ms * 0.001) {
805 break;
806 }
807 }
808
809 /* if we have something, pop it */
810 for (std::deque<ThreadQueueWork> *sub_queue :
812 {
813 if (sub_queue->empty()) {
814 continue;
815 }
816 work_reference = sub_queue->front();
817 sub_queue->pop_front();
818
819 /* Don't pop more than one work. */
820 break;
821 }
822
823 if (work_reference.work) {
824 check_finalization(queue);
825 }
826
827 pthread_mutex_unlock(&queue->mutex);
828
829 return work_reference.work;
830}
831
833{
834 int size;
835
836 pthread_mutex_lock(&queue->mutex);
837 size = queue->queue_low_priority.size() + queue->queue_normal_priority.size() +
838 queue->queue_high_priority.size();
839 pthread_mutex_unlock(&queue->mutex);
840
841 return size;
842}
843
845{
846 bool is_empty;
847
848 pthread_mutex_lock(&queue->mutex);
849 is_empty = queue->queue_low_priority.empty() && queue->queue_normal_priority.empty() &&
850 queue->queue_high_priority.empty();
851 pthread_mutex_unlock(&queue->mutex);
852
853 return is_empty;
854}
855
857{
858 pthread_mutex_lock(&queue->mutex);
859
860 queue->nowait = 1;
861
862 /* signal threads waiting to pop */
863 pthread_cond_broadcast(&queue->push_cond);
864 pthread_mutex_unlock(&queue->mutex);
865}
866
868{
869 /* wait for finish condition */
870 pthread_mutex_lock(&queue->mutex);
871
872 while (!queue->queue_low_priority.empty() || !queue->queue_normal_priority.empty() ||
873 !queue->queue_high_priority.empty())
874 {
875 pthread_cond_wait(&queue->finish_cond, &queue->mutex);
876 }
877
878 pthread_mutex_unlock(&queue->mutex);
879}
880
881} // namespace blender
#define SIMD_SET_FLUSH_TO_ZERO
Definition BLI_simd.hh:91
#define THREAD_LOCK_READ
Platform independent time functions.
Read Blender memory allocation and freeing.
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)
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
static void * tslot_thread_start(void *tslot_p)
Definition threads.cc:175
void BLI_thread_queue_nowait(ThreadQueue *queue)
Definition threads.cc:856
int BLI_available_threads(ListBaseT< ThreadSlot > *threadbase)
Definition threads.cc:148
void BLI_threadapi_exit()
Definition threads.cc:121
void BLI_ticket_mutex_lock(TicketMutex *ticket)
Definition threads.cc:555
ThreadQueueWorkPriority
@ BLI_THREAD_QUEUE_WORK_PRIORITY_HIGH
@ BLI_THREAD_QUEUE_WORK_PRIORITY_NORMAL
@ BLI_THREAD_QUEUE_WORK_PRIORITY_LOW
unsigned int uint
Definition BKE_text.h:55
pthread_spinlock_t SpinLock
void BLI_condition_init(ThreadCondition *cond)
Definition threads.cc:578
void * BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms)
Definition threads.cc:787
ThreadRWMutex * BLI_rw_mutex_alloc()
Definition threads.cc:490
bool BLI_mutex_trylock(ThreadMutex *mutex)
Definition threads.cc:358
static uint thread_levels
Definition threads.cc:102
static pthread_t mainid
Definition threads.cc:101
bool BLI_thread_queue_cancel_work(ThreadQueue *queue, uint64_t work_id)
Definition threads.cc:687
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition threads.cc:353
void BLI_rw_mutex_free(ThreadRWMutex *mutex)
Definition threads.cc:497
void BLI_thread_queue_wait_finish(ThreadQueue *queue)
Definition threads.cc:867
void BLI_threadpool_insert(ListBaseT< ThreadSlot > *threadbase, void *callerdata)
Definition threads.cc:189
static void wait_timeout(timespec *timeout, int ms)
Definition threads.cc:752
void BLI_system_num_threads_override_set(int num)
Definition threads.cc:294
bool BLI_thread_queue_is_empty(ThreadQueue *queue)
Definition threads.cc:844
void BLI_threadpool_end(ListBaseT< ThreadSlot > *threadbase)
Definition threads.cc:239
static int threads_override_num
Definition threads.cc:103
int BLI_threadpool_available_thread_index(ListBaseT< ThreadSlot > *threadbase)
Definition threads.cc:161
ThreadMutex * BLI_mutex_alloc()
Definition threads.cc:368
@ LOCK_DRAW_IMAGE
@ LOCK_MOVIECLIP
void BLI_condition_wait(ThreadCondition *cond, ThreadMutex *mutex)
Definition threads.cc:583
static pthread_mutex_t _movieclip_lock
Definition threads.cc:98
void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode)
Definition threads.cc:470
void BLI_threadapi_init()
Definition threads.cc:116
void BLI_rw_mutex_init(ThreadRWMutex *mutex)
Definition threads.cc:465
void BLI_condition_end(ThreadCondition *cond)
Definition threads.cc:603
static pthread_mutex_t _image_lock
Definition threads.cc:93
static pthread_mutex_t _custom1_lock
Definition threads.cc:96
int BLI_system_thread_count()
Definition threads.cc:258
static ThreadMutex * global_mutex_from_type(const int type)
Definition threads.cc:306
void BLI_condition_notify_one(ThreadCondition *cond)
Definition threads.cc:593
void BLI_spin_end(SpinLock *spin)
Definition threads.cc:448
void BLI_mutex_lock(ThreadMutex *mutex)
Definition threads.cc:348
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BLI_rw_mutex_unlock(ThreadRWMutex *mutex)
Definition threads.cc:480
static pthread_mutex_t _nodes_lock
Definition threads.cc:97
static pthread_mutex_t _view3d_lock
Definition threads.cc:100
void BLI_condition_wait_global_mutex(ThreadCondition *cond, int type)
Definition threads.cc:588
static pthread_mutex_t _image_draw_lock
Definition threads.cc:94
TicketMutex * BLI_ticket_mutex_alloc()
Definition threads.cc:513
static void check_finalization(ThreadQueue *queue)
Definition threads.cc:678
void BLI_ticket_mutex_free(TicketMutex *ticket)
Definition threads.cc:523
int BLI_thread_is_main()
Definition threads.cc:184
void BLI_thread_queue_free(ThreadQueue *queue)
Definition threads.cc:638
ThreadQueue * BLI_thread_queue_init()
Definition threads.cc:627
ATTR_WARN_UNUSED_RESULT const size_t num
void * BLI_thread_queue_pop(ThreadQueue *queue)
Definition threads.cc:717
void BLI_threadpool_remove(ListBaseT< ThreadSlot > *threadbase, void *callerdata)
Definition threads.cc:202
void BLI_mutex_end(ThreadMutex *mutex)
Definition threads.cc:363
void BLI_condition_notify_all(ThreadCondition *cond)
Definition threads.cc:598
void BLI_ticket_mutex_unlock(TicketMutex *ticket)
Definition threads.cc:565
void BLI_rw_mutex_end(ThreadRWMutex *mutex)
Definition threads.cc:485
void BLI_spin_unlock(SpinLock *spin)
Definition threads.cc:433
void BLI_spin_init(SpinLock *spin)
Definition threads.cc:394
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BLI_mutex_free(ThreadMutex *mutex)
Definition threads.cc:375
int BLI_system_num_threads_override_get()
Definition threads.cc:299
pthread_cond_t ThreadCondition
pthread_mutex_t ThreadMutex
static bool ticket_mutex_lock(TicketMutex *ticket, const bool check_recursive)
Definition threads.cc:530
int BLI_thread_queue_len(ThreadQueue *queue)
Definition threads.cc:832
static pthread_mutex_t _fftw_lock
Definition threads.cc:99
double BLI_time_now_seconds()
Definition time.cc:30
bool BLI_ticket_mutex_lock_check_recursive(TicketMutex *ticket)
Definition threads.cc:560
void BLI_thread_unlock(int type)
Definition threads.cc:336
uint64_t BLI_thread_queue_push(ThreadQueue *queue, void *work, ThreadQueueWorkPriority priority)
Definition threads.cc:648
static pthread_mutex_t _viewer_lock
Definition threads.cc:95
pthread_rwlock_t ThreadRWMutex
void BLI_spin_lock(SpinLock *spin)
Definition threads.cc:408
void BLI_threadpool_remove_index(ListBaseT< ThreadSlot > *threadbase, int index)
Definition threads.cc:213
void BLI_mutex_init(ThreadMutex *mutex)
Definition threads.cc:343
void BLI_threadpool_init(ListBaseT< ThreadSlot > *threadbase, void *(*do_thread)(void *), int tot)
Definition threads.cc:123
void BLI_thread_lock(int type)
Definition threads.cc:331
void BLI_threadpool_clear(ListBaseT< ThreadSlot > *threadbase)
Definition threads.cc:228
std::deque< ThreadQueueWork > queue_high_priority
Definition threads.cc:619
volatile int nowait
Definition threads.cc:623
std::deque< ThreadQueueWork > queue_normal_priority
Definition threads.cc:618
std::deque< ThreadQueueWork > queue_low_priority
Definition threads.cc:617
volatile int canceled
Definition threads.cc:624
pthread_cond_t finish_cond
Definition threads.cc:622
pthread_cond_t push_cond
Definition threads.cc:621
pthread_mutex_t mutex
Definition threads.cc:620
pthread_t pthread
Definition threads.cc:112
ThreadSlot * next
Definition threads.cc:109
void *(*) do_thread(void *)
Definition threads.cc:110
ThreadSlot * prev
Definition threads.cc:109
pthread_cond_t cond
Definition threads.cc:506
pthread_mutex_t mutex
Definition threads.cc:507
#define RE_MAX_THREAD
Definition threads.cc:106