Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/threads' into threads
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Oct 14, 2024
2 parents 58d5fd8 + 064c303 commit a5c3af2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions libs/thread.b
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class Thread {
raise Exception('string length must be between 1 and 16')
}

self._name = name
_thread.set_name(name)
if self._ptr {
self._name = name
_thread.set_name(self._ptr, name)
}
}

get_name() {
Expand Down
16 changes: 13 additions & 3 deletions src/standard/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@ DECLARE_MODULE_METHOD(thread__detach) {
}

DECLARE_MODULE_METHOD(thread__set_name) {
ENFORCE_ARG_COUNT(set_name, 1);
ENFORCE_ARG_TYPE(set_name, 0, IS_STRING);
RETURN_BOOL(pthread_setname_np(AS_C_STRING(args[0])) == 0);
ENFORCE_ARG_COUNT(set_name, 2);
ENFORCE_ARG_TYPE(set_name, 0, IS_PTR);
ENFORCE_ARG_TYPE(set_name, 1, IS_STRING);
#ifdef __APPLE__
RETURN_BOOL(pthread_setname_np(AS_C_STRING(args[1])) == 0);
#else
b_thread_handle *thread = AS_PTR(args[0])->pointer;
# if defined(PTHREAD_MAX_NAMELEN_NP) && PTHREAD_MAX_NAMELEN_NP == 16
RETURN_BOOL(pthread_setname_np(thread->thread, AS_C_STRING(args[1]), NULL) == 0);
# else
RETURN_BOOL(pthread_setname_np(thread->thread, AS_C_STRING(args[1])) == 0);
# endif
#endif
}

uint64_t get_thread_id(void)
Expand Down

0 comments on commit a5c3af2

Please sign in to comment.