Lines Matching refs:object

42  * objects.c - contains routines which manipulate object lists of NCUs,
101 /* Should be kept in same order as object types */
168 nwamd_object_t object;
174 while ((object = uu_list_teardown(object_lists[i].object_list,
176 free(object);
206 nlog(LOG_ERR, "cannot get lock for object list: %s",
222 * Initialize object and return it in locked state.
228 nwamd_object_t object;
231 object = calloc(1, sizeof (struct nwamd_object));
232 if (object == NULL)
235 (void) strlcpy(object->nwamd_object_name, name, NWAM_MAX_NAME_LEN);
237 /* 1 for the list and 1 for the returned object */
238 object->nwamd_object_refcount = 2;
239 object->nwamd_object_handle = handle;
240 object->nwamd_object_data = data;
241 object->nwamd_object_type = type;
242 object->nwamd_object_state = NWAM_STATE_INITIALIZED;
243 object->nwamd_object_aux_state = NWAM_AUX_STATE_INITIALIZED;
245 /* Add object to appropriate object list */
248 "object %s", name);
249 free(object);
253 if (pthread_mutex_init(&object->nwamd_object_mutex, NULL) == -1) {
256 free(object);
260 (void) pthread_mutex_lock(&object->nwamd_object_mutex);
262 uu_list_node_init(object, &object->nwamd_object_node, object_list_pool);
264 uu_list_last(object_list->object_list), object);
268 return (object);
272 * Find object in object list, returning it holding a lock and with the
279 nwamd_object_t object;
287 for (object = uu_list_first(object_list->object_list);
288 object != NULL;
289 object = uu_list_next(object_list->object_list, object)) {
290 if (strcmp(object->nwamd_object_name, name) == 0)
293 if (object != NULL) {
294 (void) pthread_mutex_lock(&object->nwamd_object_mutex);
295 object->nwamd_object_refcount++;
299 return (object);
302 /* Removes object from list, destroy mutex, and free storage. */
304 nwamd_object_fini(nwamd_object_t object, nwam_object_type_t objtype)
309 assert(object != NULL);
316 if (o == object) {
317 uu_list_remove(object_list->object_list, object);
319 &object->nwamd_object_mutex);
321 &object->nwamd_object_mutex);
322 uu_list_node_fini(object, &object->nwamd_object_node,
326 nwamd_ncu_free(object->nwamd_object_data);
327 nwam_ncu_free(object->nwamd_object_handle);
330 nwam_loc_free(object->nwamd_object_handle);
333 nwam_enm_free(object->nwamd_object_handle);
337 "got unexpected object type %d", objtype);
340 free(object);
347 nwamd_object_decref(nwamd_object_t object, int num)
351 assert(object->nwamd_object_refcount >= num);
352 object->nwamd_object_refcount -= num;
353 if (object->nwamd_object_refcount == 0) {
356 * list lock before we get the object lock when we are
357 * destroying the object. If we merely release and then
359 * object. Instead we bump the ref count so that it can't
360 * be destroyed, we drop the object lock, we acquire the
361 * list lock, we acquire the object lock, decrement the ref
366 object->nwamd_object_refcount++;
367 objtype = object->nwamd_object_type;
368 (void) pthread_mutex_unlock(&object->nwamd_object_mutex);
370 (void) pthread_mutex_lock(&object->nwamd_object_mutex);
371 if (--object->nwamd_object_refcount != 0)
373 &object->nwamd_object_mutex);
375 nwamd_object_fini(object, objtype);
378 (void) pthread_mutex_unlock(&object->nwamd_object_mutex);
384 * let go of an object but ensure it will not go away.
387 nwamd_object_release_and_preserve(nwamd_object_t object)
389 (void) pthread_mutex_unlock(&object->nwamd_object_mutex);
393 nwamd_object_release(nwamd_object_t object)
395 nwamd_object_decref(object, 1);
399 nwamd_object_release_and_destroy(nwamd_object_t object)
401 nwamd_object_decref(object, 2);
405 nwamd_object_release_and_destroy_after_preserve(nwamd_object_t object)
407 nwamd_object_decref(object, 3);
411 nwamd_object_release_after_preserve(nwamd_object_t object)
413 nwamd_object_decref(object, 2);
453 nwamd_object_t object;
460 for (object = uu_list_first(object_list->object_list);
461 object != NULL;
462 object = uu_list_next(object_list->object_list, object)) {
463 (void) pthread_mutex_lock(&object->nwamd_object_mutex);
464 ret = cb(object, data);
465 (void) pthread_mutex_unlock(&object->nwamd_object_mutex);