Short circuit the most common pthread_canceled() call for singlethreaded programs

This commit is contained in:
Lubos Dolezel 2018-07-18 22:10:01 +02:00
parent 6d65774cf7
commit 1515283c7f
3 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,8 @@ extern void *memset(void *s, int c, size_t n);
#define STACK_GUARD_SIZE 4096
static bool _uses_threads = false;
// http://www.tldp.org/FAQ/Threads-FAQ/clone.c
long sys_bsdthread_create(void* thread_start, void* arg,
@ -31,6 +33,8 @@ long sys_bsdthread_create(void* thread_start, void* arg,
int ret;
unsigned long stacksize = 0;
_uses_threads = true;
#ifndef BSDTHREAD_WRAP_LINUX_PTHREAD
if (!(flags & PTHREAD_START_CUSTOM))
{
@ -123,4 +127,8 @@ int darling_thread_create(void** stack, void* entry_point, uintptr_t arg3,
}
#endif
bool uses_threads(void)
{
return _uses_threads;
}

View File

@ -1,6 +1,7 @@
#ifndef BSDTHREAD_CREATE_H
#define BSDTHREAD_CREATE_H
#include <stdint.h>
#include <stdbool.h>
long sys_bsdthread_create(void* thread_start, void* arg, void** stack,
void* pthread, uint32_t flags);
@ -10,6 +11,8 @@ int darling_thread_create(void** stack, void* entry_point, uintptr_t arg3,
void* thread_stack_allocate(unsigned long stacksize);
bool uses_threads(void);
#define LINUX_CLONE_VM 0x00000100
#define LINUX_CLONE_FS 0x00000200
#define LINUX_CLONE_FILES 0x00000400

View File

@ -5,9 +5,14 @@
#include <stddef.h>
#include "../mach/lkm.h"
#include "../../../../lkm/api.h"
#include "bsdthread_create.h"
#include <sys/errno.h>
long sys_pthread_canceled(int action)
{
if (action == 0 && !uses_threads())
return -EINVAL;
int ret = lkm_call(NR_pthread_canceled, (void*)(long) action);
if (ret < 0)
ret = errno_linux_to_bsd(ret);