1/* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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_ABSTRACT_SEMAPHORE_H 16#define OHOS_PROFILER_ABSTRACT_SEMAPHORE_H 17 18#include <memory> 19#include <string> 20 21class ISemaphore { 22public: 23 virtual ~ISemaphore() {} 24 virtual bool Wait() = 0; 25 virtual bool TryWait() = 0; 26 bool TimedWait(int seconds) 27 { 28 return TimedWait(seconds, 0); 29 } 30 virtual bool TimedWait(int seconds, int nanoSeconds) = 0; 31 virtual bool Post() = 0; 32 virtual unsigned int Value() const = 0; 33}; 34using SemaphorePtr = std::shared_ptr<ISemaphore>; 35 36enum SemaphoreFactoryType : int { STD_SEMAPHORE_FACTORY, POSIX_SEMAPHORE_FACTORY, PTHREAD_SEMAPHORE_FACTORY }; 37 38class ISemaphoreFactory { 39public: 40 virtual SemaphorePtr Create(unsigned int value) = 0; 41}; 42 43ISemaphoreFactory& GetSemaphoreFactory(SemaphoreFactoryType type = STD_SEMAPHORE_FACTORY); 44 45#endif // OHOS_PROFILER_ABSTRACT_SEMAPHORE_H