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