[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
synch.h
Go to the documentation of this file.
1#ifndef THREADS_SYNCH_H
2#define THREADS_SYNCH_H
3
4#include <list.h>
5#include <stdbool.h>
6
7/* A counting semaphore. */
8struct semaphore {
9 unsigned value; /* Current value. */
10 struct list waiters; /* List of waiting threads. */
11};
12
13void sema_init (struct semaphore *, unsigned value);
14void sema_down (struct semaphore *);
15bool sema_try_down (struct semaphore *);
16void sema_up (struct semaphore *);
17void sema_self_test (void);
18
19/* Lock. */
20struct lock {
21 struct thread *holder; /* Thread holding lock (for debugging). */
22 struct semaphore semaphore; /* Binary semaphore controlling access. */
23};
24
25void lock_init (struct lock *);
26void lock_acquire (struct lock *);
27bool lock_try_acquire (struct lock *);
28void lock_release (struct lock *);
29bool lock_held_by_current_thread (const struct lock *);
30/*------------------------- [P1] Priority Scheduling --------------------------*/
31void donate_priority(void);
32void remove_with_lock(struct lock *);
33void refresh_priority(void);
34
35/* Condition variable. */
36struct condition {
37 struct list waiters; /* List of waiting threads. */
38};
39
40void cond_init (struct condition *);
41void cond_wait (struct condition *, struct lock *);
42void cond_signal (struct condition *, struct lock *);
43void cond_broadcast (struct condition *, struct lock *);
44
45/* Optimization barrier.
46 *
47 * The compiler will not reorder operations across an
48 * optimization barrier. See "Optimization Barriers" in the
49 * reference guide for more information.*/
50#define barrier() asm volatile ("" : : : "memory")
51
52#endif /* threads/synch.h */
Definition: synch.h:36
struct list waiters
Definition: synch.h:37
Definition: list.h:93
Definition: synch.h:20
struct thread * holder
Definition: synch.h:21
Definition: synch.h:8
unsigned value
Definition: synch.h:9
struct list waiters
Definition: synch.h:10
Definition: thread.h:100
bool lock_held_by_current_thread(const struct lock *)
Definition: synch.c:258
void lock_release(struct lock *)
Definition: synch.c:243
void cond_wait(struct condition *, struct lock *)
Definition: synch.c:371
void sema_up(struct semaphore *)
Definition: synch.c:114
void cond_init(struct condition *)
Definition: synch.c:344
void sema_down(struct semaphore *)
Definition: synch.c:68
bool sema_try_down(struct semaphore *)
Definition: synch.c:90
void lock_acquire(struct lock *)
Definition: synch.c:202
void donate_priority(void)
Definition: synch.c:269
void sema_init(struct semaphore *, unsigned value)
Definition: synch.c:52
void cond_signal(struct condition *, struct lock *)
void sema_self_test(void)
Definition: synch.c:141
void cond_broadcast(struct condition *, struct lock *)
Definition: synch.c:416
void remove_with_lock(struct lock *)
Definition: synch.c:289
bool lock_try_acquire(struct lock *)
Definition: synch.c:224
void refresh_priority(void)
Definition: synch.c:304
void lock_init(struct lock *)
Definition: synch.c:186