author | kbarrett |
Thu, 23 Aug 2018 18:14:53 -0400 | |
changeset 51511 | eb8d5aeabab3 |
parent 50429 | 83aec1d357d4 |
child 51548 | 35a6956f4243 |
permissions | -rw-r--r-- |
49800 | 1 |
/* |
2 |
* Copyright (c) 2018, 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_UTILITIES_GLOBAL_COUNTER_INLINE_HPP |
|
26 |
#define SHARE_UTILITIES_GLOBAL_COUNTER_INLINE_HPP |
|
27 |
||
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
49812
diff
changeset
|
28 |
#include "runtime/orderAccess.hpp" |
49812
0c2ceb50783e
8201799: Build failures after JDK-8195099 (Concurrent safe-memory-reclamation mechanism)
shade
parents:
49800
diff
changeset
|
29 |
#include "runtime/thread.inline.hpp" |
49800 | 30 |
#include "utilities/globalCounter.hpp" |
31 |
||
32 |
inline void GlobalCounter::critical_section_begin(Thread *thread) { |
|
33 |
assert(thread == Thread::current(), "must be current thread"); |
|
51511
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50429
diff
changeset
|
34 |
assert(thread->is_Named_thread() || thread->is_Java_thread(), "must be NamedThread or JavaThread"); |
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50429
diff
changeset
|
35 |
assert((*thread->get_rcu_counter() & COUNTER_ACTIVE) == 0x0, "nested critical sections, not supported yet"); |
49800 | 36 |
uintx gbl_cnt = OrderAccess::load_acquire(&_global_counter._counter); |
37 |
OrderAccess::release_store_fence(thread->get_rcu_counter(), gbl_cnt | COUNTER_ACTIVE); |
|
38 |
} |
|
39 |
||
40 |
inline void GlobalCounter::critical_section_end(Thread *thread) { |
|
41 |
assert(thread == Thread::current(), "must be current thread"); |
|
51511
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50429
diff
changeset
|
42 |
assert(thread->is_Named_thread() || thread->is_Java_thread(), "must be NamedThread or JavaThread"); |
eb8d5aeabab3
8209850: Allow NamedThreads to use GlobalCounter critical sections
kbarrett
parents:
50429
diff
changeset
|
43 |
assert((*thread->get_rcu_counter() & COUNTER_ACTIVE) == COUNTER_ACTIVE, "must be in critical section"); |
49800 | 44 |
// Mainly for debugging we set it to 'now'. |
45 |
uintx gbl_cnt = OrderAccess::load_acquire(&_global_counter._counter); |
|
46 |
OrderAccess::release_store(thread->get_rcu_counter(), gbl_cnt); |
|
47 |
} |
|
48 |
||
49 |
class GlobalCounter::CriticalSection { |
|
50 |
private: |
|
51 |
Thread* _thread; |
|
52 |
public: |
|
53 |
inline CriticalSection(Thread* thread) : _thread(thread) { |
|
54 |
GlobalCounter::critical_section_begin(_thread); |
|
55 |
} |
|
56 |
inline ~CriticalSection() { |
|
57 |
GlobalCounter::critical_section_end(_thread); |
|
58 |
} |
|
59 |
}; |
|
60 |
||
61 |
#endif // include guard |