From f19ecb0650b2a564ca9bbf4e8fef2d58d16b8541 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 16 Jul 2020 14:31:24 +0200 Subject: [PATCH] Use Mutex/Blockade instead of Lock due to changes in Genode repository Issue genodelabs/genode#3802 --- ports/protobuf_grpc.hash | 2 +- src/lib/libsodium/genode_core.cc | 8 ++++---- src/lib/protobuf/patches/01-mutex.patch | 16 +++++++++++++--- src/lib/sdl/audio/SDL_genodeaudio.cc | 8 ++++---- src/lib/sdl/video/SDL_genode_fb_events.cc | 4 ++-- src/lib/sdl/video/SDL_genode_fb_video.cc | 6 +++--- src/lib/sdl2/video/SDL_genode_fb_events.cc | 4 ++-- src/lib/sdl2/video/SDL_genode_fb_video.cc | 6 +++--- src/server/flif_capture/main.cc | 10 ++++++---- src/server/fuse_fs/node.h | 1 - src/server/tftp_rom/component.cc | 15 +++++++-------- 11 files changed, 45 insertions(+), 35 deletions(-) diff --git a/ports/protobuf_grpc.hash b/ports/protobuf_grpc.hash index ada3f82..6940c59 100644 --- a/ports/protobuf_grpc.hash +++ b/ports/protobuf_grpc.hash @@ -1 +1 @@ -319da8b104f7eca04998b1f3ae3041e4bca0fd9c +a912520e3a877afd0ecc7cd71b9ca13aee08d713 diff --git a/src/lib/libsodium/genode_core.cc b/src/lib/libsodium/genode_core.cc index 3b458b8..bdf4a9f 100644 --- a/src/lib/libsodium/genode_core.cc +++ b/src/lib/libsodium/genode_core.cc @@ -10,12 +10,12 @@ #include "private/implementations.h" #include "private/mutex.h" -#include +#include #include static int initialized; -static Genode::Lock *_sodium_lock; +static Genode::Mutex *_sodium_mutex; extern "C" int sodium_init(void) @@ -35,14 +35,14 @@ int sodium_init(void) int sodium_crit_enter(void) { - _sodium_lock->lock(); + _sodium_mutex->acquire(); return 0; } int sodium_crit_leave(void) { - _sodium_lock->unlock(); + _sodium_mutex->release(); return 0; } diff --git a/src/lib/protobuf/patches/01-mutex.patch b/src/lib/protobuf/patches/01-mutex.patch index 44f6699..0f208c0 100644 --- a/src/lib/protobuf/patches/01-mutex.patch +++ b/src/lib/protobuf/patches/01-mutex.patch @@ -13,16 +13,26 @@ index a311889..967be6a 100644 #define GOOGLE_PROTOBUF_STUBS_MUTEX_H_ -#include -+#include ++#include #ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP -@@ -104,7 +104,7 @@ class PROTOBUF_EXPORT GOOGLE_PROTOBUF_CAPABILITY("mutex") WrappedMutex { +@@ -96,15 +96,15 @@ + class PROTOBUF_EXPORT GOOGLE_PROTOBUF_CAPABILITY("mutex") WrappedMutex { + public: + WrappedMutex() = default; +- void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); } +- void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); } ++ void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.acquire(); } ++ void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.release(); } + // Crash if this Mutex is not held exclusively by this thread. + // May fail to crash when it should; will never crash when it should not. + void AssertHeld() const {} private: #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP - std::mutex mu_; -+ Genode::Lock mu_; ++ Genode::Mutex mu_; #else // ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP CriticalSectionLock mu_; #endif // #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP diff --git a/src/lib/sdl/audio/SDL_genodeaudio.cc b/src/lib/sdl/audio/SDL_genodeaudio.cc index 2d50716..84f0dc6 100644 --- a/src/lib/sdl/audio/SDL_genodeaudio.cc +++ b/src/lib/sdl/audio/SDL_genodeaudio.cc @@ -26,8 +26,8 @@ #include -extern Genode::Env *global_env(); -extern Genode::Lock event_lock; +extern Genode::Env *global_env(); +extern Genode::Mutex event_mutex; enum { @@ -75,7 +75,7 @@ struct Volume_config if (!_config_rom.valid()) { return; } - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); Genode::Xml_node config = _config_rom.xml(); @@ -212,7 +212,7 @@ static void GENODEAUD_WaitAudio(_THIS) static void GENODEAUD_PlayAudio(_THIS) { - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); Audio_out::Connection *c[AUDIO_CHANNELS]; Audio_out::Packet *p[AUDIO_CHANNELS]; diff --git a/src/lib/sdl/video/SDL_genode_fb_events.cc b/src/lib/sdl/video/SDL_genode_fb_events.cc index ae82538..c43d24e 100644 --- a/src/lib/sdl/video/SDL_genode_fb_events.cc +++ b/src/lib/sdl/video/SDL_genode_fb_events.cc @@ -40,7 +40,7 @@ #include -Genode::Lock event_lock; +Genode::Mutex event_mutex; Video video_events; @@ -101,7 +101,7 @@ extern "C" { void Genode_Fb_PumpEvents(SDL_VideoDevice *t) { - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); if (video_events.resize_pending) { video_events.resize_pending = false; diff --git a/src/lib/sdl/video/SDL_genode_fb_video.cc b/src/lib/sdl/video/SDL_genode_fb_video.cc index 0e2bd02..2334cfb 100644 --- a/src/lib/sdl/video/SDL_genode_fb_video.cc +++ b/src/lib/sdl/video/SDL_genode_fb_video.cc @@ -41,8 +41,8 @@ extern Genode::Env &global_env(); extern Gui::Connection &global_gui(); -extern Genode::Lock event_lock; -extern Video video_events; +extern Genode::Mutex event_mutex; +extern Video video_events; extern "C" { @@ -68,7 +68,7 @@ extern "C" { void _handle_mode_change() { - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); Framebuffer::Mode mode = _gui.mode(); df_mode.w = mode.area.w(); diff --git a/src/lib/sdl2/video/SDL_genode_fb_events.cc b/src/lib/sdl2/video/SDL_genode_fb_events.cc index e9ac623..5225fb4 100644 --- a/src/lib/sdl2/video/SDL_genode_fb_events.cc +++ b/src/lib/sdl2/video/SDL_genode_fb_events.cc @@ -40,7 +40,7 @@ #include -Genode::Lock event_lock; +Genode::Mutex event_mutex; Video video_events; @@ -107,7 +107,7 @@ extern "C" { // SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); } - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); if (video_events.resize_pending) { video_events.resize_pending = false; diff --git a/src/lib/sdl2/video/SDL_genode_fb_video.cc b/src/lib/sdl2/video/SDL_genode_fb_video.cc index e83ea5e..2b00c15 100644 --- a/src/lib/sdl2/video/SDL_genode_fb_video.cc +++ b/src/lib/sdl2/video/SDL_genode_fb_video.cc @@ -42,8 +42,8 @@ extern Genode::Env &global_env(); extern Gui::Connection &global_gui(); -extern Genode::Lock event_lock; -extern Video video_events; +extern Genode::Mutex event_mutex; +extern Video video_events; extern "C" { @@ -69,7 +69,7 @@ extern "C" { void _handle_mode_change() { - Genode::Lock_guard guard(event_lock); + Genode::Mutex::Guard guard(event_mutex); Framebuffer::Mode mode = _gui.mode(); diff --git a/src/server/flif_capture/main.cc b/src/server/flif_capture/main.cc index 64ecec0..d4927b4 100644 --- a/src/server/flif_capture/main.cc +++ b/src/server/flif_capture/main.cc @@ -54,7 +54,7 @@ class Flif_capture::Encoder // TODO: reuse FLIF_IMAGE, do not reallocate FLIF_IMAGE *_image = nullptr; Semaphore _semaphore { }; - Lock _lock { Lock::LOCKED }; + Mutex _mutex { }; public: @@ -71,11 +71,13 @@ class Flif_capture::Encoder */ void entry() { + _mutex.acquire(); + for (;;) { while (_image == nullptr) { - _lock.unlock(); + _mutex.release(); _semaphore.down(); - _lock.lock(); + _mutex.acquire(); } char filename[32] { '\0' }; @@ -119,7 +121,7 @@ class Flif_capture::Encoder if (_image != nullptr) return; - Lock::Guard guard(_lock); + Mutex::Guard guard(_mutex); /* TODO: attach/detach each capture? */ Genode::Attached_dataspace fb_ds(_env.rm(), fb_cap); diff --git a/src/server/fuse_fs/node.h b/src/server/fuse_fs/node.h index c4330f7..27761c3 100644 --- a/src/server/fuse_fs/node.h +++ b/src/server/fuse_fs/node.h @@ -18,7 +18,6 @@ /* Genode includes */ #include -#include #include #include diff --git a/src/server/tftp_rom/component.cc b/src/server/tftp_rom/component.cc index 11e5347..5061550 100644 --- a/src/server/tftp_rom/component.cc +++ b/src/server/tftp_rom/component.cc @@ -58,7 +58,7 @@ extern "C" void data_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p, class Tftp_rom::Session_component : public Genode::Rpc_object, public Session_list::Element, - Genode::Lock + Genode::Blockade { private: @@ -90,7 +90,7 @@ class Tftp_rom::Session_component : inline void finalize() { - unlock(); + wakeup(); _ack_timeout = 0; if (_chain_head != NULL) { pbuf_free(_chain_head); @@ -132,7 +132,6 @@ class Tftp_rom::Session_component : unsigned long now, unsigned timeout) : - Lock(LOCKED), _env(env), _filename(namestr), _pcb(udp_new()), @@ -309,7 +308,7 @@ class Tftp_rom::Session_component : Rom_dataspace_capability dataspace() override { - if (!done()) lock(); + if (!done()) block(); Dataspace_capability ds = _dataspace; return static_cap_cast(ds); @@ -370,7 +369,7 @@ class Tftp_rom::Root : public Genode::Root_component */ Lwip::Nic_netif _netif { _env, *md_alloc(), _config_rom.xml() }; - class Timeout_dispatcher : Genode::Thread, Genode::Lock + class Timeout_dispatcher : Genode::Thread, Genode::Mutex { private: @@ -390,7 +389,7 @@ class Tftp_rom::Root : public Genode::Root_component ctx == &_sig_ctx; ctx = _sig_rec.wait_for_signal().context()) { - Lock::Guard(*this); + Mutex::Guard guard(*this); Session_component *session = _sessions.first(); if (!session) { @@ -439,7 +438,7 @@ class Tftp_rom::Root : public Genode::Root_component void insert(Session_component *session) { - Lock::Guard(*this); + Mutex::Guard guard(*this); if (!_sessions.first()) _timer.sigh(_sig_cap); @@ -449,7 +448,7 @@ class Tftp_rom::Root : public Genode::Root_component void remove(Session_component *session) { - Lock::Guard(*this); + Mutex::Guard guard(*this); _sessions.remove(session); /* timer will be stopped at the next signal */