mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 03:45:24 +00:00
Follow-up for spin-lock unification, ref #123
This commit is contained in:
parent
319813a59b
commit
e4cb3ed929
1
base-codezero/lib/import/import-syscall.mk
Normal file
1
base-codezero/lib/import/import-syscall.mk
Normal file
@ -0,0 +1 @@
|
||||
REP_INC_DIR += include/codezero/dummies
|
6
base-codezero/lib/mk/env.mk
Normal file
6
base-codezero/lib/mk/env.mk
Normal file
@ -0,0 +1,6 @@
|
||||
include $(BASE_DIR)/lib/mk/env.mk
|
||||
|
||||
SRC_CC += utcb.cc
|
||||
|
||||
vpath utcb.cc $(REP_DIR)/src/base/env
|
||||
vpath env.cc $(BASE_DIR)/src/base/env
|
40
base-codezero/src/base/env/utcb.cc
vendored
Normal file
40
base-codezero/src/base/env/utcb.cc
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* \brief Helper functions UTCB access on Codezero
|
||||
* \author Norman Feske
|
||||
* \date 2012-03-01
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/thread.h>
|
||||
|
||||
|
||||
/**
|
||||
* Resolve 'Thread_base::myself' when not linking the thread library
|
||||
*
|
||||
* This weak symbol is primarily used by test cases. Most other Genode programs
|
||||
* use the thread library. If the thread library is not used, 'myself' can only
|
||||
* be called by the main thread, for which 'myself' is defined as zero.
|
||||
*/
|
||||
Genode::Thread_base * __attribute__((weak)) Genode::Thread_base::myself() { return 0; }
|
||||
|
||||
|
||||
Genode::Native_utcb *Genode::Thread_base::utcb()
|
||||
{
|
||||
/*
|
||||
* If 'utcb' is called on the object returned by 'myself',
|
||||
* the 'this' pointer may be NULL (if the calling thread is
|
||||
* the main thread). Therefore we handle this special case
|
||||
* here.
|
||||
*/
|
||||
if (this == 0) return 0;
|
||||
|
||||
return &_context->utcb;
|
||||
}
|
||||
|
@ -22,30 +22,6 @@
|
||||
#include <codezero/syscalls.h>
|
||||
|
||||
|
||||
/**
|
||||
* Resolve 'Thread_base::myself' when not linking the thread library
|
||||
*
|
||||
* This weak symbol is primarily used by test cases. Most other Genode programs
|
||||
* use the thread library. If the thread library is not used, 'myself' can only
|
||||
* be called by the main thread, for which 'myself' is defined as zero.
|
||||
*/
|
||||
Genode::Thread_base * __attribute__((weak)) Genode::Thread_base::myself() { return 0; }
|
||||
|
||||
|
||||
Genode::Native_utcb *Genode::Thread_base::utcb()
|
||||
{
|
||||
/*
|
||||
* If 'utcb' is called on the object returned by 'myself',
|
||||
* the 'this' pointer may be NULL (if the calling thread is
|
||||
* the main thread). Therefore we handle this special case
|
||||
* here.
|
||||
*/
|
||||
if (this == 0) return 0;
|
||||
|
||||
return &_context->utcb;
|
||||
}
|
||||
|
||||
|
||||
static Codezero::l4_mutex main_running_lock = { -1 };
|
||||
|
||||
|
||||
@ -61,7 +37,7 @@ static inline bool thread_id_valid(Genode::Native_thread_id tid)
|
||||
}
|
||||
|
||||
|
||||
static bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
|
||||
static inline bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
|
||||
{
|
||||
if (!thread_id_valid(tid))
|
||||
return false;
|
||||
|
@ -29,7 +29,8 @@ SRC_CC = \
|
||||
core_rm_session.cc \
|
||||
core_mem_alloc.cc \
|
||||
dump_alloc.cc \
|
||||
context_area.cc
|
||||
context_area.cc \
|
||||
utcb.cc
|
||||
|
||||
INC_DIR = $(REP_DIR)/src/core/include \
|
||||
$(GEN_CORE_DIR)/include \
|
||||
@ -52,4 +53,5 @@ vpath context_area.cc $(GEN_CORE_DIR)
|
||||
vpath %.cc $(REP_DIR)/src/core
|
||||
vpath thread_bootstrap.cc $(BASE_DIR)/src/base/thread
|
||||
vpath thread.cc $(BASE_DIR)/src/base/thread
|
||||
vpath utcb.cc $(REP_DIR)/src/base/env
|
||||
|
||||
|
34
base-fiasco/src/base/lock/lock_helper.h
Normal file
34
base-fiasco/src/base/lock/lock_helper.h
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
/*
|
||||
* \brief L4/Fiasco-specific helper functions for the Lock implementation
|
||||
* \author Norman Feske
|
||||
* \date 2012-03-01
|
||||
*
|
||||
* L4/Fiasco is the only kernel that does not rely on Genode's generic lock
|
||||
* implementation. The custom implementation contained in 'lock.cc' does not
|
||||
* need 'lock_helper.h'. This file exists for the sole reason to make the
|
||||
* L4/Fiasco version of 'lock_helper' usable from the DDE Kit's spin lock.
|
||||
* Otherwise, we would need to add a special case for L4/Fiasco to the DDE Kit
|
||||
* library.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009-2012 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
/* L4/Fiasco includes */
|
||||
namespace Fiasco {
|
||||
#include <l4/sys/ipc.h>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Yield CPU time
|
||||
*/
|
||||
static inline void thread_yield()
|
||||
{
|
||||
Fiasco::l4_ipc_sleep(Fiasco::l4_ipc_timeout(0, 0, 500, 0));
|
||||
}
|
@ -24,8 +24,8 @@ namespace Pistachio {
|
||||
}
|
||||
|
||||
|
||||
bool operator == (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw == t2.raw; }
|
||||
bool operator != (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw != t2.raw; }
|
||||
static inline bool operator == (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw == t2.raw; }
|
||||
static inline bool operator != (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw != t2.raw; }
|
||||
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ static inline void thread_yield() { Pistachio::L4_Yield(); }
|
||||
*
|
||||
* \return true if the thread was in blocking state
|
||||
*/
|
||||
static bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
|
||||
static inline bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
|
||||
{
|
||||
using namespace Pistachio;
|
||||
|
||||
|
6
base/lib/mk/syscall.mk
Normal file
6
base/lib/mk/syscall.mk
Normal file
@ -0,0 +1,6 @@
|
||||
#
|
||||
# This file is placeholder to enable generic targets to specify the syscall
|
||||
# library at the 'LIBS' declaration, even on platforms where no such library
|
||||
# exists. This is done by DDE Kit for reusing the spinlock implementation of
|
||||
# the base repository.
|
||||
#
|
@ -19,6 +19,9 @@
|
||||
*/
|
||||
typedef volatile int dde_kit_spin_lock;
|
||||
|
||||
enum { DDE_KIT_SPIN_LOCK_LOCKED, DDE_KIT_SPIN_LOCK_UNLOCKED };
|
||||
|
||||
|
||||
/**
|
||||
* Initialize spin lock
|
||||
*
|
||||
|
@ -1,7 +1,17 @@
|
||||
SRC_C = lock.cc semaphore.cc panic.cc printf.cc interrupt.cc pgtab.cc \
|
||||
memory.cc thread.cc pci_tree.cc pci.cc resources.cc timer.cc \
|
||||
dde_kit.cc spin_lock.cc
|
||||
LIBS = thread alarm lock
|
||||
REP_INC_DIR += src/base/lock
|
||||
SRC_C = lock.cc semaphore.cc panic.cc printf.cc interrupt.cc pgtab.cc \
|
||||
memory.cc thread.cc pci_tree.cc pci.cc resources.cc timer.cc \
|
||||
dde_kit.cc spin_lock.cc
|
||||
LIBS = thread alarm lock
|
||||
|
||||
#
|
||||
# Enable 'spin_lock.cc' to reuse the spinlock implementation of the base
|
||||
# repository by including the corresponding non-public headers local to
|
||||
# 'base-<platform>/src'. Because the platform-specific parts of these headers
|
||||
# may contain code that invokes system calls, we need to specify the 'syscall'
|
||||
# lib as well. This way, the needed include-search directories are supplied to
|
||||
# the build system via the respective 'import-syscall.mk' file.
|
||||
#
|
||||
LIBS += syscall
|
||||
REP_INC_DIR += src/base/lock src/platform
|
||||
|
||||
vpath % $(REP_DIR)/src/lib/dde_kit
|
||||
|
@ -15,15 +15,28 @@
|
||||
#include <cpu/atomic.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
#include <spin_lock.h>
|
||||
#include <spin_lock.h> /* included from 'base/src/base/lock/' */
|
||||
|
||||
extern "C" {
|
||||
#include <dde_kit/spin_lock.h>
|
||||
}
|
||||
|
||||
|
||||
template <bool b> struct Static_assert { };
|
||||
|
||||
/* specialization for successful static assertion */
|
||||
template <> struct Static_assert<true> { static void assert() { } };
|
||||
|
||||
|
||||
extern "C" void dde_kit_spin_lock_init(dde_kit_spin_lock *spin_lock)
|
||||
{
|
||||
/*
|
||||
* Check at compile time that the enum values defined for DDE Kit
|
||||
* correspond to those defined in 'base/src/base/lock/spin_lock.h'.
|
||||
*/
|
||||
Static_assert<(int)DDE_KIT_SPIN_LOCK_LOCKED == (int)SPINLOCK_LOCKED >::assert();
|
||||
Static_assert<(int)DDE_KIT_SPIN_LOCK_UNLOCKED == (int)SPINLOCK_UNLOCKED>::assert();
|
||||
|
||||
*spin_lock = SPINLOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user