Lines Matching refs:nsem

41 	struct nsem_obj *nsem;  in nsem_find()  local
43 SYS_SLIST_FOR_EACH_CONTAINER(&nsem_list, nsem, snode) { in nsem_find()
44 if ((nsem->name != NULL) && (strcmp(nsem->name, name) == 0)) { in nsem_find()
45 return nsem; in nsem_find()
53 static void nsem_cleanup(struct nsem_obj *nsem) in nsem_cleanup() argument
55 if (nsem != NULL) { in nsem_cleanup()
56 if (nsem->name != NULL) { in nsem_cleanup()
57 k_free(nsem->name); in nsem_cleanup()
59 k_free(nsem); in nsem_cleanup()
64 static void nsem_unref(struct nsem_obj *nsem) in nsem_unref() argument
66 nsem->ref_count -= 1; in nsem_unref()
67 __ASSERT(nsem->ref_count >= 0, "ref_count may not be negative"); in nsem_unref()
69 if (nsem->ref_count == 0) { in nsem_unref()
70 __ASSERT(nsem->name == NULL, "ref_count is 0 but sem is not unlinked"); in nsem_unref()
72 sys_slist_find_and_remove(&nsem_list, (sys_snode_t *) nsem); in nsem_unref()
75 nsem_cleanup(nsem); in nsem_unref()
226 struct nsem_obj *nsem = NULL; in sem_open() local
255 nsem = nsem_find(name); in sem_open()
257 if (nsem != NULL) { /* Named semaphore exists */ in sem_open()
263 __ASSERT_NO_MSG(nsem->ref_count != INT_MAX); in sem_open()
264 nsem->ref_count++; in sem_open()
275 nsem = k_calloc(1, sizeof(struct nsem_obj)); in sem_open()
276 if (nsem == NULL) { in sem_open()
283 nsem->name = k_calloc(namelen + 1, sizeof(uint8_t)); in sem_open()
284 if (nsem->name == NULL) { in sem_open()
289 strcpy(nsem->name, name); in sem_open()
292 nsem->ref_count = 2; in sem_open()
294 (void)k_sem_init(&nsem->sem, value, CONFIG_POSIX_SEM_VALUE_MAX); in sem_open()
296 sys_slist_append(&nsem_list, (sys_snode_t *)&(nsem->snode)); in sem_open()
301 nsem_cleanup(nsem); in sem_open()
304 nsem = NULL; in sem_open()
308 return nsem == NULL ? SEM_FAILED : &nsem->sem; in sem_open()
314 struct nsem_obj *nsem; in sem_unlink() local
329 nsem = nsem_find(name); in sem_unlink()
330 if (nsem == NULL) { in sem_unlink()
336 k_free(nsem->name); in sem_unlink()
337 nsem->name = NULL; in sem_unlink()
338 nsem_unref(nsem); in sem_unlink()
347 struct nsem_obj *nsem = CONTAINER_OF(sem, struct nsem_obj, sem); in sem_close() local
355 nsem_unref(nsem); in sem_close()
364 struct nsem_obj *nsem = CONTAINER_OF(sem, struct nsem_obj, sem); in nsem_get_ref_count() local
368 __ASSERT_NO_MSG(nsem != NULL); in nsem_get_ref_count()
371 ref_count = nsem->ref_count; in nsem_get_ref_count()