• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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 "intrinsics.h"
17 #include "plugins/ets/runtime/types/ets_sync_primitives.h"
18 
19 namespace ark::ets::intrinsics {
20 
EtsMutexCreate()21 EtsObject *EtsMutexCreate()
22 {
23     return EtsMutex::Create(EtsCoroutine::GetCurrent());
24 }
25 
EtsMutexLock(EtsObject * mutex)26 void EtsMutexLock(EtsObject *mutex)
27 {
28     ASSERT(mutex->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetMutexClass());
29     EtsMutex::FromEtsObject(mutex)->Lock();
30 }
31 
EtsMutexUnlock(EtsObject * mutex)32 void EtsMutexUnlock(EtsObject *mutex)
33 {
34     ASSERT(mutex->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetMutexClass());
35     EtsMutex::FromEtsObject(mutex)->Unlock();
36 }
37 
EtsEventCreate()38 EtsObject *EtsEventCreate()
39 {
40     return EtsEvent::Create(EtsCoroutine::GetCurrent());
41 }
42 
EtsEventWait(EtsObject * event)43 void EtsEventWait(EtsObject *event)
44 {
45     ASSERT(event->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetEventClass());
46     EtsEvent::FromEtsObject(event)->Wait();
47 }
48 
EtsEventFire(EtsObject * event)49 void EtsEventFire(EtsObject *event)
50 {
51     ASSERT(event->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetEventClass());
52     EtsEvent::FromEtsObject(event)->Fire();
53 }
54 
EtsCondVarCreate()55 EtsObject *EtsCondVarCreate()
56 {
57     return EtsCondVar::Create(EtsCoroutine::GetCurrent());
58 }
59 
EtsCondVarWait(EtsObject * condVar,EtsObject * mutex)60 void EtsCondVarWait(EtsObject *condVar, EtsObject *mutex)
61 {
62     auto *coro = EtsCoroutine::GetCurrent();
63     ASSERT(condVar->GetClass() == coro->GetPandaVM()->GetClassLinker()->GetCondVarClass());
64     ASSERT(mutex->GetClass() == coro->GetPandaVM()->GetClassLinker()->GetMutexClass());
65     EtsHandleScope scope(coro);
66     EtsHandle<EtsMutex> hMutex(coro, EtsMutex::FromEtsObject(mutex));
67     EtsCondVar::FromEtsObject(condVar)->Wait(hMutex);
68 }
69 
EtsCondVarNotifyOne(EtsObject * condVar,EtsObject * mutex)70 void EtsCondVarNotifyOne(EtsObject *condVar, EtsObject *mutex)
71 {
72     ASSERT(condVar->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetCondVarClass());
73     ASSERT(mutex->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetMutexClass());
74     EtsCondVar::FromEtsObject(condVar)->NotifyOne(EtsMutex::FromEtsObject(mutex));
75 }
76 
EtsCondVarNotifyAll(EtsObject * condVar,EtsObject * mutex)77 void EtsCondVarNotifyAll(EtsObject *condVar, EtsObject *mutex)
78 {
79     ASSERT(condVar->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetCondVarClass());
80     ASSERT(mutex->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetMutexClass());
81     EtsCondVar::FromEtsObject(condVar)->NotifyAll(EtsMutex::FromEtsObject(mutex));
82 }
83 
84 }  // namespace ark::ets::intrinsics
85