1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_GC_SCOPED_GC_CRITICAL_SECTION_H_
18 #define ART_RUNTIME_GC_SCOPED_GC_CRITICAL_SECTION_H_
19 
20 #include "base/mutex.h"
21 #include "collector_type.h"
22 #include "gc_cause.h"
23 
24 namespace art {
25 
26 class Thread;
27 
28 namespace gc {
29 
30 // Wait until the GC is finished and then prevent the GC from starting until the destructor. Used
31 // to prevent deadlocks in places where we call ClassLinker::VisitClass with all the threads
32 // suspended.
33 class ScopedGCCriticalSection {
34  public:
35   ScopedGCCriticalSection(Thread* self, GcCause cause, CollectorType collector_type)
36       ACQUIRE(Roles::uninterruptible_);
37   ~ScopedGCCriticalSection() RELEASE(Roles::uninterruptible_);
38 
39  private:
40   Thread* const self_;
41   const char* old_cause_;
42 };
43 
44 }  // namespace gc
45 }  // namespace art
46 
47 #endif  // ART_RUNTIME_GC_SCOPED_GC_CRITICAL_SECTION_H_
48