mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add pthread_exit(3).
This commit is contained in:
parent
978aa68906
commit
094635b2c3
3 changed files with 49 additions and 1 deletions
|
@ -22,6 +22,7 @@ pthread_cond_signal.o \
|
|||
pthread_cond_timedwait.o \
|
||||
pthread_cond_wait.o \
|
||||
pthread_equal.o \
|
||||
pthread_exit.o \
|
||||
pthread_initialize.o \
|
||||
pthread_mutexattr_destroy.o \
|
||||
pthread_mutexattr_gettype.o \
|
||||
|
|
|
@ -209,7 +209,8 @@ int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
|
|||
/* TODO: pthread_create */
|
||||
/* TODO: pthread_detach */
|
||||
int pthread_equal(pthread_t, pthread_t);
|
||||
/* TODO: pthread_exit */
|
||||
__attribute__((__noreturn__))
|
||||
void pthread_exit(void*);
|
||||
/* TODO: pthread_getconcurrency */
|
||||
/* TODO: pthread_getcpuclockid */
|
||||
/* TODO: pthread_getschedparam */
|
||||
|
|
46
libpthread/pthread_exit.c++
Normal file
46
libpthread/pthread_exit.c++
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
pthread_exit.c++
|
||||
Exits the current thread.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C"
|
||||
__attribute__((__noreturn__))
|
||||
void pthread_exit(void* /*return_value*/)
|
||||
{
|
||||
struct pthread* thread = pthread_self();
|
||||
size_t num_threads = 1;
|
||||
if ( num_threads == 1 )
|
||||
exit(0);
|
||||
struct exit_thread extended;
|
||||
memset(&extended, 0, sizeof(extended));
|
||||
extended.unmap_from = thread->uthread.stack_mmap;
|
||||
extended.unmap_size = thread->uthread.stack_size;
|
||||
exit_thread(0, EXIT_THREAD_UNMAP, &extended);
|
||||
__builtin_unreachable();
|
||||
}
|
Loading…
Reference in a new issue