• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ABSTRACT_SEMAPHORE_H
16 #define OHOS_PROFILER_ABSTRACT_SEMAPHORE_H
17 
18 #include <memory>
19 #include <string>
20 
21 class ISemaphore {
22 public:
~ISemaphore()23     virtual ~ISemaphore() {}
24     virtual bool Wait() = 0;
25     virtual bool TryWait() = 0;
TimedWait(int seconds)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 };
34 using SemaphorePtr = std::shared_ptr<ISemaphore>;
35 
36 enum SemaphoreFactoryType : int { STD_SEMAPHORE_FACTORY, POSIX_SEMAPHORE_FACTORY, PTHREAD_SEMAPHORE_FACTORY };
37 
38 class ISemaphoreFactory {
39 public:
40     virtual SemaphorePtr Create(unsigned int value) = 0;
41 };
42 
43 ISemaphoreFactory& GetSemaphoreFactory(SemaphoreFactoryType type = STD_SEMAPHORE_FACTORY);
44 
45 #endif // OHOS_PROFILER_ABSTRACT_SEMAPHORE_H