• 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 #ifndef PANDA_RUNTIME_HANDLE_SCOPE_INL_H_
17 #define PANDA_RUNTIME_HANDLE_SCOPE_INL_H_
18 
19 #include "runtime/handle_scope.h"
20 #include "runtime/include/thread-inl.h"
21 
22 namespace panda {
23 template <typename T>
HandleScope(ManagedThread * thread)24 inline HandleScope<T>::HandleScope(ManagedThread *thread) : thread_(thread)
25 {
26     HandleScope<T> *topScope = thread->GetTopScope<T>();
27     if (topScope != nullptr) {
28         beginIndex_ = topScope->GetBeginIndex() + topScope->GetHandleCount();
29     }
30     thread->PushHandleScope<T>(this);
31 }
32 
33 template <typename T>
HandleScope(ManagedThread * thread,T value)34 inline HandleScope<T>::HandleScope(ManagedThread *thread, T value) : thread_(thread)
35 {
36     HandleScope<T> *topScope = thread->GetTopScope<T>();
37     ASSERT(topScope != nullptr);
38     topScope->NewHandle(value);
39     beginIndex_ = topScope->GetBeginIndex() + topScope->GetHandleCount();
40     thread->PushHandleScope<T>(this);
41 }
42 
43 template <typename T>
~HandleScope()44 inline HandleScope<T>::~HandleScope()
45 {
46     thread_->PopHandleScope<T>();
47     thread_->GetHandleStorage<T>()->FreeHandles(beginIndex_);
48 }
49 
50 template <typename T>
GetThread()51 inline ManagedThread *HandleScope<T>::GetThread() const
52 {
53     return thread_;
54 }
55 
56 template <typename T>
EscapeHandleScope(ManagedThread * thread)57 inline EscapeHandleScope<T>::EscapeHandleScope(ManagedThread *thread)
58     : HandleScope<T>(thread, 0),
59       escapeHandle_(thread->GetHandleStorage<T>()->GetNodeAddress(thread->GetTopScope<T>()->GetBeginIndex() - 1))
60 {
61 }
62 
63 }  // namespace panda
64 
65 #endif  // PANDA_RUNTIME_HANDLE_SCOPE_INL_H_
66