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 c2d220a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 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
21 changes: 11 additions & 10 deletions src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ dpusmph_init(struct module *module, const dpusm_pf_t *funcs)
dpusmph->module = module;
dpusmph->funcs = funcs;
dpusmph->self = dpusmph;
atomic_set(&dpusmph->refs, 0);
}

return dpusmph;
Expand Down Expand Up @@ -304,7 +303,7 @@ dpusm_provider_unregister_handle(dpusm_t *dpusm, dpusm_ph_t **provider) {
}

int rc = 0;
const int refs = atomic_read(&(*provider)->refs);
const int refs = module_refcount((*provider)->module) - 1;
if (refs) {
printk("%s: Unregistering provider \"%s\" with %d references remaining.\n",
__func__, module_name((*provider)->module), refs);
Expand Down Expand Up @@ -358,11 +357,12 @@ dpusm_provider_get(dpusm_t *dpusm, const char *name) {
return NULL;
}

atomic_inc(&(*provider)->refs);
printk("refcount %d\n", module_refcount((*provider)->module));

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) - 1);

if ((*provider)->funcs->at_connect) {
(*provider)->funcs->at_connect();
Expand All @@ -385,14 +385,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) == 1) {
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 +403,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) - 1);
return DPUSM_OK;
}

Expand All @@ -423,7 +424,7 @@ void dpusm_provider_invalidate(dpusm_t *dpusm, const char *name) {
(*provider)->funcs = NULL;
memset(&(*provider)->capabilities, 0, sizeof((*provider)->capabilities));
printk("%s: Provider \"%s\" has been invalidated with %d users active.\n",
__func__, name, atomic_read(&(*provider)->refs));
__func__, name, module_refcount((*provider)->module) - 1);
/* not decrementing module reference count here - provider is still registered */
}
else {
Expand Down

0 comments on commit c2d220a

Please sign in to comment.