* @brief Creating a semaphore object. * * @note For the semaphore object, its memory space is allocated automatically. * By contrast, the rt_sem_init() function will initialize a static semaphore object. * * @see rt_sem_init() * * @param name is a pointer to the name you would like to give the semaphore. * * @param value is the initial value for the semaphore.
| 465 | * @warning This function can NOT be called in interrupt context. You can use macor RT_DEBUG_NOT_IN_INTERRUPT to check it. |
| 466 | */ |
| 467 | rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) |
| 468 | { |
| 469 | rt_sem_t sem; |
| 470 | |
| 471 | RT_ASSERT(value < 0x10000U); |
| 472 | RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO)); |
| 473 | |
| 474 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 475 | |
| 476 | /* allocate object */ |
| 477 | sem = (rt_sem_t)rt_object_allocate(RT_Object_Class_Semaphore, name); |
| 478 | if (sem == RT_NULL) |
| 479 | return sem; |
| 480 | |
| 481 | _sem_object_init(sem, value, flag, RT_SEM_VALUE_MAX); |
| 482 | |
| 483 | return sem; |
| 484 | } |
| 485 | RTM_EXPORT(rt_sem_create); |
| 486 | |
| 487 |