-
Notifications
You must be signed in to change notification settings - Fork 0
/
threads.hpp
92 lines (69 loc) · 2.09 KB
/
threads.hpp
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
/*
This file is part of OmpSs-2 Linter and is licensed under
the terms contained in the COPYING file.
Copyright (C) 2019 Barcelona Supercomputing Center (BSC)
*/
INLINE
thread_data_t *thread_create(uint32_t id, uint64_t stackbase) {
thread_data_t *thread = new thread_data_t;
thread->id = id;
thread->task = NULL;
thread->stackbase = stackbase;
thread->calls = thread->zeros = 0;
thread->next_task_verified = false;
thread->dymreq.type = DYNMEM_REQUEST_NONE;
if (utils_open_pipe(&thread->read_fd, &thread->write_fd)) {
error(thread, NULL,
"Unable to create pipe.");
}
char filepath[MAX_PATH_LENGTH];
snprintf(filepath, MAX_PATH_LENGTH,
"%s/%s.%u.log",
config.logs_dir, config.experiment_name, thread->id);
char *tmp_file_path = (char *)malloc(strlen(filepath) + 1);
strcpy(tmp_file_path, filepath);
thread->log_file_path = tmp_file_path;
if (utils_open_fd(thread->log_file_path, "w+", &thread->log_fd)) {
error(thread, NULL,
"Unable to create log file '%s'", thread->log_file_path);
}
return thread;
}
INLINE
void thread_destroy(thread_data_t *thread) {
if (utils_close_fd(thread->read_fd)) {
error(thread, NULL,
"Unable to close read end of pipe.");
}
if (utils_close_fd(thread->write_fd)) {
error(thread, NULL,
"Unable to close read end of pipe.");
}
if (utils_close_fd(thread->log_fd)) {
error(thread, NULL,
"Unable to close log file '%s'", thread->log_file_path);
}
delete thread;
}
INLINE
void thread_push_task(thread_data_t *thread, task_data_t *task) {
// if (thread->task) {
// If we were executing another task (a parent task)
// we temporarily store its meta-data.
// We need this check because when the 'main' task is
// executed for the first time, the current thread doesn't
// have a binding to a task yet.
task->prev = thread->task;
// }
// The thread is now executing another task
thread->task = task;
}
INLINE
void thread_pop_task(thread_data_t *thread) {
// Restore any parent task that was suspended to execute the
// current task
thread->task = thread->task->prev;
}
INLINE
void thread_write_log(const char *format, ...) {
}