Skip to content

Commit

Permalink
remove provider handle refcount
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Jul 1, 2024
1 parent 5b508d3 commit bb2f8c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion include/dpusm/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ typedef struct dpusm_provider_handle {
struct module *module;
dpusm_pc_t capabilities; /* constant set of capabilities */
const dpusm_pf_t *funcs; /* reference to a struct */
atomic_t refs; /* how many users are holding this provider */
struct list_head list;
struct dpusm_provider_handle *self;
} dpusm_ph_t;
Expand Down
14 changes: 7 additions & 7 deletions src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,10 @@ dpusm_provider_get(dpusm_t *dpusm, const char *name) {
return NULL;
}

atomic_inc(&(*provider)->refs);
atomic_inc(&dpusm->active);

printk("%s: User has been given a handle to \"%s\" (%p) (now %d users).\n",
__func__, name, *provider, atomic_read(&(*provider)->refs));
__func__, name, *provider, module_refcount(&(*provider)->module));

if ((*provider)->funcs->at_connect) {
(*provider)->funcs->at_connect();
Expand All @@ -385,14 +384,15 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
return DPUSM_ERROR;
}

if (!atomic_read(&(*provider)->refs)) {
struct module *module = (*provider)->module;

if (!module_refcount(module) {
printk("%s Error: Cannot decrement provider \"%s\" user count already at 0.\n",
__func__, module_name((*provider)->module));
__func__, module_name(module));
return DPUSM_ERROR;
}

module_put((*provider)->module);
atomic_dec(&(*provider)->refs);
module_put(module);
atomic_dec(&dpusm->active);

if ((*provider)->funcs) { /* provider might have been invalidated */
Expand All @@ -402,7 +402,7 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
}

printk("%s: User has returned a handle to \"%s\" (%p) (now %d users).\n",
__func__, module_name((*provider)->module), *provider, atomic_read(&(*provider)->refs));
__func__, module_name(module), *provider, module_refcount(module));
return DPUSM_OK;
}

Expand Down

0 comments on commit bb2f8c0

Please sign in to comment.