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 16 #include "runtime/mem/rendezvous.h" 17 18 #include "runtime/include/runtime.h" 19 #include "runtime/include/panda_vm.h" 20 21 namespace panda { 22 SafepointBegin()23void Rendezvous::SafepointBegin() 24 { 25 ASSERT(!Locks::mutator_lock->HasLock()); 26 LOG(DEBUG, GC) << "Rendezvous: SafepointBegin"; 27 // Suspend all threads 28 Thread::GetCurrent()->GetVM()->GetThreadManager()->SuspendAllThreads(); 29 // Acquire write MutatorLock 30 Locks::mutator_lock->WriteLock(); 31 } 32 SafepointEnd()33void Rendezvous::SafepointEnd() 34 { 35 ASSERT(Locks::mutator_lock->HasLock()); 36 LOG(DEBUG, GC) << "Rendezvous: SafepointEnd"; 37 // Release write MutatorLock 38 Locks::mutator_lock->Unlock(); 39 // Resume all threads 40 Thread::GetCurrent()->GetVM()->GetThreadManager()->ResumeAllThreads(); 41 LOG(DEBUG, GC) << "Rendezvous: SafepointEnd exit"; 42 } 43 ScopedSuspendAllThreadsRunning(Rendezvous * rendezvous)44ScopedSuspendAllThreadsRunning::ScopedSuspendAllThreadsRunning(Rendezvous *rendezvous) : rendezvous_(rendezvous) 45 { 46 ASSERT(rendezvous_ != nullptr); 47 ASSERT(Locks::mutator_lock->HasLock()); 48 Locks::mutator_lock->Unlock(); 49 rendezvous_->SafepointBegin(); 50 } 51 ~ScopedSuspendAllThreadsRunning()52ScopedSuspendAllThreadsRunning::~ScopedSuspendAllThreadsRunning() 53 { 54 rendezvous_->SafepointEnd(); 55 Locks::mutator_lock->ReadLock(); 56 } 57 58 } // namespace panda 59