1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2016/10/1 Bernard The first version 9 */ 10 11 #pragma once 12 13 #include <stdint.h> 14 #include <rtthread.h> 15 16 namespace rtthread { 17 18 /** The Semaphore class is used to manage and protect access to a set of shared resources. */ 19 class Semaphore 20 { 21 public: 22 /** Create and Initialize a Semaphore object used for managing resources. 23 @param number of available resources; maximum index value is (count-1). 24 */ 25 Semaphore(const char *name = "sem", int32_t count = 0); 26 ~Semaphore(); 27 28 /** Wait until a Semaphore resource becomes available. 29 @param millisec timeout value or 0 in case of no time-out. 30 @return true on success. 31 */ 32 bool wait(int32_t millisec = -1); 33 34 /** Release a Semaphore resource that was obtain with Semaphore::wait. 35 */ 36 void release(void); 37 38 private: 39 struct rt_semaphore mID; 40 }; 41 42 } 43