-
Notifications
You must be signed in to change notification settings - Fork 0
/
ufiber16.h
86 lines (63 loc) · 1.35 KB
/
ufiber16.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Program12 only one thread support
#include <iostream>
#include <vector>
#include <atomic>
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <chrono>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
using Function = add_pointer<void()>::type;
struct Context {
uint64_t rsp;
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t rbx;
uint64_t rbp;
uint32_t mxcsr;
uint32_t x87;
};
struct Thread {
Context context;
uint8_t* stack;
Thread(bool create_stack);
~Thread();
};
class UserThreading{
public:
Thread* volatile current_thread;
//volatile Thread* current_thread;
int current_thread_num;
Context *orginialContext;
Thread* sched_thread;
int sp_exit_threadnum;
pthread_spinlock_t *sp_spinlock;
volatile int sp_spinlock_check;
//
//__attribute__((align(64))) ????
//
//repr C ????
//
//rdtscp ??? number of cycles
//
volatile bool sp_exit_check;
Thread* volatile *foriegn_thread_ptr;
//volatile Thread** foriegn_thread_ptr;
UserThreading();
void Scheduler();
void Yield(bool cond);
void ThreadExit();
int makeThread(Function fn);
~UserThreading(){
}
void WaitLoop2();
//void WaitLoop3();
};