mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-29 15:44:02 +00:00
libc: implement '_spinlock()' and '_spinunlock()'
FreeBSD libc code uses only a single spinlock instance and, thus there is no obvious reason why it would need to be implemented as an actual spinlock. _spinlock() and _spinunlock() functions are implemented with a static pthread mutex. Issue #725
This commit is contained in:
parent
94bbdbb71d
commit
9aa0de24af
@ -19,7 +19,7 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \
|
||||
vfs_plugin.cc dynamic_linker.cc signal.cc \
|
||||
socket_operations.cc socket_fs_plugin.cc syscall.cc \
|
||||
getpwent.cc getrandom.cc fork.cc execve.cc kernel.cc component.cc \
|
||||
genode.cc
|
||||
genode.cc spinlock.cc
|
||||
|
||||
#
|
||||
# Pthreads
|
||||
|
@ -163,8 +163,6 @@ __SYS_DUMMY(int , -1, ptrace, (int, pid_t, caddr_t, int));
|
||||
__SYS_DUMMY(ssize_t, -1, sendmsg, (int s, const struct msghdr*, int));
|
||||
__SYS_DUMMY(int , -1, setcontext, (const ucontext_t *ucp));
|
||||
__SYS_DUMMY(void , , spinlock_stub, (spinlock_t *));
|
||||
__SYS_DUMMY(void , , spinlock, (spinlock_t *));
|
||||
__SYS_DUMMY(void , , spinunlock, (spinlock_t *));
|
||||
__SYS_DUMMY(void , , spinunlock_stub, (spinlock_t *));
|
||||
__SYS_DUMMY(int, -1, swapcontext, (ucontext_t *, const ucontext_t *));
|
||||
__SYS_DUMMY(int, -1, system, (const char *string));
|
||||
|
45
repos/libports/src/lib/libc/spinlock.cc
Normal file
45
repos/libports/src/lib/libc/spinlock.cc
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* \brief libc-internal spinlock implementation
|
||||
* \author Christian Prochaska
|
||||
* \date 2023-10-23
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <spinlock.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Only one spinlock ('__stdio_thread_lock') is
|
||||
* used in the FreeBSD libc code.
|
||||
*/
|
||||
|
||||
static pthread_mutex_t *stdio_thread_lock_mutex()
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
return &mutex;
|
||||
}
|
||||
|
||||
void _spinlock(spinlock_t *)
|
||||
{
|
||||
pthread_mutex_lock(stdio_thread_lock_mutex());
|
||||
}
|
||||
|
||||
typeof(_spinlock) __sys_spinlock
|
||||
__attribute__((alias("_spinlock")));
|
||||
|
||||
void _spinunlock(spinlock_t *)
|
||||
{
|
||||
pthread_mutex_unlock(stdio_thread_lock_mutex());
|
||||
}
|
||||
|
||||
typeof(_spinunlock) __sys_spinunlock
|
||||
__attribute__((alias("_spinunlock")));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user