1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #include <stdint.h> 6 #include <k_api.h> 7 8 /** @defgroup cpp_aos_sem 9 * @ingroup cpp_aos_api 10 * @{ 11 */ 12 namespace AOS { 13 14 #define Semaphore_WAIT_FOREVER 0xFFFFFFFFU 15 16 /** 17 * @brief Semaphore Class. 18 * 19 */ 20 21 class Semaphore 22 { 23 public: 24 /** 25 * This function will create a semaphore 26 * @param[in] name name of the semaphore 27 * @param[in] count the init count of the semaphore 28 * @return the operation status, RHINO_SUCCESS is OK, others is error 29 */ 30 kstat_t create(const name_t *name, sem_count_t count); 31 32 /** 33 * This function will delete a semaphore 34 * @param[in] NULL 35 * @return the operation status, RHINO_SUCCESS is OK, others is error 36 */ 37 kstat_t destroy(void); 38 39 /** 40 * This function will wait a semaphore 41 * @param[in] millisec millisec to wait before take 42 * @return the operation status, RHINO_SUCCESS is OK, others is error 43 */ 44 kstat_t wait(uint32_t millisec); 45 46 /** 47 * This function will release a semaphore 48 * @param[in] NULL 49 * @return the operation status, RHINO_SUCCESS is OK, others is error 50 */ 51 kstat_t release(void); 52 53 /** 54 * This function will release all semaphore 55 * @param[in] NULL 56 * @return the operation status, RHINO_SUCCESS is OK, others is error 57 */ 58 kstat_t release_all(void); 59 60 /** 61 * This function will set the count of a semaphore 62 * @param[in] sem_count count of the semaphore 63 * @return the operation status, RHINO_SUCCESS is OK, others is error 64 */ 65 kstat_t count_set(sem_count_t count); 66 67 /** 68 * This function will get count of a semaphore 69 * @param[out] count count of the semaphore 70 * @return the operation status, RHINO_SUCCESS is OK, others is error 71 */ 72 kstat_t count_get(sem_count_t *count); 73 74 /** 75 * This function will get a Semaphore struct pointer 76 * @param[in] none 77 * @return Semaphore struct pointer 78 */ 79 ksem_t *self(void); 80 81 private: 82 /** 83 * @brief a Queue buffer 84 */ 85 ksem_t _sem_def; 86 }; 87 88 } 89 /** 90 * @} 91 */ 92