Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (71 sloc) 2.312 kB
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
1 #include "prelude.hpp"
2 #include "auxiliary_threads.hpp"
3
4 namespace rubinius {
5 void AuxiliaryThreads::register_thread(AuxiliaryThread* thread) {
6 threads_.insert(thread);
7 }
8
9 void AuxiliaryThreads::unregister_thread(AuxiliaryThread* thread) {
10 threads_.erase(thread);
11 }
12
13 void AuxiliaryThreads::shutdown(STATE) {
cb9e8b0 @ryoqun Move thread under rubinius::utilities::thread
ryoqun authored
14 utilities::thread::Mutex::LockGuard guard(mutex_);
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
15
16 if(shutdown_in_progress_) return;
17 shutdown_in_progress_ = true;
18
19 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
20 i != threads_.end();
21 ++i) {
22 (*i)->shutdown(state);
23 }
24
25 shutdown_in_progress_ = false;
26 }
27
28 void AuxiliaryThreads::before_exec(STATE) {
cb9e8b0 @ryoqun Move thread under rubinius::utilities::thread
ryoqun authored
29 utilities::thread::Mutex::LockGuard guard(mutex_);
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
30
31 if(exec_in_progress_) return;
32 exec_in_progress_ = true;
33
34 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
35 i != threads_.end();
36 ++i) {
37 (*i)->before_exec(state);
38 }
39 }
40
41 void AuxiliaryThreads::after_exec(STATE) {
42 // We don't guard here on the assumption that only one thread is running
43 // after execvp() call.
44 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
45 i != threads_.end();
46 ++i) {
47 (*i)->after_exec(state);
48 }
49
50 exec_in_progress_ = false;
51 }
52
53 void AuxiliaryThreads::before_fork(STATE) {
cb9e8b0 @ryoqun Move thread under rubinius::utilities::thread
ryoqun authored
54 utilities::thread::Mutex::LockGuard guard(mutex_);
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
55
56 if(fork_in_progress_) return;
57 fork_in_progress_ = true;
58
59 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
60 i != threads_.end();
61 ++i) {
62 (*i)->before_fork(state);
63 }
64 }
65
66 void AuxiliaryThreads::after_fork_parent(STATE) {
67 // We don't guard here on the assumption that only one thread is running
68 // after fork() call.
69 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
70 i != threads_.end();
71 ++i) {
72 (*i)->after_fork_parent(state);
73 }
74
75 fork_in_progress_ = false;
76 }
77
78 void AuxiliaryThreads::after_fork_child(STATE) {
79 // We don't guard here on the assumption that only one thread is running
80 // after fork() call.
81 for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
82 i != threads_.end();
83 ++i) {
84 (*i)->after_fork_child(state);
85 }
86
87 fork_in_progress_ = false;
88 }
89 }
Something went wrong with that request. Please try again.