• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "global_object_lock.h"
17 
18 namespace panda {
19 
20 // Use some global lock as fast solution.
21 static os::memory::Mutex mtx;             // NOLINT(fuchsia-statically-constructed-objects)
22 static os::memory::ConditionVariable cv;  // NOLINT(fuchsia-statically-constructed-objects)
23 
GlobalObjectLock(const ObjectHeader * obj)24 GlobalObjectLock::GlobalObjectLock([[maybe_unused]] const ObjectHeader *obj)
25 {
26     mtx.Lock();
27 }
28 
Wait(bool ignore_interruption)29 void GlobalObjectLock::Wait([[maybe_unused]] bool ignore_interruption)
30 {
31     cv.Wait(&mtx);
32 }
33 
TimedWait(uint64_t timeout)34 void GlobalObjectLock::TimedWait(uint64_t timeout)
35 {
36     cv.TimedWait(&mtx, timeout);
37 }
38 
Notify()39 void GlobalObjectLock::Notify()
40 {
41     cv.Signal();
42 }
43 
NotifyAll()44 void GlobalObjectLock::NotifyAll()
45 {
46     cv.SignalAll();
47 }
48 
~GlobalObjectLock()49 GlobalObjectLock::~GlobalObjectLock()
50 {
51     mtx.Unlock();
52 }
53 
54 }  // namespace panda
55