FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UserSpaceThread/task_system.cpp at main · ddeka0/UserSpaceThread · GitHub
ddeka0
/
UserSpaceThread
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
UserSpaceThread
/
task_system.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (72 loc) · 1.73 KB
Breadcrumbs
UserSpaceThread
/
task_system.cpp
Copy path
File metadata and controls
83 lines (72 loc) · 1.73 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
*
* @file task_system.cpp
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-02-14
*
*/
#
include
"
config.hpp
"
#
include
"
task_system.hpp
"
/*
*
* @brief
* Each Thread loop to get user space thread request in a queue
* @param i
* i = Thread Number
*/
void
task_system::run
(
unsigned
i) {
currContext[
KTHREAD
] =
new
ThreadCtx
();
currContext[
KTHREAD
]->
setState
(uState::
RUNNING
);
currContext[
UTHREAD
] =
nullptr
;
while
(
true
) {
ThreadCtx * ctx =
nullptr
;
if
(!_q.
pop
(&ctx))
break
;
if
(ctx ==
nullptr
) {
Log
(
"
ctx is nullptr
"
);
}
else
if
(ctx->
getState
() != uState::
COMPLETE
) {
u_yield_to
(ctx);
if
(ctx->
getState
() != uState::
COMPLETE
) {
//
push tp queue again
_q.
push
(ctx);
std::this_thread::sleep_for
(
std::chrono::milliseconds
(
1000
));
}
else
{
Log
(
"
rsp =
"
,(
uint64_t
)(ctx->
getRegCtxPtr
()->
rsp
));
auto
stackbase = (
char
*)(ctx->
getRegCtxPtr
()->
rsp
) - StackSize;
//
delete stackbase;
delete
ctx;
}
}
}
delete
currContext[
KTHREAD
];
}
/*
*
* @brief Construct a new task system::task system object
*
*/
task_system::task_system
() {
for
(
unsigned
n =
0
;n !=
this
->
_count
;++n) {
_threads.
emplace_back
([&,n]() {
run
(n);
Log
(
"
work done!
"
);
});
}
}
/*
*
* @brief Destroy the task system object
*
*/
task_system::~task_system
() {
destruct
();
}
/*
*
* @brief
*
*/
void
task_system::destruct
() {
this
->
_q
.
done
();
//
wake up the threads
for
(
auto
& e :
this
->
_threads
) {
if
(e.
joinable
()) {
e.
join
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL