1 /** 2 * Copyright (c) 2021-2025 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 ark { 23 24 #ifndef ARK_HYBRID 25 class PANDA_PUBLIC_API MutatorLock : public os::memory::RWLock { 26 using LockT = os::memory::RWLock; 27 #else 28 class PANDA_PUBLIC_API MutatorLock : public os::memory::DummyLock { 29 using LockT = os::memory::DummyLock; 30 #endif 31 #ifndef NDEBUG 32 public: 33 enum MutatorLockState {UNLOCKED, RDLOCK, WRLOCK}; 34 35 void ReadLock() ACQUIRE_SHARED(); 36 37 void WriteLock() ACQUIRE(); 38 39 bool TryReadLock() TRY_ACQUIRE_SHARED(true); 40 41 bool TryWriteLock() TRY_ACQUIRE(true); 42 43 void Unlock() RELEASE_GENERIC(); 44 45 MutatorLockState GetState() const; 46 47 bool HasLock() const; 48 #endif // !NDEBUG 49 }; 50 51 class PANDA_PUBLIC_API Locks { 52 public: 53 static void Initialize(); 54 55 static MutatorLock *NewMutatorLock(); 56 57 /// Lock used for preventing custom_tls_cache_ modifications 58 static os::memory::Mutex *customTlsLock_; // NOLINT(misc-non-private-member-variables-in-classes) 59 60 /** 61 * The lock is a specific lock for exclusive suspension process, 62 * It is static for access from JVMTI interface 63 */ 64 static os::memory::Mutex *userSuspensionLock_; 65 }; 66 67 } // namespace ark 68 69 #endif // PANDA_RUNTIME_LOCKS_H_ 70