From a090ea06ef1732079157dbd7bea820b883bbd6fa Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 1 Jul 2024 15:58:06 -0600 Subject: [PATCH] mutex_lock_interruptible --- src/dpusm.c | 2 +- src/provider.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dpusm.c b/src/dpusm.c index 712f6f7..fd65b59 100644 --- a/src/dpusm.c +++ b/src/dpusm.c @@ -77,7 +77,7 @@ dpusm_init(void) { static void __exit dpusm_exit(void) { - mutex_lock(&dpusm.lock); + while (mutex_lock_interruptible(&dpusm.lock)); const int active = atomic_read(&dpusm.active); if (unlikely(active)) { diff --git a/src/provider.c b/src/provider.c index 41b9354..9b5bf69 100644 --- a/src/provider.c +++ b/src/provider.c @@ -265,19 +265,19 @@ dpusm_provider_register(dpusm_t *dpusm, struct module *module, const dpusm_pf_t return -EINVAL; } - mutex_lock(&dpusm->lock);; + while (mutex_lock_interruptible(&dpusm->lock)); dpusm_ph_t **found = find_provider(dpusm, module_name(module)); if (found) { printk("%s: DPUSM Provider with the name \"%s\" (%p) already exists. %zu providers registered.\n", __func__, module_name(module), *found, dpusm->count); - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); return -EEXIST; } dpusm_ph_t *provider = dpusmph_init(module, funcs); if (!provider) { - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); return -ECANCELED; } @@ -295,7 +295,7 @@ dpusm_provider_register(dpusm_t *dpusm, struct module *module, const dpusm_pf_t printk("%s: DPUSM Provider \"%s\" (%p) added. Now %zu providers registered.\n", __func__, module_name(module), provider, dpusm->count); - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); return 0; } @@ -329,12 +329,12 @@ dpusm_provider_unregister_handle(dpusm_t *dpusm, dpusm_ph_t **provider) { int dpusm_provider_unregister(dpusm_t *dpusm, struct module *module) { - mutex_lock(&dpusm->lock);; + while (mutex_lock_interruptible(&dpusm->lock)); dpusm_ph_t **provider = find_provider(dpusm, module_name(module)); if (!provider) { printk("%s: Could not find provider with name \"%s\"\n", __func__, module_name(module)); - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); return DPUSM_ERROR; } @@ -342,7 +342,7 @@ dpusm_provider_unregister(dpusm_t *dpusm, struct module *module) { const int rc = dpusm_provider_unregister_handle(dpusm, provider); printk("%s: Unregistered \"%s\" (%p): %d\n", __func__, module_name(module), addr, rc); - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); return rc; } @@ -354,7 +354,7 @@ dpusm_provider_unregister(dpusm_t *dpusm, struct module *module) { /* get a provider by name */ dpusm_ph_t ** dpusm_provider_get(dpusm_t *dpusm, const char *name) { - mutex_lock(&dpusm->lock); + while (mutex_lock_interruptible(&dpusm->lock)); dpusm_ph_t **provider = find_provider(dpusm, name); if (provider) { struct module *module = (*provider)->module; @@ -414,7 +414,7 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) { } void dpusm_provider_invalidate(dpusm_t *dpusm, const char *name) { - mutex_lock(&dpusm->lock);; + while (mutex_lock_interruptible(&dpusm->lock)); dpusm_ph_t **provider = find_provider(dpusm, name); if (provider && *provider) { (*provider)->funcs = NULL; @@ -427,5 +427,5 @@ void dpusm_provider_invalidate(dpusm_t *dpusm, const char *name) { printk("%s: Error: Did not find provider \"%s\"\n", __func__, name); } - mutex_unlock(&dpusm->lock);; + mutex_unlock(&dpusm->lock); }