* @brief This function will initialize a static semaphore object. * * @note For the static semaphore object, its memory space is allocated by the compiler during compiling, * and shall placed on the read-write data segment or on the uninitialized data segment. * By contrast, the rt_sem_create() function will allocate memory space automatically and initialize *
| 374 | * @warning This function can ONLY be called from threads. |
| 375 | */ |
| 376 | rt_err_t rt_sem_init(rt_sem_t sem, |
| 377 | const char *name, |
| 378 | rt_uint32_t value, |
| 379 | rt_uint8_t flag) |
| 380 | { |
| 381 | RT_ASSERT(sem != RT_NULL); |
| 382 | RT_ASSERT(value < 0x10000U); |
| 383 | RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO)); |
| 384 | |
| 385 | /* initialize object */ |
| 386 | rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name); |
| 387 | |
| 388 | _sem_object_init(sem, value, flag, RT_SEM_VALUE_MAX); |
| 389 | |
| 390 | return RT_EOK; |
| 391 | } |
| 392 | RTM_EXPORT(rt_sem_init); |
| 393 | |
| 394 |