• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef PANDA_RUNTIME_LOCKS_H_
16 #define PANDA_RUNTIME_LOCKS_H_
17 
18 #include "libpandabase/os/mutex.h"
19 
20 #include <memory>
21 
22 namespace panda {
23 
24 class MutatorLock : public os::memory::RWLock {
25 #ifndef NDEBUG
26 public:
27     enum MutatorLockState { UNLOCKED, RDLOCK, WRLOCK };
28 
29     void ReadLock() ACQUIRE_SHARED();
30 
31     void WriteLock() ACQUIRE();
32 
33     bool TryReadLock() TRY_ACQUIRE_SHARED(true);
34 
35     bool TryWriteLock() TRY_ACQUIRE(true);
36 
37     void Unlock() RELEASE_GENERIC();
38 
39     MutatorLockState GetState();
40 
41     bool HasLock();
42 #endif  // !NDEBUG
43 };
44 
45 class Locks {
46 public:
47     static void Initialize();
48 
49     /**
50      * Lock used for preventing object heap modifications (for example at GC<->JIT,ManagedCode interaction during STW)
51      */
52     static MutatorLock *mutator_lock;  // NOLINT(misc-non-private-member-variables-in-classes)
53     /**
54      * Lock used for preventing custom_tls_cache_ modifications
55      */
56     static os::memory::Mutex *custom_tls_lock;  // NOLINT(misc-non-private-member-variables-in-classes)
57 
58     /**
59      * The lock is a specific lock for exclusive suspension process,
60      * It is static for access from JVMTI interface
61      */
62     static os::memory::Mutex *user_suspension_lock;
63 };
64 
65 }  // namespace panda
66 
67 #endif  // PANDA_RUNTIME_LOCKS_H_
68