14d6c458bSopenharmony_ci/* 24d6c458bSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 34d6c458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44d6c458bSopenharmony_ci * you may not use this file except in compliance with the License. 54d6c458bSopenharmony_ci * You may obtain a copy of the License at 64d6c458bSopenharmony_ci * 74d6c458bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84d6c458bSopenharmony_ci * 94d6c458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104d6c458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114d6c458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124d6c458bSopenharmony_ci * See the License for the specific language governing permissions and 134d6c458bSopenharmony_ci * limitations under the License. 144d6c458bSopenharmony_ci */ 154d6c458bSopenharmony_ci 164d6c458bSopenharmony_ci#include "thread.h" 174d6c458bSopenharmony_ci 184d6c458bSopenharmony_cinamespace Commonlibrary::Concurrent::WorkerModule { 194d6c458bSopenharmony_ciThread::Thread() : tId_() {} 204d6c458bSopenharmony_ci 214d6c458bSopenharmony_cibool Thread::Start() 224d6c458bSopenharmony_ci{ 234d6c458bSopenharmony_ci int ret = uv_thread_create(&tId_, [](void* arg) { 244d6c458bSopenharmony_ci#if defined IOS_PLATFORM || defined MAC_PLATFORM 254d6c458bSopenharmony_ci pthread_setname_np("WorkerThread"); 264d6c458bSopenharmony_ci#else 274d6c458bSopenharmony_ci pthread_setname_np(pthread_self(), "WorkerThread"); 284d6c458bSopenharmony_ci#endif 294d6c458bSopenharmony_ci Thread* thread = reinterpret_cast<Thread*>(arg); 304d6c458bSopenharmony_ci thread->Run(); 314d6c458bSopenharmony_ci }, this); 324d6c458bSopenharmony_ci return ret != 0; 334d6c458bSopenharmony_ci} 344d6c458bSopenharmony_ci} // namespace Commonlibrary::Concurrent::WorkerModule