1 /* 2 * Copyright (c) 2023 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 #include "serial_task.h" 16 #include "dfx/log/ffrt_log_api.h" 17 #include "util/slab.h" 18 19 namespace ffrt { SerialTask()20SerialTask::SerialTask() 21 { 22 FFRT_LOGD("ctor serial task gid=%llu", gid); 23 } 24 ~SerialTask()25SerialTask::~SerialTask() 26 { 27 FFRT_LOGD("dtor serial task gid=%llu", gid); 28 } 29 SetQueHandler(IHandler * handler)30ITask* SerialTask::SetQueHandler(IHandler* handler) 31 { 32 handler_ = handler; 33 return this; 34 } 35 Wait()36void SerialTask::Wait() 37 { 38 std::unique_lock lock(mutex_); 39 while (!isFinished_) { 40 cond_.wait(lock); 41 } 42 } 43 Notify()44void SerialTask::Notify() 45 { 46 std::unique_lock lock(mutex_); 47 isFinished_ = true; 48 cond_.notify_all(); 49 } 50 freeMem()51void SerialTask::freeMem() 52 { 53 SimpleAllocator<SerialTask>::freeMem(this); 54 } 55 } // namespace ffrt 56