16 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,
NULL);
17 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
27 return pthread_self();
29 return GetCurrentThread();
31 #pragma message("Not implemented on this platform")
47 #if defined(HAVE_PTHREAD_NP) && HAVE_PTHREAD_NP
48 #if __linux__ || __sun
49 if (pthread_setname_np(th->tid,
name) != 0) {
53 #elif __APPLE__ && defined(MAC_OS_X_VERSION_10_6)
54 if (pthread_setname_np(
name) != 0) {
58 #elif __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun
59 pthread_set_name_np(th->tid,
name);
61 if (pthread_setname_np(th->tid,
"%s", (
void *)
name) != 0) {
66 if (rename_thread((thread_id)th->tid,
name) != B_OK) {
71 #pragma message("warning rz_th_setname not implemented")
89 #if defined(HAVE_PTHREAD_NP) && HAVE_PTHREAD_NP
90 #if __linux__ || __NetBSD__ || (__APPLE__ && defined(MAC_OS_X_VERSION_10_6)) || __sun
91 if (pthread_getname_np(th->tid,
name,
len) != 0) {
95 #elif (__FreeBSD__ && __FreeBSD_version >= 1200000) || __DragonFly__ || (__OpenBSD__ && OpenBSD >= 201905)
96 pthread_get_name_np(th->tid,
name,
len);
97 #elif defined(__HAIKU__)
99 size_t flen =
len < B_OS_NAME_LENGTH ?
len : B_OS_NAME_LENGTH;
101 if (get_thread_info((thread_id)th->tid, &ti) != B_OK) {
108 #pragma message("warning rz_th_getname not implemented")
126 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)
128 #pragma message("warning rz_th_setaffinity not implemented")
134 if (sched_setaffinity((
pid_t)(
ut64)th->tid,
sizeof(
c), &
c) != 0) {
139 #elif __FreeBSD__ || __DragonFly__
144 if (pthread_setaffinity_np(th->tid,
sizeof(
c), &
c) != 0) {
152 if (pthread_setaffinity_np(th->tid, cpuset_size(
c),
c) != 0) {
160 thread_affinity_policy_data_t
c = { cpuid };
161 if (thread_policy_set(pthread_mach_thread_np(th->tid),
162 THREAD_AFFINITY_POLICY, (thread_policy_t)&
c, 1) != KERN_SUCCESS) {
167 if (SetThreadAffinityMask(th->tid, (DWORD_PTR)1 << cpuid) == 0) {
175 pset_assign(
c, cpuid,
NULL);
177 if (pset_bind(
c, P_PID, getpid(),
NULL)) {
185 #pragma message("warning rz_th_setaffinity not implemented")
235 return pthread_join(th->tid, &thret) == 0;
237 return WaitForSingleObject(th->tid, INFINITE) == 0;
251 CloseHandle(th->tid);
287 return SwitchToThread() != 0;
RZ_API void Ht_() free(HtName_(Ht) *ht)
static RZ_TH_RET_T thread_main_function(void *_th)
RZ_API void rz_th_free(RZ_NULLABLE RzThread *th)
Frees a RzThread structure.
RZ_API RZ_OWN void * rz_th_get_user(RZ_NONNULL RzThread *th)
Returns user pointer of thread.
RZ_API bool rz_th_yield(void)
Yield the processor.
RZ_API bool rz_th_set_affinity(RZ_NONNULL RzThread *th, int cpuid)
Sets the thread cpu affinity.
RZ_API bool rz_th_get_name(RZ_NONNULL RzThread *th, RZ_NONNULL RZ_OUT char *name, size_t len)
Gets the name of the thread and writes it into the output buffer.
RZ_API RZ_OWN RzThread * rz_th_new(RZ_NONNULL RzThreadFunction function, RZ_NULLABLE void *user)
Creates and starts a new thread.
RZ_API RZ_OWN void * rz_th_get_retv(RZ_NONNULL RzThread *th)
Returns return value of the thread.
RZ_API bool rz_th_wait(RZ_NONNULL RzThread *th)
Awaits indefinetely for a thread to join.
RZ_IPI RZ_TH_TID rz_th_self(void)
RZ_API bool rz_th_set_name(RZ_NONNULL RzThread *th, RZ_NONNULL const char *name)
Sets the name of the thread.
#define rz_return_val_if_fail(expr, val)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
void *(* RzThreadFunction)(void *user)
void * retv
Thread return value.
RZ_TH_TID tid
Thread identifier.
void * user
User defined thread data to pass (can be NULL).
RzThreadFunction function
User defined thread function.
ut64(WINAPI *w32_GetEnabledXStateFeatures)()