1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
26 #define SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
27
28 #include "memory/allocation.hpp"
29
30 // A SuspendibleThreadSet is a set of threads that can be suspended.
31 // A thread can join and later leave the set, and periodically yield.
32 // If some thread (not in the set) requests, via synchronize(), that
33 // the threads be suspended, then the requesting thread is blocked
34 // until all the threads in the set have yielded or left the set. Threads
35 // may not enter the set when an attempted suspension is in progress. The
36 // suspending thread later calls desynchronize(), allowing the suspended
37 // threads to continue.
38 class SuspendibleThreadSet : public AllStatic {
39 friend class SuspendibleThreadSetJoiner;
40 friend class SuspendibleThreadSetLeaver;
41
42 private:
43 static uint _nthreads;
44 static uint _nthreads_stopped;
45 static bool _suspend_all;
46 static double _suspend_all_start;
99 };
100
101 class SuspendibleThreadSetLeaver : public StackObj {
102 private:
103 bool _active;
104
105 public:
106 SuspendibleThreadSetLeaver(bool active = true) : _active(active) {
107 if (_active) {
108 SuspendibleThreadSet::leave();
109 }
110 }
111
112 ~SuspendibleThreadSetLeaver() {
113 if (_active) {
114 SuspendibleThreadSet::join();
115 }
116 }
117 };
118
119 #endif // SHARE_VM_GC_G1_SUSPENDIBLETHREADSET_HPP
|
1 /*
2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_COMMON_SUSPENDIBLETHREADSET_HPP
26 #define SHARE_GC_COMMON_SUSPENDIBLETHREADSET_HPP
27
28 #include "memory/allocation.hpp"
29
30 // A SuspendibleThreadSet is a set of threads that can be suspended.
31 // A thread can join and later leave the set, and periodically yield.
32 // If some thread (not in the set) requests, via synchronize(), that
33 // the threads be suspended, then the requesting thread is blocked
34 // until all the threads in the set have yielded or left the set. Threads
35 // may not enter the set when an attempted suspension is in progress. The
36 // suspending thread later calls desynchronize(), allowing the suspended
37 // threads to continue.
38 class SuspendibleThreadSet : public AllStatic {
39 friend class SuspendibleThreadSetJoiner;
40 friend class SuspendibleThreadSetLeaver;
41
42 private:
43 static uint _nthreads;
44 static uint _nthreads_stopped;
45 static bool _suspend_all;
46 static double _suspend_all_start;
99 };
100
101 class SuspendibleThreadSetLeaver : public StackObj {
102 private:
103 bool _active;
104
105 public:
106 SuspendibleThreadSetLeaver(bool active = true) : _active(active) {
107 if (_active) {
108 SuspendibleThreadSet::leave();
109 }
110 }
111
112 ~SuspendibleThreadSetLeaver() {
113 if (_active) {
114 SuspendibleThreadSet::join();
115 }
116 }
117 };
118
119 #endif // SHARE_GC_COMMON_SUSPENDIBLETHREADSET_HPP
|