dde_rump: remove static globals

This commit is contained in:
Christian Helmuth 2015-11-11 10:09:23 +01:00
parent db3a5a3b02
commit 5c6f7bdea0
2 changed files with 31 additions and 19 deletions

View File

@ -61,12 +61,16 @@ int rumpuser_init(int version, const struct rumpuser_hyperup *hyp)
** Threads **
*************/
static Hard_context _main_thread(0);
static Hard_context * main_thread()
{
static Hard_context inst(0);
return &inst;
}
static Hard_context *myself()
{
Hard_context *h = dynamic_cast<Hard_context *>(Genode::Thread_base::myself());
return h ? h : &_main_thread;
return h ? h : main_thread();
}
@ -181,12 +185,12 @@ void rumpuser_putchar(int ch)
if (ch == '\n') {
buf[count] = 0;
int nlocks;
if (myself() != &_main_thread)
if (myself() != main_thread())
rumpkern_unsched(&nlocks, 0);
PLOG("rump: %s", buf);
if (myself() != &_main_thread)
if (myself() != main_thread())
rumpkern_sched(nlocks, 0);
count = 0;
@ -204,21 +208,26 @@ struct Allocator_policy
{
int nlocks;
if (myself() != &_main_thread)
if (myself() != main_thread())
rumpkern_unsched(&nlocks, 0);
return nlocks;
}
static void unblock(int nlocks)
{
if (myself() != &_main_thread)
if (myself() != main_thread())
rumpkern_sched(nlocks, 0);
}
};
typedef Allocator::Fap<128 * 1024 * 1024, Allocator_policy> Rump_alloc;
static Genode::Lock _alloc_lock;
static Genode::Lock & alloc_lock()
{
static Genode::Lock inst;
return inst;
}
static Rump_alloc* allocator()
{
@ -228,7 +237,7 @@ static Rump_alloc* allocator()
int rumpuser_malloc(size_t len, int alignment, void **memp)
{
Genode::Lock::Guard guard(_alloc_lock);
Genode::Lock::Guard guard(alloc_lock());
int align = alignment ? Genode::log2(alignment) : 0;
*memp = allocator()->alloc(len, align);
@ -243,7 +252,7 @@ int rumpuser_malloc(size_t len, int alignment, void **memp)
void rumpuser_free(void *mem, size_t len)
{
Genode::Lock::Guard guard(_alloc_lock);
Genode::Lock::Guard guard(alloc_lock());
allocator()->free(mem, len);

View File

@ -41,7 +41,12 @@ static char const *fs_types[] = { RUMP_MOUNT_CD9660, RUMP_MOUNT_EXT2FS,
RUMP_MOUNT_NTFS, RUMP_MOUNT_UDF, 0 };
typedef Genode::String<16> Fs_type;
static Fs_type _fs_type;
static Fs_type & fs_type()
{
static Fs_type inst = Genode::config()->xml_node().attribute_value("fs", Fs_type());
return inst;
}
static bool _supports_symlinks;
@ -64,10 +69,10 @@ static void _print_types()
static bool check_symlinks()
{
if (!Genode::strcmp(_fs_type.string(), RUMP_MOUNT_EXT2FS))
if (!Genode::strcmp(fs_type().string(), RUMP_MOUNT_EXT2FS))
return true;
if (!Genode::strcmp(_fs_type.string(), RUMP_MOUNT_FFS))
if (!Genode::strcmp(fs_type().string(), RUMP_MOUNT_FFS))
return true;
return false;
@ -76,7 +81,7 @@ static bool check_symlinks()
static bool check_read_only()
{
if (!Genode::strcmp(_fs_type.string(), RUMP_MOUNT_CD9660))
if (!Genode::strcmp(fs_type().string(), RUMP_MOUNT_CD9660))
return true;
return false;
@ -123,14 +128,12 @@ class File_system::Sync : public Genode::Thread<1024 * sizeof(Genode::addr_t)>
void File_system::init(Server::Entrypoint &ep)
{
_fs_type = Genode::config()->xml_node().attribute_value("fs", Fs_type());
if (!_check_type(_fs_type.string())) {
if (!_check_type(fs_type().string())) {
PERR("Invalid or no file system given (use \'<config fs=\"<fs type>\"/>)");
_print_types();
throw Genode::Exception();
}
PINF("Using %s as file system", _fs_type.string());
PINF("Using %s as file system", fs_type().string());
/* start rump kernel */
rump_init();
@ -143,8 +146,8 @@ void File_system::init(Server::Entrypoint &ep)
int opts = check_read_only() ? RUMP_MNT_RDONLY : 0;
args.fspec = (char *)GENODE_DEVICE;
if (rump_sys_mount(_fs_type.string(), "/", opts, &args, sizeof(args)) == -1) {
PERR("Mounting '%s' file system failed (errno %u)", _fs_type.string(), errno);
if (rump_sys_mount(fs_type().string(), "/", opts, &args, sizeof(args)) == -1) {
PERR("Mounting '%s' file system failed (errno %u)", fs_type().string(), errno);
throw Genode::Exception();
}