Skip to content

Commit

Permalink
mutex_lock_interruptible
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Jul 9, 2024
1 parent 965cc4e commit a090ea0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/dpusm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
20 changes: 10 additions & 10 deletions src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -329,20 +329,20 @@ 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;
}

void *addr = *provider;
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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

0 comments on commit a090ea0

Please sign in to comment.