Changeset View
Standalone View
source/blender/blenlib/intern/threads.c
| Context not available. | |||||
| /* for checking system threads - BLI_system_thread_count */ | /* for checking system threads - BLI_system_thread_count */ | ||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| # include "BLI_winstuff.h" | |||||
| # include <windows.h> | # include <windows.h> | ||||
| # include <sys/timeb.h> | # include <sys/timeb.h> | ||||
| #elif defined(__APPLE__) | #elif defined(__APPLE__) | ||||
| Context not available. | |||||
| * problem otherwise: scene render will kill of the mutex! | * problem otherwise: scene render will kill of the mutex! | ||||
| */ | */ | ||||
| void BLI_threadpool_init(ListBase *threadbase, void *(*do_thread)(void *), int tot) | void BLI_threadpool_init(ListBase *threadbase, void *(*do_thread)(void *), int tot, const char *pool_name) | ||||
| { | { | ||||
| int a; | int a; | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| const char *thread_name; | |||||
| if (pool_name) | |||||
sybren: Is `pool_name` this the name of the pool or the name of the thread? It seems to be used as both… | |||||
velocityAuthorUnsubmitted Done Inline ActionsWell it's the pool name, but it's only use by the implementation is to set it as a thread name. You're right, I'll just name it thread_name, since I also need to make the < 15 chars requirement clear. velocity: Well it's the pool name, but it's only use by the implementation is to set it as a thread name. | |||||
| thread_name = pool_name; | |||||
| else | |||||
| thread_name = "Unnamed TPool"; | |||||
brechtUnsubmitted Done Inline ActionsDon't use unnecessary abbreviations like "TPool" or "Sched". brecht: Don't use unnecessary abbreviations like "TPool" or "Sched". | |||||
velocityAuthorUnsubmitted Done Inline ActionsYeah I'd like to use more expressive names, but it's a POSIX limitation that the thread name can't be longer than 15 characters, so I had to abbreviate. I should probably mention this in the documentation for BLI_threadpool_init too (after I rename it to thread_name). Alternatively, I could not have this limitatin for the threadpool API and cull to the last 15 characters (or something like that) when naming the thread, what do you think? velocity: Yeah I'd like to use more expressive names, but it's a [[ https://linux.die. | |||||
| BLI_thread_name_set(thread_name); | |||||
| 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); | ||||
Not Done Inline ActionsSeems that thread_name will be considered unused with pedantic compiler? Easy to fix when applying though. sergey: Seems that `thread_name` will be considered unused with pedantic compiler? Easy to fix when… | |||||
Done Inline ActionsIs there any good reason just to do this for debug builds? I tend to profile RelWithDebinfo Builds a lot and named threads would be nice there as well. LazyDodo: Is there any good reason just to do this for debug builds? I tend to profile RelWithDebinfo… | |||||
Done Inline ActionsNot really, I just didn't think it'd be useful, but touche, I'll enable it on release builds too. velocity: Not really, I just didn't think it'd be useful, but touche, I'll enable it on release builds… | |||||
| Context not available. | |||||
| pthread_mutex_unlock(&queue->mutex); | pthread_mutex_unlock(&queue->mutex); | ||||
| } | } | ||||
| void BLI_thread_name_set(const char* thread_name) | |||||
| { | |||||
| #ifndef NDEBUG | |||||
| if (thread_name) | |||||
sergeyUnsubmitted Done Inline Actions
sergey: - Put { at the same line
- Would prefer to have early output rather than having a whole block… | |||||
| { | |||||
| #if defined(_MSC_VER) && !defined(NDEBUG) | |||||
sergeyUnsubmitted Done Inline ActionsNDEBUG is already checked. sergey: `NDEBUG` is already checked. | |||||
velocityAuthorUnsubmitted Done Inline ActionsI fixed this yesterday, I probably messed something up updating the patch. velocity: I fixed this yesterday, I probably messed something up updating the patch. | |||||
| if (IsDebuggerPresent()) | |||||
| SetThreadName(-1, thread_name); | |||||
| #elif defined(__linux__) | |||||
| pthread_setname_np(pthread_self(), thread_name); | |||||
| #elif defined(__APPLE__) | |||||
Not Done Inline Actions# if defined(_WIN32) || (defined(__linux__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)) try this? LazyDodo: ```
# if defined(_WIN32) || (defined(__linux__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >=… | |||||
| pthread_setname_np(thread_name); | |||||
| #elif defined(__FreeBSD__) | |||||
| pthread_setname_np(pthread_self(), "%s", thread_name); | |||||
| #endif | |||||
| } | |||||
| #endif | |||||
| } | |||||
| void BLI_thread_queue_wait_finish(ThreadQueue *queue) | void BLI_thread_queue_wait_finish(ThreadQueue *queue) | ||||
| { | { | ||||
| /* wait for finish condition */ | /* wait for finish condition */ | ||||
| Context not available. | |||||
Is pool_name this the name of the pool or the name of the thread? It seems to be used as both, which I find confusing.