Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/threads.c
| Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | void BLI_threadapi_init(void) | ||||
| if (numaAPI_Initialize() == NUMAAPI_SUCCESS) { | if (numaAPI_Initialize() == NUMAAPI_SUCCESS) { | ||||
| is_numa_available = true; | is_numa_available = true; | ||||
| } | } | ||||
| } | } | ||||
| void BLI_threadapi_exit(void) | void BLI_threadapi_exit(void) | ||||
| { | { | ||||
| if (task_scheduler) { | if (task_scheduler) { | ||||
| BLI_task_scheduler_free(task_scheduler); | BLI_task_scheduler_legacy_free(task_scheduler); | ||||
| task_scheduler = NULL; | task_scheduler = NULL; | ||||
| } | } | ||||
| BLI_spin_end(&_malloc_lock); | BLI_spin_end(&_malloc_lock); | ||||
| } | } | ||||
| TaskScheduler *BLI_task_scheduler_get(void) | TaskScheduler *BLI_task_scheduler_legacy_get(void) | ||||
| { | { | ||||
| if (task_scheduler == NULL) { | if (task_scheduler == NULL) { | ||||
| int tot_thread = BLI_system_thread_count(); | int tot_thread = BLI_system_thread_count(); | ||||
| /* Do a lazy initialization, so it happens after | /* Do a lazy initialization, so it happens after | ||||
| * command line arguments parsing | * command line arguments parsing | ||||
| */ | */ | ||||
| task_scheduler = BLI_task_scheduler_create(tot_thread); | task_scheduler = BLI_task_scheduler_legacy_create(tot_thread); | ||||
| } | } | ||||
| return task_scheduler; | return task_scheduler; | ||||
| } | } | ||||
| /* tot = 0 only initializes malloc mutex in a safe way (see sequence.c) | /* tot = 0 only initializes malloc mutex in a safe way (see sequence.c) | ||||
| * problem otherwise: scene render will kill of the mutex! | * problem otherwise: scene render will kill of the mutex! | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 654 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| unsigned int level = atomic_fetch_and_add_u(&thread_levels, 1); | unsigned int level = atomic_fetch_and_add_u(&thread_levels, 1); | ||||
| if (level == 0) { | if (level == 0) { | ||||
| MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); | MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); | ||||
| /* There is a little chance that two threads will need to access to a | /* There is a little chance that two threads will need to access to a | ||||
| * scheduler which was not yet created from main thread. which could | * scheduler which was not yet created from main thread. which could | ||||
| * cause scheduler created multiple times. | * cause scheduler created multiple times. | ||||
| */ | */ | ||||
| BLI_task_scheduler_get(); | BLI_task_scheduler_legacy_get(); | ||||
| } | } | ||||
| } | } | ||||
| void BLI_threaded_malloc_end(void) | void BLI_threaded_malloc_end(void) | ||||
| { | { | ||||
| unsigned int level = atomic_sub_and_fetch_u(&thread_levels, 1); | unsigned int level = atomic_sub_and_fetch_u(&thread_levels, 1); | ||||
| if (level == 0) { | if (level == 0) { | ||||
| MEM_set_lock_callback(NULL, NULL); | MEM_set_lock_callback(NULL, NULL); | ||||
| ▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines | |||||