libobs: Add ability to set thread names
This commit is contained in:
parent
3259a6831b
commit
144fb925ff
@ -20,6 +20,7 @@
|
||||
#include <mach/task.h>
|
||||
#include <mach/mach_init.h>
|
||||
#else
|
||||
#define _GNU_SOURCE
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
@ -248,3 +249,12 @@ long os_atomic_dec_long(volatile long *val)
|
||||
{
|
||||
return __sync_sub_and_fetch(val, 1);
|
||||
}
|
||||
|
||||
void os_set_thread_name(const char *name)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
pthread_setname_np(name);
|
||||
#else
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
#endif
|
||||
}
|
||||
|
@ -160,3 +160,32 @@ long os_atomic_dec_long(volatile long *val)
|
||||
{
|
||||
return InterlockedDecrement(val);
|
||||
}
|
||||
|
||||
#define VC_EXCEPTION 0x406D1388
|
||||
|
||||
#pragma pack(push,8)
|
||||
struct vs_threadname_info {
|
||||
DWORD type; /* 0x1000 */
|
||||
const char *name;
|
||||
DWORD thread_id;
|
||||
DWORD flags;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#define THREADNAME_INFO_SIZE \
|
||||
(sizeof(struct vs_threadname_info) / sizeof(ULONG_PTR))
|
||||
|
||||
void os_set_thread_name(const char *name)
|
||||
{
|
||||
struct vs_threadname_info info;
|
||||
info.type = 0x1000;
|
||||
info.name = name;
|
||||
info.thread_id = GetCurrentThreadId();
|
||||
info.flags = 0;
|
||||
|
||||
__try {
|
||||
RaiseException(VC_EXCEPTION, 0, THREADNAME_INFO_SIZE,
|
||||
(ULONG_PTR*)&info);
|
||||
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ EXPORT int os_sem_wait(os_sem_t *sem);
|
||||
EXPORT long os_atomic_inc_long(volatile long *val);
|
||||
EXPORT long os_atomic_dec_long(volatile long *val);
|
||||
|
||||
EXPORT void os_set_thread_name(const char *name);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user