gcc: Threads support enabled

TODO: Impl pthread_cond for libstdc++

Signed-off-by: Max Logaev <maxlogaev@proton.me>
This commit is contained in:
2026-03-04 04:50:48 +03:00
parent cdb58c68a5
commit c22e35146b
7 changed files with 64 additions and 4 deletions

View File

@@ -9,7 +9,7 @@
#include <stdatomic.h>
#include <sys/cdefs.h>
#include <sys/sched.h>
#include <sched.h>
#include <sys/_pthreadtypes.h>
#ifdef __cplusplus

View File

@@ -132,6 +132,13 @@ typedef struct
#define _PTHREAD_ONCE_INIT { 0 }
/* POSIX Condition Variables */
typedef struct
{
int stub;
} pthread_cond_t;
#ifdef __cplusplus
extern "C"
}

View File

@@ -12,6 +12,7 @@ add_executable(mutex pthread/mutex.c)
add_executable(mutex_errcheck pthread/mutex_errcheck.c)
add_executable(key pthread/key.c)
add_executable(once pthread/once.c)
add_executable(thread_local pthread/thread_local.c)
install(TARGETS hello malloc DESTINATION tests)
install(TARGETS mutex mutex_errcheck create detach exit key once DESTINATION tests/pthread)
install(TARGETS mutex mutex_errcheck create detach exit key once thread_local DESTINATION tests/pthread)

View File

@@ -0,0 +1,52 @@
#include <string.h>
#include <kolibrios/dbg.h>
#include <pthread.h>
static _Thread_local int tl_var = 99;
static void *
thread (void *arg)
{
if (tl_var != 99)
{
__kos_dbg_puts ("E: Test failed: tl != 99");
}
tl_var = 222;
return NULL;
}
int
main ()
{
int rc = 0;
pthread_t id;
tl_var = 100;
__kos_dbg_puts ("I: Thread local test");
rc = pthread_create (&id, NULL, thread, NULL);
if (rc)
{
__kos_dbg_printf ("E: pthread_create() failed: %s\n", strerror (rc));
return 1;
}
rc = pthread_join (id, NULL);
if (rc)
{
__kos_dbg_printf ("E: pthread_join() failed: %s\n", strerror (rc));
return 1;
}
if (tl_var != 100)
{
__kos_dbg_puts ("E: Test failed: tl != 100");
return 1;
}
__kos_dbg_puts ("I: Test passed");
return 0;
}

View File

@@ -63,6 +63,7 @@ ExternalProject_Add(
--disable-multilib
--disable-nls
--enable-shared
--enable-threads
--enable-languages=c
BUILD_COMMAND
make -j${JOBS} all-gcc all-target-libgcc

View File

@@ -2121,7 +2121,6 @@ i[34567]86-*-kolibrios*)
default_use_cxa_atexit=yes
use_gcc_stdint=wrap
if test x$enable_threads = xyes; then
# Not supported yet!
thread_file='posix'
fi
;;

View File

@@ -13012,7 +13012,7 @@ case ${enable_threads} in
target_thread_file='single'
;;
aix | dce | lynx | mipssde | posix | rtems | \
single | tpf | vxworks | win32 | mcf | kolibrios)
single | tpf | vxworks | win32 | mcf)
target_thread_file=${enable_threads}
;;
*)