1 /* 2 * Copyright (c) 2021 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 #ifndef OHOS_PROFILER_POSIX_SEMAPHORE_H 16 #define OHOS_PROFILER_POSIX_SEMAPHORE_H 17 18 #include <semaphore.h> 19 #include "i_semaphore.h" 20 21 class PosixSemaphore : public ISemaphore { 22 public: 23 explicit PosixSemaphore(unsigned int value); 24 ~PosixSemaphore(); 25 26 bool Wait() override; 27 bool TryWait() override; 28 bool TimedWait(int seconds, int nanoSeconds) override; 29 bool Post() override; 30 unsigned Value() const override; 31 32 private: 33 mutable sem_t sem_ = {}; 34 }; 35 36 class PosixSemaphoreFactory : public ISemaphoreFactory { 37 public: 38 SemaphorePtr Create(unsigned int value) override; 39 }; 40 41 #endif // OHOS_PROFILER_POSIX_SEMAPHORE_H