diff --git a/Makefile b/Makefile index d8bbf86b..1c2a1b12 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ MODULES=\ doc \ libc \ libm \ -libpthread \ dispd \ libmount \ bench \ @@ -126,7 +125,7 @@ sysroot-fsh: .PHONY: sysroot-base-headers sysroot-base-headers: sysroot-fsh export SYSROOT="$(SYSROOT)" && \ - (for D in libc libm libpthread kernel; do ($(MAKE) -C $$D install-headers DESTDIR="$(SYSROOT)") || exit $$?; done) + (for D in libc libm kernel; do ($(MAKE) -C $$D install-headers DESTDIR="$(SYSROOT)") || exit $$?; done) .PHONY: sysroot-system sysroot-system: sysroot-fsh sysroot-base-headers diff --git a/libc/Makefile b/libc/Makefile index bf222402..0ac48792 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -399,6 +399,50 @@ netdb/setservent.o \ poll/poll.o \ poll/ppoll.o \ psctl/psctl.o \ +pthread/pthread_attr_destroy.o \ +pthread/pthread_attr_getdetachstate.o \ +pthread/pthread_attr_getstacksize.o \ +pthread/pthread_attr_init.o \ +pthread/pthread_attr_setdetachstate.o \ +pthread/pthread_attr_setstacksize.o \ +pthread/pthread_condattr_destroy.o \ +pthread/pthread_condattr_getclock.o \ +pthread/pthread_condattr_init.o \ +pthread/pthread_condattr_setclock.o \ +pthread/pthread_cond_broadcast.o \ +pthread/pthread_cond_destroy.o \ +pthread/pthread_cond_init.o \ +pthread/pthread_cond_signal.o \ +pthread/pthread_cond_timedwait.o \ +pthread/pthread_cond_wait.o \ +pthread/pthread_create.o \ +pthread/pthread_detach.o \ +pthread/pthread_equal.o \ +pthread/pthread_exit.o \ +pthread/pthread_getspecific.o \ +pthread/pthread_join.o \ +pthread/pthread_key_create.o \ +pthread/pthread_key_delete.o \ +pthread/pthread_keys.o \ +pthread/pthread_mutexattr_destroy.o \ +pthread/pthread_mutexattr_gettype.o \ +pthread/pthread_mutexattr_init.o \ +pthread/pthread_mutexattr_settype.o \ +pthread/pthread_mutex_destroy.o \ +pthread/pthread_mutex_init.o \ +pthread/pthread_mutex_lock.o \ +pthread/pthread_mutex_trylock.o \ +pthread/pthread_mutex_unlock.o \ +pthread/pthread_once.o \ +pthread/pthread_rwlock_destroy.o \ +pthread/pthread_rwlock_init.o \ +pthread/pthread_rwlock_rdlock.o \ +pthread/pthread_rwlock_tryrdlock.o \ +pthread/pthread_rwlock_trywrlock.o \ +pthread/pthread_rwlock_unlock.o \ +pthread/pthread_rwlock_wrlock.o \ +pthread/pthread_self.o \ +pthread/pthread_setspecific.o \ pwd/bcrypt_newhash.o \ pwd/endpwent.o \ pwd/fgetpwent.o \ @@ -413,10 +457,18 @@ pwd/openpw.o \ pwd/setpwent.o \ sched/sched_yield.o \ scram/scram.o \ +semaphore/sem_destroy.o \ +semaphore/sem_getvalue.o \ +semaphore/sem_init.o \ +semaphore/sem_post.o \ +semaphore/sem_timedwait.o \ +semaphore/sem_trywait.o \ +semaphore/sem_wait.o \ signal/kill.o \ signal/killpg.o \ signal/psiginfo.o \ signal/psignal.o \ +signal/pthread_sigmask.o \ signal/raise.o \ signal/sigaction.o \ signal/sigaltstack.o \ @@ -696,7 +748,7 @@ ifeq ($(HOST),x86_64-sortix) LIBK_FLAGS:=$(LIBK_FLAGS) -mno-red-zone -mno-mmx -mno-sse -mno-sse2 endif -BINS=libc.a libdl.a librt.a $(CRTOBJ) +BINS=libc.a libdl.a libpthread.a librt.a $(CRTOBJ) BINSKERNEL=libk.a INSTALLLIBS:=$(addprefix $(DESTDIR)$(LIBDIR)/,$(BINS)) INSTALLLIBSKERNEL:=$(addprefix $(DESTDIR)$(LIBDIR)/,$(BINSKERNEL)) @@ -721,6 +773,9 @@ libdl.a: libk.a: $(LIBK_OBJS) $(AR) rcs $@ $(LIBK_OBJS) +libpthread.a: + $(AR) rcs $@ + librt.a: $(AR) rcs $@ diff --git a/libpthread/include/__/pthread.h b/libc/include/__/pthread.h similarity index 78% rename from libpthread/include/__/pthread.h rename to libc/include/__/pthread.h index 1e2420ed..b8e5f371 100644 --- a/libpthread/include/__/pthread.h +++ b/libc/include/__/pthread.h @@ -2,20 +2,20 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . __/pthread.h Thread API. @@ -33,9 +33,7 @@ extern "C" { #endif -#define __sortix_libpthread__ 1 - -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { __SIZE_TYPE__ stack_size; @@ -53,7 +51,7 @@ typedef int __pthread_barrier_t; typedef int __pthread_barrierattr_t; -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { struct pthread_cond_elem* first; @@ -69,7 +67,7 @@ typedef struct } __pthread_cond_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { __clock_t clock; @@ -83,7 +81,7 @@ typedef struct typedef __SIZE_TYPE__ __pthread_key_t; -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { unsigned long lock; @@ -101,7 +99,7 @@ typedef struct } __pthread_mutex_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { int type; @@ -113,7 +111,7 @@ typedef struct } __pthread_mutexattr_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { __pthread_mutex_t lock; @@ -127,7 +125,7 @@ typedef struct } __pthread_once_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { __pthread_cond_t reader_condition; @@ -151,7 +149,7 @@ typedef struct } __pthread_rwlock_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct { } __pthread_rwlockattr_t; @@ -163,7 +161,7 @@ typedef struct typedef int __pthread_spinlock_t; -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) typedef struct pthread* __pthread_t; #else typedef struct __pthread* __pthread_t; diff --git a/libc/include/features.h b/libc/include/features.h index 93e3eeaa..81281815 100644 --- a/libc/include/features.h +++ b/libc/include/features.h @@ -29,8 +29,7 @@ /* Detect whether we are a core system library. */ #if defined(__is_sortix_libc) || \ - defined(__is_sortix_libm) || \ - defined(__is_sortix_libpthread) + defined(__is_sortix_libm) #if !defined(__is_sortix_system_library) #define __is_sortix_system_library #endif diff --git a/libpthread/include/pthread.h b/libc/include/pthread.h similarity index 93% rename from libpthread/include/pthread.h rename to libc/include/pthread.h index bf7cc8be..d8584298 100644 --- a/libpthread/include/pthread.h +++ b/libc/include/pthread.h @@ -2,20 +2,20 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . pthread.h Thread API. @@ -32,12 +32,12 @@ #include #include -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) #include #include #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) #include #endif @@ -136,7 +136,7 @@ typedef __pthread_spinlock_t pthread_spinlock_t; typedef __pthread_t pthread_t; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) struct pthread { struct uthread uthread; @@ -151,7 +151,7 @@ struct pthread }; #endif -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) struct pthread_cond_elem { struct pthread_cond_elem* next; @@ -170,9 +170,7 @@ struct pthread_cond_elem #define PTHREAD_ONCE_INIT { PTHREAD_NORMAL_MUTEX_INITIALIZER_NP, 0 } -void pthread_initialize(void); - -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) struct pthread_key { diff --git a/libpthread/include/semaphore.h b/libc/include/semaphore.h similarity index 71% rename from libpthread/include/semaphore.h rename to libc/include/semaphore.h index 1e8ddb02..385f60c8 100644 --- a/libpthread/include/semaphore.h +++ b/libc/include/semaphore.h @@ -2,20 +2,20 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . semaphore.h Semaphore API. @@ -35,7 +35,7 @@ extern "C" { typedef struct { -#if defined(__is_sortix_libpthread) +#if defined(__is_sortix_libc) int value; #else int __value; diff --git a/libc/include/unistd.h b/libc/include/unistd.h index aef86d07..ac820983 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -105,17 +105,17 @@ extern "C" { #define _POSIX_SPIN_LOCKS 200809L /*TODO: _POSIX_SPORADIC_SERVER - Research what this is. */ /*TODO: _POSIX_SYNCHRONIZED_IO - Research what this is. */ -/*TODO: _POSIX_THREAD_ATTR_STACKADDR - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_ATTR_STACKSIZE - Research what this is, cooperate with libpthread. */ +/*TODO: _POSIX_THREAD_ATTR_STACKADDR - Research what this is. */ +/*TODO: _POSIX_THREAD_ATTR_STACKSIZE - Research what this is. */ #define _POSIX_THREAD_CPUTIME 200809L -/*TODO: _POSIX_THREAD_PRIO_INHERIT - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_PRIO_PROTECT - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_PRIORITY_SCHEDULING - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_PROCESS_SHARED - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_ROBUST_PRIO_INHERIT - Research what this is, cooperate with libpthread. */ -/*TODO: _POSIX_THREAD_ROBUST_PRIO_PROTECT - Research what this is, cooperate with libpthread. */ +/*TODO: _POSIX_THREAD_PRIO_INHERIT - Research what this is. */ +/*TODO: _POSIX_THREAD_PRIO_PROTECT - Research what this is. */ +/*TODO: _POSIX_THREAD_PRIORITY_SCHEDULING - Research what this is. */ +/*TODO: _POSIX_THREAD_PROCESS_SHARED - Research what this is. */ +/*TODO: _POSIX_THREAD_ROBUST_PRIO_INHERIT - Research what this is. */ +/*TODO: _POSIX_THREAD_ROBUST_PRIO_PROTECT - Research what this is. */ #define _POSIX_THREAD_SAFE_FUNCTIONS 200809L -/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is, cooperate with libpthread. */ +/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is. */ #define _POSIX_THREADS 200809L #define _POSIX_TIMEOUTS 200809L #define _POSIX_TIMERS 200809L diff --git a/libc/init/init.c b/libc/init/init.c index d71e78cf..eb8a83e6 100644 --- a/libc/init/init.c +++ b/libc/init/init.c @@ -18,11 +18,11 @@ along with the Sortix C Library. If not, see . init/init.c - Initializes the process by setting up the heap, signal handling, static - memory and other useful things. + Initializes the standard library. *******************************************************************************/ +#include #include #include #include @@ -39,12 +39,48 @@ static char* find_last_elem(char* str) return str; } +// Emit an ELF note containing the size and alignment of struct pthread. +__attribute__((used)) +static void elf_note_sortix_pthread_size(void) +{ + asm volatile ( + ".pushsection .note.sortix,\"a\",@note\n\t" + ".align 4\n\t" + ".long 2f-1f\n\t" // namesz + ".long 4f-3f\n\t" // descsz + ".long %c0\n" // type + "1:\n\t" + ".string \"Sortix\"\n" // name + "2:\n\t" + ".align 4\n" + "3:\n\t" +#if defined(__x86_64__) + ".quad %c1\n" + ".quad %c2\n" +#elif defined(__i386__) + ".long %c1\n" + ".long %c2\n" +#endif + "4:\n\t" + ".align 4\n\t" + ".popsection\n\t" + :: "n"(ELF_NOTE_SORTIX_UTHREAD_SIZE), + "n"(sizeof(struct pthread)), + "n"(alignof(struct pthread)) + ); +} + void initialize_standard_library(int argc, char* argv[]) { const char* argv0 = argc ? argv[0] : ""; program_invocation_name = (char*) argv0; program_invocation_short_name = find_last_elem((char*) argv0); - // Initialize pthreads. - pthread_initialize(); + struct pthread* self = pthread_self(); + self->join_lock = (pthread_mutex_t) PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; + self->join_lock.lock = 1 /* LOCKED_VALUE */; + self->join_lock.type = PTHREAD_MUTEX_NORMAL; + self->join_lock.owner = (unsigned long) self; + self->detach_lock = (pthread_mutex_t) PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; + self->detach_state = PTHREAD_CREATE_JOINABLE; } diff --git a/libpthread/pthread_attr_destroy.c++ b/libc/pthread/pthread_attr_destroy.c similarity index 51% rename from libpthread/pthread_attr_destroy.c++ rename to libc/pthread/pthread_attr_destroy.c index f5e17945..eb83c9b3 100644 --- a/libpthread/pthread_attr_destroy.c++ +++ b/libc/pthread/pthread_attr_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_destroy.c++ + pthread/pthread_attr_destroy.c Destroys a thread attributes object. *******************************************************************************/ #include -extern "C" int pthread_attr_destroy(pthread_attr_t* /*attr*/) +int pthread_attr_destroy(pthread_attr_t* attr) { + (void) attr; return 0; } diff --git a/libpthread/pthread_attr_getdetachstate.c++ b/libc/pthread/pthread_attr_getdetachstate.c similarity index 59% rename from libpthread/pthread_attr_getdetachstate.c++ rename to libc/pthread/pthread_attr_getdetachstate.c index 02eeb12f..2af6d4da 100644 --- a/libpthread/pthread_attr_getdetachstate.c++ +++ b/libc/pthread/pthread_attr_getdetachstate.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_getdetachstate.c++ + pthread/pthread_attr_getdetachstate.c Gets the requested detach state in a thread attribute object. *******************************************************************************/ #include -extern "C" int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* detach_state) { return *detach_state = attr->detach_state, 0; diff --git a/libpthread/pthread_attr_getstacksize.c++ b/libc/pthread/pthread_attr_getstacksize.c similarity index 61% rename from libpthread/pthread_attr_getstacksize.c++ rename to libc/pthread/pthread_attr_getstacksize.c index a1b607f2..046db458 100644 --- a/libpthread/pthread_attr_getstacksize.c++ +++ b/libc/pthread/pthread_attr_getstacksize.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_getstacksize.c++ + pthread/pthread_attr_getstacksize.c Gets the requested stack size in a thread attribute object. *******************************************************************************/ #include -extern "C" int pthread_attr_getstacksize(const pthread_attr_t* restrict attr, size_t* restrict stack_size_ptr) { diff --git a/libpthread/pthread_attr_init.c++ b/libc/pthread/pthread_attr_init.c similarity index 60% rename from libpthread/pthread_attr_init.c++ rename to libc/pthread/pthread_attr_init.c index 9e1ea469..b983677f 100644 --- a/libpthread/pthread_attr_init.c++ +++ b/libc/pthread/pthread_attr_init.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_init.c++ + pthread/pthread_attr_init.c Initialize a thread attributes object. *******************************************************************************/ @@ -27,7 +27,7 @@ static const unsigned long DEFAULT_STACK_SIZE = 80 * 1024; -extern "C" int pthread_attr_init(pthread_attr_t* attr) +int pthread_attr_init(pthread_attr_t* attr) { memset(attr, 0, sizeof(*attr)); attr->stack_size = DEFAULT_STACK_SIZE; diff --git a/libpthread/pthread_attr_setdetachstate.c++ b/libc/pthread/pthread_attr_setdetachstate.c similarity index 63% rename from libpthread/pthread_attr_setdetachstate.c++ rename to libc/pthread/pthread_attr_setdetachstate.c index 8460b938..838cc7af 100644 --- a/libpthread/pthread_attr_setdetachstate.c++ +++ b/libc/pthread/pthread_attr_setdetachstate.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_setdetachstate.c++ + pthread/pthread_attr_setdetachstate.c Sets the requested detach state in a thread attribute object. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int pthread_attr_setdetachstate(pthread_attr_t* attr, int detach_state) { if ( detach_state != PTHREAD_CREATE_JOINABLE && diff --git a/libpthread/pthread_attr_setstacksize.c++ b/libc/pthread/pthread_attr_setstacksize.c similarity index 53% rename from libpthread/pthread_attr_setstacksize.c++ rename to libc/pthread/pthread_attr_setstacksize.c index 03b3373a..4f2a2400 100644 --- a/libpthread/pthread_attr_setstacksize.c++ +++ b/libc/pthread/pthread_attr_setstacksize.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_attr_setstacksize.c++ + pthread/pthread_attr_setstacksize.c Sets the requested stack size in a thread attribute object. *******************************************************************************/ #include -extern "C" int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stack_size) +int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stack_size) { attr->stack_size = stack_size; return 0; diff --git a/libpthread/pthread_cond_broadcast.c++ b/libc/pthread/pthread_cond_broadcast.c similarity index 51% rename from libpthread/pthread_cond_broadcast.c++ rename to libc/pthread/pthread_cond_broadcast.c index 43b0dff9..909eff04 100644 --- a/libpthread/pthread_cond_broadcast.c++ +++ b/libc/pthread/pthread_cond_broadcast.c @@ -2,32 +2,33 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_broadcast.c++ + pthread/pthread_cond_broadcast.c Broadcasts a condition. *******************************************************************************/ #include -extern "C" int pthread_cond_broadcast(pthread_cond_t* cond) +int pthread_cond_broadcast(pthread_cond_t* cond) { + int ret; while ( cond->first ) - if ( int ret = pthread_cond_signal(cond) ) + if ( (ret = pthread_cond_signal(cond)) ) return ret; return 0; } diff --git a/libpthread/pthread_cond_destroy.c++ b/libc/pthread/pthread_cond_destroy.c similarity index 51% rename from libpthread/pthread_cond_destroy.c++ rename to libc/pthread/pthread_cond_destroy.c index 549cb1e7..831f9643 100644 --- a/libpthread/pthread_cond_destroy.c++ +++ b/libc/pthread/pthread_cond_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_destroy.c++ + pthread/pthread_cond_destroy.c Destroys a condition variable. *******************************************************************************/ #include -extern "C" int pthread_cond_destroy(pthread_cond_t* restrict /*cond*/) +int pthread_cond_destroy(pthread_cond_t* restrict cond) { + (void) cond; return 0; } diff --git a/libpthread/pthread_cond_init.c++ b/libc/pthread/pthread_cond_init.c similarity index 65% rename from libpthread/pthread_cond_init.c++ rename to libc/pthread/pthread_cond_init.c index 37d4b5ce..00142270 100644 --- a/libpthread/pthread_cond_init.c++ +++ b/libc/pthread/pthread_cond_init.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_init.c++ + pthread/pthread_cond_init.c Initializes a condition variable. *******************************************************************************/ #include -extern "C" int pthread_cond_init(pthread_cond_t* restrict cond, const pthread_condattr_t* restrict attr) { diff --git a/libpthread/pthread_cond_signal.c++ b/libc/pthread/pthread_cond_signal.c similarity index 58% rename from libpthread/pthread_cond_signal.c++ rename to libc/pthread/pthread_cond_signal.c index c754ea13..5a1b2736 100644 --- a/libpthread/pthread_cond_signal.c++ +++ b/libc/pthread/pthread_cond_signal.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_signal.c++ + pthread/pthread_cond_signal.c Signals a condition. *******************************************************************************/ #include -extern "C" int pthread_cond_signal(pthread_cond_t* cond) +int pthread_cond_signal(pthread_cond_t* cond) { struct pthread_cond_elem* elem = cond->first; if ( !elem ) diff --git a/libpthread/pthread_cond_timedwait.c++ b/libc/pthread/pthread_cond_timedwait.c similarity index 73% rename from libpthread/pthread_cond_timedwait.c++ rename to libc/pthread/pthread_cond_timedwait.c index b7de24c8..5ec307a6 100644 --- a/libpthread/pthread_cond_timedwait.c++ +++ b/libc/pthread/pthread_cond_timedwait.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_timedwait.c++ + pthread/pthread_cond_timedwait.c Waits on a condition or until a timeout happens. *******************************************************************************/ @@ -29,7 +29,6 @@ #include #include -extern "C" int pthread_cond_timedwait(pthread_cond_t* restrict cond, pthread_mutex_t* restrict mutex, const struct timespec* restrict abstime) diff --git a/libpthread/pthread_cond_wait.c++ b/libc/pthread/pthread_cond_wait.c similarity index 68% rename from libpthread/pthread_cond_wait.c++ rename to libc/pthread/pthread_cond_wait.c index 70457ec1..8fa2d3a1 100644 --- a/libpthread/pthread_cond_wait.c++ +++ b/libc/pthread/pthread_cond_wait.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_cond_wait.c++ + pthread/pthread_cond_wait.c Waits on a condition. *******************************************************************************/ @@ -28,7 +28,6 @@ #include #include -extern "C" int pthread_cond_wait(pthread_cond_t* restrict cond, pthread_mutex_t* restrict mutex) { diff --git a/libpthread/pthread_condattr_destroy.c++ b/libc/pthread/pthread_condattr_destroy.c similarity index 51% rename from libpthread/pthread_condattr_destroy.c++ rename to libc/pthread/pthread_condattr_destroy.c index 9d349859..bdce058c 100644 --- a/libpthread/pthread_condattr_destroy.c++ +++ b/libc/pthread/pthread_condattr_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_condattr_destroy.c++ + pthread/pthread_condattr_destroy.c Destroys a condition variable attributes object. *******************************************************************************/ #include -extern "C" int pthread_condattr_destroy(pthread_condattr_t* /*attr*/) +int pthread_condattr_destroy(pthread_condattr_t* attr) { + (void) attr; return 0; } diff --git a/libpthread/pthread_condattr_getclock.c++ b/libc/pthread/pthread_condattr_getclock.c similarity index 60% rename from libpthread/pthread_condattr_getclock.c++ rename to libc/pthread/pthread_condattr_getclock.c index fc167a7c..ac348b55 100644 --- a/libpthread/pthread_condattr_getclock.c++ +++ b/libc/pthread/pthread_condattr_getclock.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_condattr_getclock.c++ + pthread/pthread_condattr_getclock.c Gets the requested clock in a cond attribute object. *******************************************************************************/ #include -extern "C" int pthread_condattr_getclock(const pthread_condattr_t* restrict attr, clockid_t* restrict clock) { diff --git a/libpthread/pthread_condattr_init.c++ b/libc/pthread/pthread_condattr_init.c similarity index 56% rename from libpthread/pthread_condattr_init.c++ rename to libc/pthread/pthread_condattr_init.c index f2ba725a..67840c47 100644 --- a/libpthread/pthread_condattr_init.c++ +++ b/libc/pthread/pthread_condattr_init.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_condattr_init.c++ + pthread/pthread_condattr_init.c Initialize a condition variable attributes object. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int pthread_condattr_init(pthread_condattr_t* attr) +int pthread_condattr_init(pthread_condattr_t* attr) { memset(attr, 0, sizeof(*attr)); attr->clock = CLOCK_REALTIME; diff --git a/libpthread/pthread_condattr_setclock.c++ b/libc/pthread/pthread_condattr_setclock.c similarity index 58% rename from libpthread/pthread_condattr_setclock.c++ rename to libc/pthread/pthread_condattr_setclock.c index c2442528..cb46fafa 100644 --- a/libpthread/pthread_condattr_setclock.c++ +++ b/libc/pthread/pthread_condattr_setclock.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_condattr_setclock.c++ + pthread/pthread_condattr_setclock.c Sets the requested clock in a cond attribute object. *******************************************************************************/ #include -extern "C" int pthread_condattr_setclock(pthread_condattr_t* attr, clockid_t clock) { return attr->clock = clock, 0; diff --git a/libpthread/pthread_create.c++ b/libc/pthread/pthread_create.c similarity index 76% rename from libpthread/pthread_create.c++ rename to libc/pthread/pthread_create.c index ea7a79c3..525ef91b 100644 --- a/libpthread/pthread_create.c++ +++ b/libc/pthread/pthread_create.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_create.c++ + pthread/pthread_create.c Creates a new thread. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -47,27 +48,27 @@ static void pthread_entrance(struct pthread* thread) } #if defined(__i386__) || defined(__x86_64__) -const unsigned long FLAGS_CARRY = 1 << 0; // 0x000001 -const unsigned long FLAGS_RESERVED1 = 1 << 1; // 0x000002, read as one -const unsigned long FLAGS_PARITY = 1 << 2; // 0x000004 -const unsigned long FLAGS_RESERVED2 = 1 << 3; // 0x000008 -const unsigned long FLAGS_AUX = 1 << 4; // 0x000010 -const unsigned long FLAGS_RESERVED3 = 1 << 5; // 0x000020 -const unsigned long FLAGS_ZERO = 1 << 6; // 0x000040 -const unsigned long FLAGS_SIGN = 1 << 7; // 0x000080 -const unsigned long FLAGS_TRAP = 1 << 8; // 0x000100 -const unsigned long FLAGS_INTERRUPT = 1 << 9; // 0x000200 -const unsigned long FLAGS_DIRECTION = 1 << 10; // 0x000400 -const unsigned long FLAGS_OVERFLOW = 1 << 11; // 0x000800 -const unsigned long FLAGS_IOPRIVLEVEL = 1 << 12 | 1 << 13; -const unsigned long FLAGS_NESTEDTASK = 1 << 14; // 0x004000 -const unsigned long FLAGS_RESERVED4 = 1 << 15; // 0x008000 -const unsigned long FLAGS_RESUME = 1 << 16; // 0x010000 -const unsigned long FLAGS_VIRTUAL8086 = 1 << 17; // 0x020000 -const unsigned long FLAGS_ALIGNCHECK = 1 << 18; // 0x040000 -const unsigned long FLAGS_VIRTINTR = 1 << 19; // 0x080000 -const unsigned long FLAGS_VIRTINTRPEND = 1 << 20; // 0x100000 -const unsigned long FLAGS_ID = 1 << 21; // 0x200000 +static const unsigned long FLAGS_CARRY = 1 << 0; // 0x000001 +static const unsigned long FLAGS_RESERVED1 = 1 << 1; // 0x000002, read as one +static const unsigned long FLAGS_PARITY = 1 << 2; // 0x000004 +static const unsigned long FLAGS_RESERVED2 = 1 << 3; // 0x000008 +static const unsigned long FLAGS_AUX = 1 << 4; // 0x000010 +static const unsigned long FLAGS_RESERVED3 = 1 << 5; // 0x000020 +static const unsigned long FLAGS_ZERO = 1 << 6; // 0x000040 +static const unsigned long FLAGS_SIGN = 1 << 7; // 0x000080 +static const unsigned long FLAGS_TRAP = 1 << 8; // 0x000100 +static const unsigned long FLAGS_INTERRUPT = 1 << 9; // 0x000200 +static const unsigned long FLAGS_DIRECTION = 1 << 10; // 0x000400 +static const unsigned long FLAGS_OVERFLOW = 1 << 11; // 0x000800 +static const unsigned long FLAGS_IOPRIVLEVEL = 1 << 12 | 1 << 13; +static const unsigned long FLAGS_NESTEDTASK = 1 << 14; // 0x004000 +static const unsigned long FLAGS_RESERVED4 = 1 << 15; // 0x008000 +static const unsigned long FLAGS_RESUME = 1 << 16; // 0x010000 +static const unsigned long FLAGS_VIRTUAL8086 = 1 << 17; // 0x020000 +static const unsigned long FLAGS_ALIGNCHECK = 1 << 18; // 0x040000 +static const unsigned long FLAGS_VIRTINTR = 1 << 19; // 0x080000 +static const unsigned long FLAGS_VIRTINTRPEND = 1 << 20; // 0x100000 +static const unsigned long FLAGS_ID = 1 << 21; // 0x200000 #endif #if defined(__i386__) @@ -122,7 +123,6 @@ static void setup_thread_state(struct pthread* thread, struct tfork* regs) } #endif -extern "C" int pthread_create(pthread_t* restrict thread_ptr, const pthread_attr_t* restrict attr, void* (*entry_function)(void*), @@ -198,11 +198,11 @@ int pthread_create(pthread_t* restrict thread_ptr, thread->uthread.tls_size = tls_size; thread->uthread.arg_mmap = self->uthread.arg_mmap; thread->uthread.arg_size = self->uthread.arg_size; - thread->join_lock = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; + thread->join_lock = (pthread_mutex_t) PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; thread->join_lock.lock = 1 /* LOCKED_VALUE */; thread->join_lock.type = PTHREAD_MUTEX_NORMAL; thread->join_lock.owner = (unsigned long) thread; - thread->detach_lock = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; + thread->detach_lock = (pthread_mutex_t) PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; thread->detach_state = attr->detach_state; thread->entry_function = entry_function; thread->entry_cookie = entry_cookie; diff --git a/libpthread/pthread_detach.c++ b/libc/pthread/pthread_detach.c similarity index 61% rename from libpthread/pthread_detach.c++ rename to libc/pthread/pthread_detach.c index 4d6e47fa..c224b904 100644 --- a/libpthread/pthread_detach.c++ +++ b/libc/pthread/pthread_detach.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_detach.c++ + pthread/pthread_detach.c Detach a thread. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int pthread_detach(pthread_t thread) +int pthread_detach(pthread_t thread) { if ( pthread_mutex_trylock(&thread->detach_lock) != 0 ) return pthread_join(thread, NULL); diff --git a/libpthread/pthread_equal.c++ b/libc/pthread/pthread_equal.c similarity index 53% rename from libpthread/pthread_equal.c++ rename to libc/pthread/pthread_equal.c index 204174a2..42d77eb2 100644 --- a/libpthread/pthread_equal.c++ +++ b/libc/pthread/pthread_equal.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_equal.c++ + pthread/pthread_equal.c Compares thread identities. *******************************************************************************/ #include -extern "C" int pthread_equal(pthread_t t1, pthread_t t2) +int pthread_equal(pthread_t t1, pthread_t t2) { return t1 == t2 ? 1 : 0; } diff --git a/libpthread/pthread_exit.c++ b/libc/pthread/pthread_exit.c similarity index 80% rename from libpthread/pthread_exit.c++ rename to libc/pthread/pthread_exit.c index 8ae159e2..fddd00ec 100644 --- a/libpthread/pthread_exit.c++ +++ b/libc/pthread/pthread_exit.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_exit.c++ + pthread/pthread_exit.c Exits the current thread. *******************************************************************************/ @@ -25,11 +25,11 @@ #include #include +#include #include #include #include -extern "C" __attribute__((__noreturn__)) void pthread_exit(void* return_value) { diff --git a/libpthread/pthread_getspecific.c++ b/libc/pthread/pthread_getspecific.c similarity index 62% rename from libpthread/pthread_getspecific.c++ rename to libc/pthread/pthread_getspecific.c index e2657397..d5403381 100644 --- a/libpthread/pthread_getspecific.c++ +++ b/libc/pthread/pthread_getspecific.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_getspecific.c++ + pthread/pthread_getspecific.c Thread-specific data management. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void* pthread_getspecific(pthread_key_t key) +void* pthread_getspecific(pthread_key_t key) { struct pthread* thread = pthread_self(); diff --git a/libpthread/pthread_join.c++ b/libc/pthread/pthread_join.c similarity index 62% rename from libpthread/pthread_join.c++ rename to libc/pthread/pthread_join.c index a57f2be1..8cb481a0 100644 --- a/libpthread/pthread_join.c++ +++ b/libc/pthread/pthread_join.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_join.c++ + pthread/pthread_join.c Wait for thread termination. *******************************************************************************/ @@ -28,7 +28,7 @@ #include #include -extern "C" int pthread_join(pthread_t thread, void** result_ptr) +int pthread_join(pthread_t thread, void** result_ptr) { pthread_mutex_lock(&thread->join_lock); pthread_mutex_unlock(&thread->join_lock); diff --git a/libpthread/pthread_key_create.c++ b/libc/pthread/pthread_key_create.c similarity index 75% rename from libpthread/pthread_key_create.c++ rename to libc/pthread/pthread_key_create.c index 5fa513d3..445197a6 100644 --- a/libpthread/pthread_key_create.c++ +++ b/libc/pthread/pthread_key_create.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_key_create.c++ + pthread/pthread_key_create.c Thread-specific data key creation. *******************************************************************************/ @@ -26,11 +26,11 @@ #include #include -static void noop_destructor(void*) +static void noop_destructor(void* ctx) { + (void) ctx; } -extern "C" int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)) { if ( !destructor ) diff --git a/libpthread/pthread_key_delete.c++ b/libc/pthread/pthread_key_delete.c similarity index 61% rename from libpthread/pthread_key_delete.c++ rename to libc/pthread/pthread_key_delete.c index d0538867..213a26a9 100644 --- a/libpthread/pthread_key_delete.c++ +++ b/libc/pthread/pthread_key_delete.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_key_delete.c++ + pthread/pthread_key_delete.c Thread-specific data key deletion. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int pthread_key_delete(pthread_key_t key) +int pthread_key_delete(pthread_key_t key) { pthread_mutex_lock(&__pthread_keys_lock); diff --git a/libc/pthread/pthread_keys.c b/libc/pthread/pthread_keys.c new file mode 100644 index 00000000..e6f84ec1 --- /dev/null +++ b/libc/pthread/pthread_keys.c @@ -0,0 +1,31 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + pthread/pthread_keys.c + pthread_keys global variables. + +*******************************************************************************/ + +#include +#include + +pthread_mutex_t __pthread_keys_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +struct pthread_key* __pthread_keys = NULL; +size_t __pthread_keys_used = 0; +size_t __pthread_keys_length = 0; diff --git a/libpthread/pthread_mutex_destroy.c++ b/libc/pthread/pthread_mutex_destroy.c similarity index 50% rename from libpthread/pthread_mutex_destroy.c++ rename to libc/pthread/pthread_mutex_destroy.c index 6bf032f1..fa299d4e 100644 --- a/libpthread/pthread_mutex_destroy.c++ +++ b/libc/pthread/pthread_mutex_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutex_destroy.c++ + pthread/pthread_mutex_destroy.c Destroys a mutex. *******************************************************************************/ #include -extern "C" int pthread_mutex_destroy(pthread_mutex_t* /*mutex*/) +int pthread_mutex_destroy(pthread_mutex_t* mutex) { + (void) mutex; return 0; } diff --git a/libpthread/pthread_mutex_init.c++ b/libc/pthread/pthread_mutex_init.c similarity index 65% rename from libpthread/pthread_mutex_init.c++ rename to libc/pthread/pthread_mutex_init.c index 60a69cc8..9bf67aa9 100644 --- a/libpthread/pthread_mutex_init.c++ +++ b/libc/pthread/pthread_mutex_init.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutex_init.c++ + pthread/pthread_mutex_init.c Initializes a mutex. *******************************************************************************/ #include -extern "C" int pthread_mutex_init(pthread_mutex_t* restrict mutex, const pthread_mutexattr_t* restrict attr) { diff --git a/libpthread/pthread_mutex_lock.c++ b/libc/pthread/pthread_mutex_lock.c similarity index 66% rename from libpthread/pthread_mutex_lock.c++ rename to libc/pthread/pthread_mutex_lock.c index 5605a22d..48e1d40c 100644 --- a/libpthread/pthread_mutex_lock.c++ +++ b/libc/pthread/pthread_mutex_lock.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutex_lock.c++ + pthread/pthread_mutex_lock.c Locks a mutex. *******************************************************************************/ @@ -30,7 +30,7 @@ static const unsigned long UNLOCKED_VALUE = 0; static const unsigned long LOCKED_VALUE = 1; -extern "C" int pthread_mutex_lock(pthread_mutex_t* mutex) +int pthread_mutex_lock(pthread_mutex_t* mutex) { while ( !__sync_bool_compare_and_swap(&mutex->lock, UNLOCKED_VALUE, LOCKED_VALUE) ) { diff --git a/libpthread/pthread_mutex_trylock.c++ b/libc/pthread/pthread_mutex_trylock.c similarity index 65% rename from libpthread/pthread_mutex_trylock.c++ rename to libc/pthread/pthread_mutex_trylock.c index 062de9ce..7bd5fad2 100644 --- a/libpthread/pthread_mutex_trylock.c++ +++ b/libc/pthread/pthread_mutex_trylock.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutex_trylock.c++ + pthread/pthread_mutex_trylock.c Attempts to lock a mutex. *******************************************************************************/ @@ -28,7 +28,7 @@ static const unsigned long UNLOCKED_VALUE = 0; static const unsigned long LOCKED_VALUE = 1; -extern "C" int pthread_mutex_trylock(pthread_mutex_t* mutex) +int pthread_mutex_trylock(pthread_mutex_t* mutex) { if ( !__sync_bool_compare_and_swap(&mutex->lock, UNLOCKED_VALUE, LOCKED_VALUE) ) { diff --git a/libpthread/pthread_mutex_unlock.c++ b/libc/pthread/pthread_mutex_unlock.c similarity index 60% rename from libpthread/pthread_mutex_unlock.c++ rename to libc/pthread/pthread_mutex_unlock.c index eb02a75a..36961526 100644 --- a/libpthread/pthread_mutex_unlock.c++ +++ b/libc/pthread/pthread_mutex_unlock.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutex_unlock.c++ + pthread/pthread_mutex_unlock.c Unlocks a mutex. *******************************************************************************/ @@ -27,7 +27,7 @@ static const unsigned long UNLOCKED_VALUE = 0; static const unsigned long LOCKED_VALUE = 1; -extern "C" int pthread_mutex_unlock(pthread_mutex_t* mutex) +int pthread_mutex_unlock(pthread_mutex_t* mutex) { if ( mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->recursion ) return mutex->recursion--, 0; diff --git a/libpthread/pthread_mutexattr_destroy.c++ b/libc/pthread/pthread_mutexattr_destroy.c similarity index 51% rename from libpthread/pthread_mutexattr_destroy.c++ rename to libc/pthread/pthread_mutexattr_destroy.c index 0df7d363..373c4c0a 100644 --- a/libpthread/pthread_mutexattr_destroy.c++ +++ b/libc/pthread/pthread_mutexattr_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutexattr_destroy.c++ + pthread/pthread_mutexattr_destroy.c Destroys a mutex attributes object. *******************************************************************************/ #include -extern "C" int pthread_mutexattr_destroy(pthread_mutexattr_t* /*attr*/) +int pthread_mutexattr_destroy(pthread_mutexattr_t* attr) { + (void) attr; return 0; } diff --git a/libpthread/pthread_mutexattr_gettype.c++ b/libc/pthread/pthread_mutexattr_gettype.c similarity index 60% rename from libpthread/pthread_mutexattr_gettype.c++ rename to libc/pthread/pthread_mutexattr_gettype.c index d14e8f98..f0fb906f 100644 --- a/libpthread/pthread_mutexattr_gettype.c++ +++ b/libc/pthread/pthread_mutexattr_gettype.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutexattr_gettype.c++ + pthread/pthread_mutexattr_gettype.c Gets the requested mutex type in a mutex attribute object. *******************************************************************************/ #include -extern "C" int pthread_mutexattr_gettype(pthread_mutexattr_t* restrict attr, int* restrict type) { diff --git a/libpthread/pthread_mutexattr_init.c++ b/libc/pthread/pthread_mutexattr_init.c similarity index 55% rename from libpthread/pthread_mutexattr_init.c++ rename to libc/pthread/pthread_mutexattr_init.c index dad9ecd2..f728f755 100644 --- a/libpthread/pthread_mutexattr_init.c++ +++ b/libc/pthread/pthread_mutexattr_init.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutexattr_init.c++ + pthread/pthread_mutexattr_init.c Initialize a mutex attributes object. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int pthread_mutexattr_init(pthread_mutexattr_t* attr) +int pthread_mutexattr_init(pthread_mutexattr_t* attr) { memset(attr, 0, sizeof(*attr)); attr->type = PTHREAD_MUTEX_DEFAULT; diff --git a/libpthread/pthread_mutexattr_settype.c++ b/libc/pthread/pthread_mutexattr_settype.c similarity index 53% rename from libpthread/pthread_mutexattr_settype.c++ rename to libc/pthread/pthread_mutexattr_settype.c index eeff1488..8aea5d6b 100644 --- a/libpthread/pthread_mutexattr_settype.c++ +++ b/libc/pthread/pthread_mutexattr_settype.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_mutexattr_settype.c++ + pthread/pthread_mutexattr_settype.c Sets the requested mutex type in a mutex attribute object. *******************************************************************************/ #include -extern "C" int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type) +int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type) { return attr->type = type, 0; } diff --git a/libpthread/pthread_once.c++ b/libc/pthread/pthread_once.c similarity index 69% rename from libpthread/pthread_once.c++ rename to libc/pthread/pthread_once.c index f8bb10cd..d6733a28 100644 --- a/libpthread/pthread_once.c++ +++ b/libc/pthread/pthread_once.c @@ -2,29 +2,28 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_once.c++ + pthread/pthread_once.c Dynamic package initialization. *******************************************************************************/ #include -extern "C" int pthread_once(pthread_once_t* once_control, void (*init_routine)(void)) { pthread_mutex_lock(&once_control->lock); diff --git a/libpthread/pthread_rwlock_destroy.c++ b/libc/pthread/pthread_rwlock_destroy.c similarity index 51% rename from libpthread/pthread_rwlock_destroy.c++ rename to libc/pthread/pthread_rwlock_destroy.c index 53027548..ed5acd1e 100644 --- a/libpthread/pthread_rwlock_destroy.c++ +++ b/libc/pthread/pthread_rwlock_destroy.c @@ -2,29 +2,30 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_destroy.c++ + pthread/pthread_rwlock_destroy.c Destroys a read-write lock. *******************************************************************************/ #include -extern "C" int pthread_rwlock_destroy(pthread_rwlock_t* /*rwlock*/) +int pthread_rwlock_destroy(pthread_rwlock_t* rwlock) { + (void) rwlock; return 0; } diff --git a/libpthread/pthread_rwlock_init.c++ b/libc/pthread/pthread_rwlock_init.c similarity index 50% rename from libpthread/pthread_rwlock_init.c++ rename to libc/pthread/pthread_rwlock_init.c index 8be27cbc..312dcea8 100644 --- a/libpthread/pthread_rwlock_init.c++ +++ b/libc/pthread/pthread_rwlock_init.c @@ -2,32 +2,32 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_init.c++ + pthread/pthread_rwlock_init.c Initializes a read-write lock. *******************************************************************************/ #include -extern "C" int pthread_rwlock_init(pthread_rwlock_t* restrict rwlock, - const pthread_rwlockattr_t* restrict /*attr*/) + const pthread_rwlockattr_t* restrict attr) { - *rwlock = PTHREAD_RWLOCK_INITIALIZER; + (void) attr; + *rwlock = (pthread_rwlock_t) PTHREAD_RWLOCK_INITIALIZER; return 0; } diff --git a/libpthread/pthread_rwlock_rdlock.c++ b/libc/pthread/pthread_rwlock_rdlock.c similarity index 62% rename from libpthread/pthread_rwlock_rdlock.c++ rename to libc/pthread/pthread_rwlock_rdlock.c index 146f31ea..2b400e86 100644 --- a/libpthread/pthread_rwlock_rdlock.c++ +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_rdlock.c++ + pthread/pthread_rwlock_rdlock.c Acquires read access to a read-write lock. *******************************************************************************/ #include -extern "C" int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) +int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) { pthread_mutex_lock(&rwlock->request_mutex); rwlock->pending_readers++; diff --git a/libpthread/pthread_rwlock_tryrdlock.c++ b/libc/pthread/pthread_rwlock_tryrdlock.c similarity index 58% rename from libpthread/pthread_rwlock_tryrdlock.c++ rename to libc/pthread/pthread_rwlock_tryrdlock.c index 6074a83a..564c4809 100644 --- a/libpthread/pthread_rwlock_tryrdlock.c++ +++ b/libc/pthread/pthread_rwlock_tryrdlock.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_tryrdlock.c++ + pthread/pthread_rwlock_tryrdlock.c Attempts to acquire read access to a read-write lock. *******************************************************************************/ @@ -25,9 +25,10 @@ #include #include -extern "C" int pthread_rwlock_tryrdlock(pthread_rwlock_t* rwlock) +int pthread_rwlock_tryrdlock(pthread_rwlock_t* rwlock) { - if ( int ret = pthread_mutex_trylock(&rwlock->request_mutex) ) + int ret; + if ( (ret = pthread_mutex_trylock(&rwlock->request_mutex)) ) return errno = ret; while ( rwlock->num_writers || rwlock->pending_writers ) { diff --git a/libpthread/pthread_rwlock_trywrlock.c++ b/libc/pthread/pthread_rwlock_trywrlock.c similarity index 58% rename from libpthread/pthread_rwlock_trywrlock.c++ rename to libc/pthread/pthread_rwlock_trywrlock.c index 8d06b9c4..4bcfd502 100644 --- a/libpthread/pthread_rwlock_trywrlock.c++ +++ b/libc/pthread/pthread_rwlock_trywrlock.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_trywrlock.c++ + pthread/pthread_rwlock_trywrlock.c Attempts to acquire write access to a read-write lock. *******************************************************************************/ @@ -25,9 +25,10 @@ #include #include -extern "C" int pthread_rwlock_trywrlock(pthread_rwlock_t* rwlock) +int pthread_rwlock_trywrlock(pthread_rwlock_t* rwlock) { - if ( int ret = pthread_mutex_trylock(&rwlock->request_mutex) ) + int ret; + if ( (ret = pthread_mutex_trylock(&rwlock->request_mutex)) ) return errno = ret; if ( rwlock->num_readers || rwlock->num_writers ) { diff --git a/libpthread/pthread_rwlock_unlock.c++ b/libc/pthread/pthread_rwlock_unlock.c similarity index 65% rename from libpthread/pthread_rwlock_unlock.c++ rename to libc/pthread/pthread_rwlock_unlock.c index 2ad5fbed..3ba72053 100644 --- a/libpthread/pthread_rwlock_unlock.c++ +++ b/libc/pthread/pthread_rwlock_unlock.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_unlock.c++ + pthread/pthread_rwlock_unlock.c Releases hold of a read-write lock. *******************************************************************************/ #include -extern "C" int pthread_rwlock_unlock(pthread_rwlock_t* rwlock) +int pthread_rwlock_unlock(pthread_rwlock_t* rwlock) { pthread_mutex_lock(&rwlock->request_mutex); if ( rwlock->num_writers ) diff --git a/libpthread/pthread_rwlock_wrlock.c++ b/libc/pthread/pthread_rwlock_wrlock.c similarity index 62% rename from libpthread/pthread_rwlock_wrlock.c++ rename to libc/pthread/pthread_rwlock_wrlock.c index bf36d14c..65d864b4 100644 --- a/libpthread/pthread_rwlock_wrlock.c++ +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlock_wrlock.c++ + pthread/pthread_rwlock_wrlock.c Acquires write access to a read-write lock. *******************************************************************************/ #include -extern "C" int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) +int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) { pthread_mutex_lock(&rwlock->request_mutex); rwlock->pending_writers++; diff --git a/libpthread/pthread_rwlockattr_destroy.c++ b/libc/pthread/pthread_rwlockattr_destroy.c similarity index 52% rename from libpthread/pthread_rwlockattr_destroy.c++ rename to libc/pthread/pthread_rwlockattr_destroy.c index 77038121..bb564892 100644 --- a/libpthread/pthread_rwlockattr_destroy.c++ +++ b/libc/pthread/pthread_rwlockattr_destroy.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlockattr_destroy.c++ + pthread/pthread_rwlockattr_destroy.c Destroys a read-write lock attributes object. *******************************************************************************/ #include -extern "C" int pthread_rwlockattr_destroy(pthread_rwlockattr_t* /*attr*/) +int pthread_rwlockattr_destroy(pthread_rwlockattr_t* attr) { return 0; } diff --git a/libpthread/pthread_rwlockattr_init.c++ b/libc/pthread/pthread_rwlockattr_init.c similarity index 54% rename from libpthread/pthread_rwlockattr_init.c++ rename to libc/pthread/pthread_rwlockattr_init.c index ec5072d2..5bf5805f 100644 --- a/libpthread/pthread_rwlockattr_init.c++ +++ b/libc/pthread/pthread_rwlockattr_init.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_rwlockattr_init.c++ + pthread/pthread_rwlockattr_init.c Initialize a read-write lock attributes object. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int pthread_rwlockattr_init(pthread_rwlockattr_t* attr) +int pthread_rwlockattr_init(pthread_rwlockattr_t* attr) { memset(attr, 0, sizeof(*attr)); return 0; diff --git a/libpthread/pthread_self.c++ b/libc/pthread/pthread_self.c similarity index 62% rename from libpthread/pthread_self.c++ rename to libc/pthread/pthread_self.c index 9d381b79..4bc92694 100644 --- a/libpthread/pthread_self.c++ +++ b/libc/pthread/pthread_self.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2013. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_self.c++ + pthread/pthread_self.c Returns the identity of the current thread. *******************************************************************************/ #include -extern "C" pthread_t pthread_self(void) +pthread_t pthread_self(void) { pthread_t current_thread; #if defined(__i386__) diff --git a/libpthread/pthread_setspecific.c++ b/libc/pthread/pthread_setspecific.c similarity index 71% rename from libpthread/pthread_setspecific.c++ rename to libc/pthread/pthread_setspecific.c index a1af4c8a..936f7991 100644 --- a/libpthread/pthread_setspecific.c++ +++ b/libc/pthread/pthread_setspecific.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_setspecific.c++ + pthread/pthread_setspecific.c Thread-specific data management. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int pthread_setspecific(pthread_key_t key, const void* value_const) +int pthread_setspecific(pthread_key_t key, const void* value_const) { void* value = (void*) value_const; diff --git a/libpthread/sem_destroy.c++ b/libc/semaphore/sem_destroy.c similarity index 53% rename from libpthread/sem_destroy.c++ rename to libc/semaphore/sem_destroy.c index 9cfc9634..6b832e5d 100644 --- a/libpthread/sem_destroy.c++ +++ b/libc/semaphore/sem_destroy.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_destroy.c++ + semaphore/sem_destroy.c Destroy a semaphore. *******************************************************************************/ #include -extern "C" int sem_destroy(sem_t* sem) +int sem_destroy(sem_t* sem) { (void) sem; return 0; diff --git a/libpthread/sem_getvalue.c++ b/libc/semaphore/sem_getvalue.c similarity index 54% rename from libpthread/sem_getvalue.c++ rename to libc/semaphore/sem_getvalue.c index 6f37d5d2..97acfeb1 100644 --- a/libpthread/sem_getvalue.c++ +++ b/libc/semaphore/sem_getvalue.c @@ -2,29 +2,29 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_getvalue.c++ + semaphore/sem_getvalue.c Get the value of a semaphore. *******************************************************************************/ #include -extern "C" int sem_getvalue(sem_t* restrict sem, int* restrict value_ptr) +int sem_getvalue(sem_t* restrict sem, int* restrict value_ptr) { *value_ptr = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST); return 0; diff --git a/libpthread/sem_init.c++ b/libc/semaphore/sem_init.c similarity index 58% rename from libpthread/sem_init.c++ rename to libc/semaphore/sem_init.c index e25d3983..252b9517 100644 --- a/libpthread/sem_init.c++ +++ b/libc/semaphore/sem_init.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_init.c++ + semaphore/sem_init.c Initialize a semaphore. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int sem_init(sem_t* sem, int pshared, unsigned int value) +int sem_init(sem_t* sem, int pshared, unsigned int value) { if ( pshared ) return errno = ENOSYS, -1; diff --git a/libpthread/sem_post.c++ b/libc/semaphore/sem_post.c similarity index 65% rename from libpthread/sem_post.c++ rename to libc/semaphore/sem_post.c index 2d3fc302..5f4788cd 100644 --- a/libpthread/sem_post.c++ +++ b/libc/semaphore/sem_post.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_post.c++ + semaphore/sem_post.c Unlock a semaphore. *******************************************************************************/ @@ -25,8 +25,9 @@ #include #include #include +#include -extern "C" int sem_post(sem_t* sem) +int sem_post(sem_t* sem) { while ( true ) { diff --git a/libpthread/sem_timedwait.c++ b/libc/semaphore/sem_timedwait.c similarity index 77% rename from libpthread/sem_timedwait.c++ rename to libc/semaphore/sem_timedwait.c index dda967c9..b6b5c5d8 100644 --- a/libpthread/sem_timedwait.c++ +++ b/libc/semaphore/sem_timedwait.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_timedwait.c++ + semaphore/sem_timedwait.c Lock a semaphore. *******************************************************************************/ @@ -30,7 +30,6 @@ #include #include -extern "C" int sem_timedwait(sem_t* restrict sem, const struct timespec* restrict abstime) { if ( sem_trywait(sem) == 0 ) diff --git a/libpthread/sem_trywait.c++ b/libc/semaphore/sem_trywait.c similarity index 63% rename from libpthread/sem_trywait.c++ rename to libc/semaphore/sem_trywait.c index b247d0e4..93167318 100644 --- a/libpthread/sem_trywait.c++ +++ b/libc/semaphore/sem_trywait.c @@ -2,30 +2,31 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_trywait.c++ + semaphore/sem_trywait.c Lock a semaphore. *******************************************************************************/ #include #include +#include -extern "C" int sem_trywait(sem_t* sem) +int sem_trywait(sem_t* sem) { int old_value = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST); if ( old_value <= 0 ) diff --git a/libpthread/sem_wait.c++ b/libc/semaphore/sem_wait.c similarity index 70% rename from libpthread/sem_wait.c++ rename to libc/semaphore/sem_wait.c index 3de9ecf1..4321e694 100644 --- a/libpthread/sem_wait.c++ +++ b/libc/semaphore/sem_wait.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - sem_wait.c++ + semaphore/sem_wait.c Lock a semaphore. *******************************************************************************/ @@ -28,7 +28,7 @@ #include #include -extern "C" int sem_wait(sem_t* sem) +int sem_wait(sem_t* sem) { if ( sem_trywait(sem) == 0 ) return 0; diff --git a/libpthread/pthread_sigmask.c++ b/libc/signal/pthread_sigmask.c similarity index 62% rename from libpthread/pthread_sigmask.c++ rename to libc/signal/pthread_sigmask.c index e5fdb44e..659c5a99 100644 --- a/libpthread/pthread_sigmask.c++ +++ b/libc/signal/pthread_sigmask.c @@ -2,22 +2,22 @@ Copyright(C) Jonas 'Sortie' Termansen 2014. - This file is part of Sortix libpthread. + This file is part of the Sortix C Library. - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Sortix libpthread is distributed in the hope that it will be useful, but + The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . + along with the Sortix C Library. If not, see . - pthread_sigmask.c++ + signal/pthread_sigmask.c Examine and change blocked signals. *******************************************************************************/ @@ -26,7 +26,6 @@ #include #include -extern "C" int pthread_sigmask(int how, const sigset_t* restrict set, sigset_t* restrict oldset) diff --git a/libpthread/.gitignore b/libpthread/.gitignore deleted file mode 100644 index 9eca6c88..00000000 --- a/libpthread/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.a -*.o diff --git a/libpthread/Makefile b/libpthread/Makefile deleted file mode 100644 index b48b0038..00000000 --- a/libpthread/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -SOFTWARE_MEANT_FOR_SORTIX=1 -include ../build-aux/platform.mak -include ../build-aux/compiler.mak -include ../build-aux/version.mak -include ../build-aux/dirs.mak - -OPTLEVEL?=$(DEFAULT_OPTLEVEL) -CXXFLAGS?=$(OPTLEVEL) -CPPFLAGS?= - -CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libpthread -I include -CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti - -OBJS=\ -pthread_attr_destroy.o \ -pthread_attr_getdetachstate.o \ -pthread_attr_getstacksize.o \ -pthread_attr_init.o \ -pthread_attr_setdetachstate.o \ -pthread_attr_setstacksize.o \ -pthread_condattr_destroy.o \ -pthread_condattr_getclock.o \ -pthread_condattr_init.o \ -pthread_condattr_setclock.o \ -pthread_cond_broadcast.o \ -pthread_cond_destroy.o \ -pthread_cond_init.o \ -pthread_cond_signal.o \ -pthread_cond_timedwait.o \ -pthread_cond_wait.o \ -pthread_create.o \ -pthread_detach.o \ -pthread_equal.o \ -pthread_exit.o \ -pthread_getspecific.o \ -pthread_initialize.o \ -pthread_join.o \ -pthread_key_create.o \ -pthread_key_delete.o \ -pthread_mutexattr_destroy.o \ -pthread_mutexattr_gettype.o \ -pthread_mutexattr_init.o \ -pthread_mutexattr_settype.o \ -pthread_mutex_destroy.o \ -pthread_mutex_init.o \ -pthread_mutex_lock.o \ -pthread_mutex_trylock.o \ -pthread_mutex_unlock.o \ -pthread_once.o \ -pthread_rwlock_destroy.o \ -pthread_rwlock_init.o \ -pthread_rwlock_rdlock.o \ -pthread_rwlock_tryrdlock.o \ -pthread_rwlock_trywrlock.o \ -pthread_rwlock_unlock.o \ -pthread_rwlock_wrlock.o \ -pthread_self.o \ -pthread_setspecific.o \ -pthread_sigmask.o \ -sem_destroy.o \ -sem_getvalue.o \ -sem_init.o \ -sem_post.o \ -sem_timedwait.o \ -sem_trywait.o \ -sem_wait.o \ - -BINS:=libpthread.a - -# Main build rules. -all: $(BINS) - -.PHONY: headers clean install install-headers libs install-libs - -headers: - -libs: $(BINS) - -libpthread.a: $(OBJS) - $(AR) rcs $@ $(OBJS) - -%.o: %.c++ - $(CXX) -std=gnu++11 -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS) - -clean: - rm -f $(BINS) $(OBJS) *.o - -# Installation into sysroot. -install: install-headers install-libs - -install-headers: headers - cp -RTv include $(DESTDIR)$(INCLUDEDIR) - -install-libs: - mkdir -p $(DESTDIR)$(LIBDIR) - cp -P libpthread.a $(DESTDIR)$(LIBDIR) diff --git a/libpthread/pthread_initialize.c++ b/libpthread/pthread_initialize.c++ deleted file mode 100644 index 81b985f2..00000000 --- a/libpthread/pthread_initialize.c++ +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. - - This file is part of Sortix libpthread. - - Sortix libpthread is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - Sortix libpthread is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with Sortix libpthread. If not, see . - - pthread_initialize.c++ - Prepares the process for pthread usage. - -*******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { pthread_mutex_t __pthread_keys_lock = - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; } -extern "C" { struct pthread_key* __pthread_keys = NULL; } -extern "C" { size_t __pthread_keys_used = 0; } -extern "C" { size_t __pthread_keys_length = 0; } - -// Emit an ELF note containing the size and alignment of struct pthread. -__attribute__((used)) -static void elf_note_sortix_pthread_size() -{ - asm volatile ( - ".pushsection .note.sortix,\"a\",@note\n\t" - ".align 4\n\t" - ".long 2f-1f\n\t" // namesz - ".long 4f-3f\n\t" // descsz - ".long %c0\n" // type - "1:\n\t" - ".string \"Sortix\"\n" // name - "2:\n\t" - ".align 4\n" - "3:\n\t" -#if defined(__x86_64__) - ".quad %c1\n" - ".quad %c2\n" -#elif defined(__i386__) - ".long %c1\n" - ".long %c2\n" -#endif - "4:\n\t" - ".align 4\n\t" - ".popsection\n\t" - :: "n"(ELF_NOTE_SORTIX_UTHREAD_SIZE), - "n"(sizeof(struct pthread)), - "n"(alignof(struct pthread)) - ); -} - -extern "C" void pthread_initialize(void) -{ - struct pthread* self = pthread_self(); - - self->join_lock = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; - self->join_lock.lock = 1 /* LOCKED_VALUE */; - self->join_lock.type = PTHREAD_MUTEX_NORMAL; - self->join_lock.owner = (unsigned long) self; - self->detach_lock = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP; - self->detach_state = PTHREAD_CREATE_JOINABLE; -}