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 "plugins/ets/runtime/ets_vm.h" 17 #include "plugins/ets/runtime/ets_exceptions.h" 18 19 namespace ark::ets::intrinsics { 20 GenerateTaskId()21extern "C" EtsLong GenerateTaskId() 22 { 23 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 24 ASSERT(coroutine != nullptr); 25 return coroutine->GetPandaVM()->GetTaskpool()->GenerateTaskId(); 26 } 27 TaskpoolTaskSubmitted(EtsLong taskId)28extern "C" void TaskpoolTaskSubmitted(EtsLong taskId) 29 { 30 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 31 ASSERT(coroutine != nullptr); 32 coroutine->GetPandaVM()->GetTaskpool()->TaskSubmitted(taskId); 33 } 34 TaskpoolTaskStarted(EtsLong taskId)35extern "C" EtsBoolean TaskpoolTaskStarted(EtsLong taskId) 36 { 37 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 38 ASSERT(coroutine != nullptr); 39 return EtsBoolean(coroutine->GetPandaVM()->GetTaskpool()->TaskStarted(coroutine->GetCoroutineId(), taskId)); 40 } 41 TaskpoolTaskFinished(EtsLong taskId)42extern "C" EtsBoolean TaskpoolTaskFinished(EtsLong taskId) 43 { 44 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 45 ASSERT(coroutine != nullptr); 46 return EtsBoolean(coroutine->GetPandaVM()->GetTaskpool()->TaskFinished(coroutine->GetCoroutineId(), taskId)); 47 } 48 TaskpoolCancelTask(EtsLong taskId)49extern "C" void TaskpoolCancelTask(EtsLong taskId) 50 { 51 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 52 ASSERT(coroutine != nullptr); 53 if (!coroutine->GetPandaVM()->GetTaskpool()->CancelTask(taskId)) { 54 ThrowEtsException(coroutine, panda_file_items::class_descriptors::ERROR, 55 "taskpool:: task is not executed or has been executed"); 56 } 57 } 58 TaskpoolIsTaskCanceled()59extern "C" EtsBoolean TaskpoolIsTaskCanceled() 60 { 61 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent(); 62 ASSERT(coroutine != nullptr); 63 return EtsBoolean(coroutine->GetPandaVM()->GetTaskpool()->IsTaskCanceled(coroutine->GetCoroutineId())); 64 } 65 66 } // namespace ark::ets::intrinsics 67