fixed previous commit

pthread.h was not included in thread.c in the end

\+ small improvements
This commit is contained in:
Martin Pulec
2023-11-10 16:04:44 +01:00
parent 9f5530df1b
commit ddaba11059
2 changed files with 7 additions and 4 deletions

View File

@@ -40,6 +40,9 @@
#endif
#include <libgen.h>
#ifndef _WIN32
#include <pthread.h>
#endif
#ifdef HAVE_SETTHREADDESCRIPTION
#include <processthreadsapi.h>
#endif
@@ -65,7 +68,7 @@ static inline char *get_argv_program_name(void) {
#endif
void set_thread_name(const char *name) {
#ifdef HAVE_LINUX
#ifdef __linux__
// thread name can have at most 16 chars (including terminating null char)
char *prog_name = get_argv_program_name();
char tmp[16];
@@ -74,14 +77,14 @@ void set_thread_name(const char *name) {
free(prog_name);
strncat(tmp, name, sizeof tmp - strlen(tmp) - 1);
pthread_setname_np(pthread_self(), tmp);
#elif defined HAVE_MACOSX
#elif defined __APPLE__
char *prog_name = get_argv_program_name();
char *tmp = (char *) alloca(strlen(prog_name) + strlen(name) + 1);
strcpy(tmp, prog_name);
free(prog_name);
strcat(tmp, name);
pthread_setname_np(tmp);
#elif defined WIN32
#elif defined _WIN32
// supported from Windows 10, not yet in headers
#ifdef HAVE_SETTHREADDESCRIPTION
const char *prog_name = get_argv_program_name();

View File

@@ -39,8 +39,8 @@
#include "utils/thread.h"
#include "utils/worker.h"
#include <cassert>
#include <algorithm>
#include <cassert>
#include <pthread.h>
#include <queue>
#include <set>