Lines Matching refs:sema
25 Semaphore_Init(Semaphore *sema, int count, const char *name)
27 Spinlock_Init(&sema->lock, name, SPINLOCK_TYPE_NORMAL);
28 sema->count = count;
30 strncpy(&sema->name[0], name, SEMAPHORE_NAMELEN);
31 TAILQ_INIT(&sema->waiters);
34 LIST_INSERT_HEAD(&semaList, sema, semaphoreList);
39 Semaphore_Destroy(Semaphore *sema)
42 LIST_REMOVE(sema, semaphoreList);
45 Spinlock_Destroy(&sema->lock);
49 Semaphore_Acquire(Semaphore *sema)
54 Spinlock_Lock(&sema->lock);
55 if (sema->count > 0) {
56 sema->count -= 1;
57 Spinlock_Unlock(&sema->lock);
63 TAILQ_INSERT_TAIL(&sema->waiters, cur, semaQueue);
66 Spinlock_Unlock(&sema->lock);
72 Semaphore_Release(Semaphore *sema)
76 Spinlock_Lock(&sema->lock);
77 sema->count += 1;
80 thr = TAILQ_FIRST(&sema->waiters);
82 TAILQ_REMOVE(&sema->waiters, thr, semaQueue);
85 Spinlock_Unlock(&sema->lock);
89 Semaphore_TryAcquire(Semaphore *sema)
91 Spinlock_Lock(&sema->lock);
92 if (sema->count > 0) {
93 sema->count -= 1;
94 Spinlock_Unlock(&sema->lock);
97 Spinlock_Unlock(&sema->lock);
104 Semaphore *sema;
109 LIST_FOREACH(sema, &semaList, semaphoreList)
112 kprintf("%-36s %8d\n", sema->name, sema->count);
113 TAILQ_FOREACH(thr, &sema->waiters, semaQueue) {