-
Notifications
You must be signed in to change notification settings - Fork 608
/
auxiliary_threads.cpp
93 lines (74 loc) · 2.35 KB
/
auxiliary_threads.cpp
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
#include "prelude.hpp"
#include "auxiliary_threads.hpp"
namespace rubinius {
void AuxiliaryThreads::register_thread(AuxiliaryThread* thread) {
threads_.push_back(thread);
}
void AuxiliaryThreads::unregister_thread(AuxiliaryThread* thread) {
threads_.remove(thread);
}
void AuxiliaryThreads::shutdown(STATE) {
utilities::thread::Mutex::LockGuard guard(mutex_);
if(shutdown_in_progress_) return;
shutdown_in_progress_ = true;
for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
i != threads_.rend();
++i) {
(*i)->shutdown(state);
}
shutdown_in_progress_ = false;
}
void AuxiliaryThreads::before_exec(STATE) {
utilities::thread::Mutex::LockGuard guard(mutex_);
if(exec_in_progress_) return;
exec_in_progress_ = true;
for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
i != threads_.rend();
++i) {
(*i)->before_exec(state);
}
}
void AuxiliaryThreads::after_exec(STATE) {
// We don't guard here on the assumption that only one thread is running
// after execvp() call.
for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_exec(state);
}
exec_in_progress_ = false;
}
void AuxiliaryThreads::before_fork(STATE) {
utilities::thread::Mutex::LockGuard guard(mutex_);
if(fork_in_progress_) return;
fork_in_progress_ = true;
for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
i != threads_.rend();
++i) {
(*i)->before_fork(state);
}
}
void AuxiliaryThreads::after_fork_parent(STATE) {
// We don't guard here on the assumption that only one thread is running
// after fork() call.
for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_fork_parent(state);
}
fork_in_progress_ = false;
}
void AuxiliaryThreads::after_fork_child(STATE) {
// We don't guard here on the assumption that only one thread is running
// after fork() call.
for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_fork_child(state);
}
fork_in_progress_ = false;
}
void AuxiliaryThreads::init() {
mutex_.init();
}
}