network/uinet/sys/kern/uipc_sem.c
/*
 * ksem object management including creation and reference counting
 * routines.
 */
ksem object management including creation and reference counting
routines.
ksem object management including creation and reference counting routines .
static struct ksem *
ksem_alloc(struct ucred *ucred, mode_t mode, unsigned int value)
{
	struct ksem *ks;
	mtx_lock(&ksem_count_lock);
	if (nsems == p31b_getcfg(CTL_P1003_1B_SEM_NSEMS_MAX) || ksem_dead) {
		mtx_unlock(&ksem_count_lock);
		return (NULL);
	}
	nsems++;
	mtx_unlock(&ksem_count_lock);
	ks = malloc(sizeof(*ks), M_KSEM, M_WAITOK | M_ZERO);
	ks->ks_uid = ucred->cr_uid;
	ks->ks_gid = ucred->cr_gid;
	ks->ks_mode = mode;
	ks->ks_value = value;
	cv_init(&ks->ks_cv, "ksem");
	vfs_timestamp(&ks->ks_birthtime);
	ks->ks_atime = ks->ks_mtime = ks->ks_ctime = ks->ks_birthtime;
	refcount_init(&ks->ks_ref, 1);
#ifdef MAC
	mac_posixsem_init(ks);
	mac_posixsem_create(ucred, ks);
#endif
	return (ks);
}
static struct ksem * ksem_alloc ( struct ucred * ucred , mode_t mode , unsigned int value ) { struct ksem * ks ; mtx_lock ( & ksem_count_lock ) ; if ( nsems == p31b_getcfg ( CTL_P1003_1B_SEM_NSEMS_MAX ) || ksem_dead ) { mtx_unlock ( & ksem_count_lock ) ; return ( NULL ) ; } nsems ++ ; mtx_unlock ( & ksem_count_lock ) ; ks = malloc ( sizeof ( * ks ) , M_KSEM , M_WAITOK | M_ZERO ) ; ks -> ks_uid = ucred -> cr_uid ; ks -> ks_gid = ucred -> cr_gid ; ks -> ks_mode = mode ; ks -> ks_value = value ; cv_init ( & ks -> ks_cv , " " ) ; vfs_timestamp ( & ks -> ks_birthtime ) ; ks -> ks_atime = ks -> ks_mtime = ks -> ks_ctime = ks -> ks_birthtime ; refcount_init ( & ks -> ks_ref , 1 ) ; #ifdef MAC mac_posixsem_init ( ks ) ; mac_posixsem_create ( ucred , ks ) ; #endif return ( ks ) ; }
ksem object management including creation and reference counting
 routines.
ksem object management including creation and reference counting routines .