1 /* |
1 /* |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
31 uint SuspendibleThreadSet::_nthreads_stopped = 0; |
31 uint SuspendibleThreadSet::_nthreads_stopped = 0; |
32 bool SuspendibleThreadSet::_suspend_all = false; |
32 bool SuspendibleThreadSet::_suspend_all = false; |
33 double SuspendibleThreadSet::_suspend_all_start = 0.0; |
33 double SuspendibleThreadSet::_suspend_all_start = 0.0; |
34 |
34 |
35 void SuspendibleThreadSet::join() { |
35 void SuspendibleThreadSet::join() { |
|
36 assert(!Thread::current()->is_suspendible_thread(), "Thread already joined"); |
36 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
37 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
37 while (_suspend_all) { |
38 while (_suspend_all) { |
38 ml.wait(Mutex::_no_safepoint_check_flag); |
39 ml.wait(Mutex::_no_safepoint_check_flag); |
39 } |
40 } |
40 _nthreads++; |
41 _nthreads++; |
|
42 DEBUG_ONLY(Thread::current()->set_suspendible_thread();) |
41 } |
43 } |
42 |
44 |
43 void SuspendibleThreadSet::leave() { |
45 void SuspendibleThreadSet::leave() { |
|
46 assert(Thread::current()->is_suspendible_thread(), "Thread not joined"); |
44 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
47 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
45 assert(_nthreads > 0, "Invalid"); |
48 assert(_nthreads > 0, "Invalid"); |
|
49 DEBUG_ONLY(Thread::current()->clear_suspendible_thread();) |
46 _nthreads--; |
50 _nthreads--; |
47 if (_suspend_all) { |
51 if (_suspend_all) { |
48 ml.notify_all(); |
52 ml.notify_all(); |
49 } |
53 } |
50 } |
54 } |
51 |
55 |
52 void SuspendibleThreadSet::yield() { |
56 void SuspendibleThreadSet::yield() { |
|
57 assert(Thread::current()->is_suspendible_thread(), "Must have joined"); |
53 if (_suspend_all) { |
58 if (_suspend_all) { |
54 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
59 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag); |
55 if (_suspend_all) { |
60 if (_suspend_all) { |
56 _nthreads_stopped++; |
61 _nthreads_stopped++; |
57 if (_nthreads_stopped == _nthreads) { |
62 if (_nthreads_stopped == _nthreads) { |