Lines Matching refs:mod

49 topo_mod_release(topo_mod_t *mod, tnode_t *node)
51 topo_mod_enter(mod);
53 if (mod->tm_info->tmi_ops->tmo_release != NULL)
54 mod->tm_info->tmi_ops->tmo_release(mod, node);
56 topo_mod_exit(mod);
60 topo_mod_hold(topo_mod_t *mod)
62 (void) pthread_mutex_lock(&mod->tm_lock);
63 mod->tm_refs++;
64 assert(mod->tm_refs != 0);
65 (void) pthread_mutex_unlock(&mod->tm_lock);
69 topo_mod_rele(topo_mod_t *mod)
71 assert(mod->tm_refs != 0);
73 (void) pthread_mutex_lock(&mod->tm_lock);
78 if (--mod->tm_refs == 0)
79 topo_modhash_unload(mod);
81 (void) pthread_mutex_unlock(&mod->tm_lock);
85 topo_mod_enter(topo_mod_t *mod)
87 (void) pthread_mutex_lock(&mod->tm_lock);
89 while (mod->tm_busy != 0)
90 (void) pthread_cond_wait(&mod->tm_cv, &mod->tm_lock);
92 ++mod->tm_busy;
94 (void) pthread_mutex_unlock(&mod->tm_lock);
98 topo_mod_exit(topo_mod_t *mod)
100 (void) pthread_mutex_lock(&mod->tm_lock);
101 --mod->tm_busy;
103 assert(mod->tm_busy == 0);
105 (void) pthread_cond_broadcast(&mod->tm_cv);
106 (void) pthread_mutex_unlock(&mod->tm_lock);
122 topo_mod_stop(topo_mod_t *mod)
124 if (mod->tm_flags & TOPO_MOD_INIT) {
125 mod->tm_mops->mop_fini(mod);
126 if (mod->tm_flags & TOPO_MOD_REG)
127 topo_mod_unregister(mod);
130 mod->tm_flags = TOPO_MOD_FINI;
132 topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC,
133 "module %s stopped\n", mod->tm_name);
137 topo_mod_start(topo_mod_t *mod, topo_version_t version)
139 topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC,
140 "starting module %s\n", mod->tm_name);
142 if (mod->tm_mops->mop_init(mod, version) != 0) {
143 if (mod->tm_errno == 0)
144 mod->tm_errno = ETOPO_MOD_INIT;
145 topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR,
146 "module %s failed to initialize: %s\n", mod->tm_name,
147 topo_strerror(mod->tm_errno));
151 mod->tm_flags |= TOPO_MOD_INIT;
153 if (!(mod->tm_flags & TOPO_MOD_REG)) {
154 topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR,
155 "module %s failed to register\n", mod->tm_name);
156 mod->tm_errno = ETOPO_MOD_NOREG;
157 topo_mod_stop(mod);
167 topo_mod_t *mod;
171 mod = topo_modhash_lookup(mhp, name);
172 if (mod != NULL && bump != 0)
173 topo_mod_hold(mod);
176 return (mod);
180 topo_mod_destroy(topo_mod_t *mod)
182 topo_hdl_t *thp = mod->tm_hdl;
184 if (mod == NULL)
187 assert(mod->tm_refs == 0);
188 assert(!MUTEX_HELD(&mod->tm_lock));
190 if (mod->tm_name != NULL)
191 topo_hdl_strfree(thp, mod->tm_name);
192 if (mod->tm_path != NULL)
193 topo_hdl_strfree(thp, mod->tm_path);
194 if (mod->tm_rootdir != NULL)
195 topo_hdl_strfree(thp, mod->tm_rootdir);
197 topo_hdl_free(thp, mod, sizeof (topo_mod_t));
201 set_create_error(topo_hdl_t *thp, topo_mod_t *mod, const char *path, int err)
210 if (mod != NULL)
211 topo_mod_destroy(mod);
222 topo_mod_t *mod;
227 if ((mod = topo_hdl_zalloc(thp, sizeof (topo_mod_t))) == NULL)
228 return (set_create_error(thp, mod, path, ETOPO_NOMEM));
230 mod->tm_hdl = thp;
232 (void) pthread_mutex_init(&mod->tm_lock, NULL);
234 mod->tm_name = topo_hdl_strdup(thp, name);
236 mod->tm_path = topo_hdl_strdup(thp, path);
237 mod->tm_rootdir = topo_hdl_strdup(thp, thp->th_rootdir);
238 if (mod->tm_name == NULL || mod->tm_rootdir == NULL)
239 return (set_create_error(thp, mod, path, ETOPO_NOMEM));
241 mod->tm_mops = (topo_imodops_t *)ops;
242 mod->tm_alloc = thp->th_alloc;
247 if ((topo_mod_start(mod, version)) < 0)
248 return (set_create_error(thp, mod, path, mod->tm_errno));
250 topo_dprintf(thp, TOPO_DBG_MODSVC, "loaded module %s\n", mod->tm_name);
252 return (mod);
295 topo_mod_t *mod = NULL;
300 for (mod = mhp->mh_hash[h]; mod != NULL; mod = mod->tm_next) {
301 if (strcmp(name, mod->tm_name) == 0)
305 return (mod);
313 topo_mod_t *mod;
318 if ((mod = topo_mod_create(thp, name, path, ops, version)) == NULL) {
323 topo_mod_hold(mod);
326 mod->tm_next = mhp->mh_hash[h];
327 mhp->mh_hash[h] = mod;
331 return (mod);
335 topo_modhash_unload(topo_mod_t *mod)
339 topo_hdl_t *thp = mod->tm_hdl;
342 assert(MUTEX_HELD(&mod->tm_lock));
343 assert(mod->tm_busy == 0);
350 h = topo_strhash(mod->tm_name) % mhp->mh_hashlen;
354 if (mp == mod)
361 *pp = mod->tm_next;
370 (void) pthread_mutex_unlock(&mod->tm_lock);
372 topo_mod_stop(mod);
373 topo_mod_destroy(mod);