void rw_lock_init(rw_lock* lock, const char* name) { lock->name = name; lock->waiters = NULL; lock->holder = -1; lock->count = 0; lock->owner_count = 0; lock->active_readers = 0; lock->pending_readers = 0; lock->flags = 0; T_SCHEDULING_ANALYSIS(InitRWLock(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::RWLockInitialized, lock); }
void rw_lock_init_etc(rw_lock* lock, const char* name, uint32 flags) { lock->name = (flags & RW_LOCK_FLAG_CLONE_NAME) != 0 ? strdup(name) : name; lock->waiters = NULL; lock->holder = -1; lock->count = 0; lock->owner_count = 0; lock->active_readers = 0; lock->pending_readers = 0; lock->flags = flags & RW_LOCK_FLAG_CLONE_NAME; T_SCHEDULING_ANALYSIS(InitRWLock(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::RWLockInitialized, lock); }
void mutex_init_etc(mutex* lock, const char *name, uint32 flags) { lock->name = (flags & MUTEX_FLAG_CLONE_NAME) != 0 ? strdup(name) : name; lock->waiters = NULL; #if KDEBUG lock->holder = -1; #else lock->count = 0; lock->ignore_unlock_count = 0; #endif lock->flags = flags & MUTEX_FLAG_CLONE_NAME; T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::MutexInitialized, lock); }
void mutex_init(mutex* lock, const char *name) { lock->name = name; lock->waiters = NULL; #if KDEBUG lock->holder = -1; #else lock->count = 0; lock->ignore_unlock_count = 0; #endif lock->flags = 0; T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::MutexInitialized, lock); }
/*! Creates a semaphore with the given parameters. This function is only available from within the kernel, and should not be made public - if possible, we should remove it completely (and have only create_sem() exported). */ sem_id create_sem_etc(int32 count, const char* name, team_id owner) { struct sem_entry* sem = NULL; cpu_status state; sem_id id = B_NO_MORE_SEMS; char* tempName; size_t nameLength; if (sSemsActive == false || sUsedSems == sMaxSems) return B_NO_MORE_SEMS; if (name == NULL) name = "unnamed semaphore"; // get the owning team Team* team = Team::Get(owner); if (team == NULL) return B_BAD_TEAM_ID; BReference<Team> teamReference(team, true); // clone the name nameLength = strlen(name) + 1; nameLength = min_c(nameLength, B_OS_NAME_LENGTH); tempName = (char*)malloc(nameLength); if (tempName == NULL) return B_NO_MEMORY; strlcpy(tempName, name, nameLength); state = disable_interrupts(); GRAB_SEM_LIST_LOCK(); // get the first slot from the free list sem = sFreeSemsHead; if (sem) { // remove it from the free list sFreeSemsHead = sem->u.unused.next; if (!sFreeSemsHead) sFreeSemsTail = NULL; // init the slot GRAB_SEM_LOCK(*sem); sem->id = sem->u.unused.next_id; sem->u.used.count = count; sem->u.used.net_count = count; new(&sem->queue) ThreadQueue; sem->u.used.name = tempName; sem->u.used.owner = team->id; sem->u.used.select_infos = NULL; id = sem->id; list_add_item(&team->sem_list, &sem->u.used.team_link); RELEASE_SEM_LOCK(*sem); atomic_add(&sUsedSems, 1); KTRACE("create_sem_etc(count: %ld, name: %s, owner: %ld) -> %ld", count, name, owner, id); T_SCHEDULING_ANALYSIS(CreateSemaphore(id, name)); NotifyWaitObjectListeners(&WaitObjectListener::SemaphoreCreated, id, name); } RELEASE_SEM_LIST_LOCK(); restore_interrupts(state); if (sem == NULL) free(tempName); return id; }