sched/semaphore.c
/*
 * sem_post - increment the value of the semaphore
 *
 * @sem       - the semaphore address
 *
 * This function increments the semaphore value and unblocks all the tasks
 * that are holding it.
 */
increment the value of the semaphore
@sem       - the semaphore address

This function increments the semaphore value and unblocks all the tasks
that are holding it.
increment the value of the semaphore @sem - the semaphore address This function increments the semaphore value and unblocks all the tasks that are holding it .
int sem_post(sem_t *sem)
{
  irq_state_t irq_state = cpu_disableint();
  sem->count += 1;
  if (sem->count == 1)
  {
    struct tcb_s *current = NULL;
    list_for_each_entry(current, &g_tcb_waiting_list, next_tcb)
    {
      if (current != NULL && current->waiting_tcb_sema == sem)
      {
        assert(current->t_state == WAITING_FOR_SEM); 
        current->waiting_tcb_sema = NULL;
        current->t_state          = READY;
        SCHED_DEBUG_INFO("%s received POST sema\n", current->task_name);
        break;
      }
    }
  }
  cpu_enableint(irq_state);
  return 0;
}
int sem_post ( sem_t * sem ) { irq_state_t irq_state = cpu_disableint ( ) ; sem -> count += 1 ; if ( sem -> count == 1 ) { struct tcb_s * current = NULL ; list_for_each_entry ( current , & g_tcb_waiting_list , next_tcb ) { if ( current != NULL && current -> waiting_tcb_sema == sem ) { assert ( current -> t_state == WAITING_FOR_SEM ) ; current -> waiting_tcb_sema = NULL ; current -> t_state = READY ; SCHED_DEBUG_INFO ( " \n " , current -> task_name ) ; break ; } } } cpu_enableint ( irq_state ) ; return 0 ; }
sem_post - increment the value of the semaphore
 @sem       - the semaphore address
sem_post - increment the value of the semaphore @sem - the semaphore address
/* Disable interrupts for this task */ /* Unblock task from waiting list that is blocked by this semaphore and
     * place it in the running list
     */ /* If the task is not in the waiting state then somwthing went
         * wrong.
         */ /* Move the task state to ready and remove the semaphore from */ /* Let the sched_preempt_task function Delete the task from the
         * waiting list and add it to the ready to run list in front of other
         * tasks.
         */ /* Re-enable interrupts for the current task */