-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_impl.h
45 lines (35 loc) · 996 Bytes
/
cpu_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef _CPU_IMPL_H
#define _CPU_IMPL_H
#include <ucontext.h>
#include <atomic>
#include <queue>
#include <cassert>
#include <iostream>
#include <stdexcept>
#include "cpu.h"
using namespace std;
class cpu::impl {
public:
impl(){}
~impl(){}
/*
* A helper function for the context switching.
* Switch from the current context to the context at the front of the ready_queue
* If ready_queue is empty, return to the main context (init) of the cpu.
*/
static void switch_context(ucontext_t* cur);
/*
* A helper function to delete threads in finished_queue.
*/
static void delete_finished();
/*
* A helper function to signal a suspending cpu in the suspended_queue
*/
static void cpu_wakeup();
static queue<ucontext_t*> ready_queue;
static queue<ucontext_t*> finished_queue;
static queue<cpu*> suspended_queue;
ucontext_t *cur_context; // store the current context
ucontext_t *main_context; // the main context that cpu is running in (init)
};
#endif