pyhelper: define set_thread_name() helper

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets 2025-07-28 01:12:19 +02:00 committed by KevinOConnor
parent d5c031bc13
commit c78dd6a00a
3 changed files with 11 additions and 0 deletions

View File

@ -219,6 +219,7 @@ defs_trdispatch = """
defs_pyhelper = """ defs_pyhelper = """
void set_python_logging_callback(void (*func)(const char *)); void set_python_logging_callback(void (*func)(const char *));
double get_monotonic(void); double get_monotonic(void);
int set_thread_name(char name[16]);
""" """
defs_std = """ defs_std = """

View File

@ -10,6 +10,8 @@
#include <stdio.h> // fprintf #include <stdio.h> // fprintf
#include <string.h> // strerror #include <string.h> // strerror
#include <time.h> // struct timespec #include <time.h> // struct timespec
#include <linux/prctl.h> // PR_SET_NAME
#include <sys/prctl.h> // prctl
#include "compiler.h" // __visible #include "compiler.h" // __visible
#include "pyhelper.h" // get_monotonic #include "pyhelper.h" // get_monotonic
@ -92,3 +94,10 @@ dump_string(char *outbuf, int outbuf_size, char *inbuf, int inbuf_size)
*o = '\0'; *o = '\0';
return outbuf; return outbuf;
} }
// Set custom thread names
int __visible
set_thread_name(char name[16])
{
return prctl(PR_SET_NAME, name);
}

View File

@ -7,5 +7,6 @@ void set_python_logging_callback(void (*func)(const char *));
void errorf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); void errorf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void report_errno(char *where, int rc); void report_errno(char *where, int rc);
char *dump_string(char *outbuf, int outbuf_size, char *inbuf, int inbuf_size); char *dump_string(char *outbuf, int outbuf_size, char *inbuf, int inbuf_size);
int set_thread_name(char name[16]);
#endif // pyhelper.h #endif // pyhelper.h