intr_disable();
thread_block();
intr_set_level(old_level);
void thread_unblock(struct thread *t)
static void wake_up(int64_t cur_tick)
{
struct list_elem *e;
for (e = list_begin(&block_thread_list); e != list_end(&block_thread_list);)
{
block_thread *entry = list_entry(e, block_thread, elem);
struct list_elem *next = list_next(e);
if (entry->wakeup_tick <= cur_tick)
{
thread_unblock(entry->block_threads);
list_remove(e);
//free(e) -> 절대 하면 안됨 !!
}
else
break;
e = next;
}
if (list_empty(&block_thread_list)) // 리스트가 비어있을 경우
closet_tick = NULL; // 깨워야할 틱이 없으니까 -1로
else // 있을 경우
{
e = list_front(&block_thread_list); // 맨 앞의 엔트리를 가져와서 전역 틱에 저장
block_thread *entry = list_entry(e, block_thread, elem);
closet_tick = entry->wakeup_tick;
}
}
이 wake_up 함수는 timer_interrupt 내에서 실행되고 있음
timer_interrupt 함수는 인터럽트 핸들러이므로 내에서는 락을 걸면 안됨!! 하지만 free, malloc 같은 함수는 내부적으로 락을 잡고 진행함 !!
free_list를 하나 따로 만들어서 거기에 등록한 후, 나중에 해제해 주어야 함…
힙 메모리는 전역 자원이기 때문에 공유 자원 (임계구역) 이니까 !!
typedef struct block_threads_struct
{
struct thread *block_threads;
int64_t wakeup_tick;
struct list_elem elem;
} block_thread;