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 PANDA_PUBLIC_API 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() const; 40 41 bool HasLock() const; 42 #endif // !NDEBUG 43 }; 44 45 class PANDA_PUBLIC_API Locks { 46 public: 47 static void Initialize(); 48 49 static MutatorLock *NewMutatorLock(); 50 51 /// Lock used for preventing custom_tls_cache_ modifications 52 static os::memory::Mutex *customTlsLock_; // NOLINT(misc-non-private-member-variables-in-classes) 53 54 /** 55 * The lock is a specific lock for exclusive suspension process, 56 * It is static for access from JVMTI interface 57 */ 58 static os::memory::Mutex *userSuspensionLock_; 59 }; 60 61 } // namespace panda 62 63 #endif // PANDA_RUNTIME_LOCKS_H 64