FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
numalloc/source-reducememory/xthread.cpp at master · UTSASRG/numalloc · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
UTSASRG
/
numalloc
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
3
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
numalloc
/
source-reducememory
/
xthread.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
97 lines (82 loc) · 2.96 KB
Breadcrumbs
numalloc
/
source-reducememory
/
xthread.cpp
Copy path
File metadata and controls
97 lines (82 loc) · 2.96 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* FreeGuard: A Faster Secure Heap Allocator
* Copyright (C) 2017 Sam Silvestro, Hongyu Liu, Corey Crosser,
* Zhiqiang Lin, and Tongping Liu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @file xthread.cpp: thread-related function implementation.
* @author Tongping Liu <http://www.cs.utsa.edu/~tongpingliu/>
*/
#
include
"
xthread.hh
"
#
include
"
numaheap.hh
"
char
*
getThreadBuffer
() {
return
current->
outputBuf
;
}
int
getThreadIndex
(
void
) {
return
current->
index
;
}
int
getNodeIndex
(
void
) {
return
current->
nindex
;
}
int
xthread::thread_create
(
pthread_t
* thread,
const
pthread_attr_t
* attr, threadFunction * fn,
void
* arg) {
//
Since we will create the children threads, set this flag to be true.
//
This flag will change the allocation of the main thread, but should not affect
//
other threads.
if
(current->
hasChildrenthreads
==
false
)
current->
hasChildrenthreads
=
true
;
int
tindex =
allocThreadIndex
();
//
Acquire the thread structure.
thread_t
* children =
getThread
(tindex);
children->
index
= tindex;
children->
startArg
= arg;
children->
startRoutine
= fn;
//
If there are two threads right now, we will stop the main heap phase.
#
ifdef
INTERHEAP_SUPPORT
if
(_alives ==
2
) {
NumaHeap::getInstance
().
stopSerialPhase
();
}
#
endif
//
Create the thread and bind the thread to the specific node (passed by _tattrs[nodeindex])
int
result =
Real::pthread_create
(thread, &_tattrs[children->
nindex
], xthread::startThread, (
void
*)children);
if
(result) {
fprintf
(stderr,
"
pthread_create failed with error code %d
\n
"
, result);
exit
(-
1
);
}
//
Setting up this in the creater thread so that
//
pthread_join can always find its pthread_t.
//
Otherwise, it may fail if the child haven't set this value before the join
children->
thread
= *thread;
return
result;
}
int
xthread::thread_join
(
pthread_t
thread,
void
** retval) {
int
ret;
if
((ret =
Real::pthread_join
(thread, retval)) ==
0
) {
int
joinee = -
1
;
//
Clean up the thread entry so that the future threads
//
can utilize the same entry, and also the
lock
();
joinee =
findJoineeIndex
(thread);
_threads[joinee].
available
=
true
;
_alives--;
unlock
();
}
#
ifdef
INTERHEAP_SUPPORT
if
(_alives ==
1
) {
NumaHeap::getInstance
().
startSerialPhase
();
}
#
endif
return
ret;
}
Back
|
FazBrowse Home
|
New Git URL