コード例 #1
0
ファイル: mm_sem.c プロジェクト: alexlotw/nuttx
void mm_givesemaphore(FAR struct mm_heap_s *heap)
{
#ifdef CONFIG_DEBUG
  pid_t my_pid = getpid();
#endif

  /* I better be holding at least one reference to the semaphore */

  DEBUGASSERT(heap->mm_holder == my_pid);

  /* Do I hold multiple references to the semphore */

  if (heap->mm_counts_held > 1)
    {
      /* Yes, just release one count and return */

      heap->mm_counts_held--;
      msemdbg("Holder=%d count=%d\n", heap->mm_holder, heap->mm_counts_held);
    }
  else
    {
      /* Nope, this is the last reference I have */

#ifdef CONFIG_DEBUG
      msemdbg("PID=%d giving\n", my_pid);
#endif

      heap->mm_holder      = -1;
      heap->mm_counts_held = 0;
      irqrestore(heap->mm_flags);
    }
}
コード例 #2
0
ファイル: mm_sem.c プロジェクト: 1015472/PX4NuttX
void mm_takesemaphore(FAR struct mm_heap_s *heap)
{
  pid_t my_pid = getpid();

  /* Do I already have the semaphore? */

  if (heap->mm_holder == my_pid)
    {
      /* Yes, just increment the number of references that I have */

      heap->mm_counts_held++;
    }
  else
    {
      /* Take the semaphore (perhaps waiting) */

      msemdbg("PID=%d taking\n", my_pid);
      while (sem_wait(&heap->mm_semaphore) != 0)
        {
          /* The only case that an error should occur here is if
           * the wait was awakened by a signal.
           */

          ASSERT(errno == EINTR);
        }

      /* We have it.  Claim the stake and return */

      heap->mm_holder      = my_pid;
      heap->mm_counts_held = 1;
    }

  msemdbg("Holder=%d count=%d\n", heap->mm_holder, heap->mm_counts_held);
}
コード例 #3
0
ファイル: mm_sem.c プロジェクト: alexlotw/nuttx
void mm_takesemaphore(FAR struct mm_heap_s *heap)
{
  pid_t my_pid = getpid();

  /* Do I already have the semaphore? */

  if (heap->mm_holder == my_pid)
    {
      /* Yes, just increment the number of references that I have */

      heap->mm_counts_held++;
    }
  else
    {
      /* Disable interrupts */

      msemdbg("PID=%d taking\n", my_pid);
      heap->mm_flags = irqsave();

      /* We have it.  Claim the stake and return */

      heap->mm_holder      = my_pid;
      heap->mm_counts_held = 1;
    }

  msemdbg("Holder=%d count=%d\n", heap->mm_holder, heap->mm_counts_held);
}
コード例 #4
0
ファイル: mm_sem.c プロジェクト: CNCBASHER/Firmware
void mm_givesemaphore(void)
{
#ifdef CONFIG_DEBUG
  pid_t my_pid = getpid();
#endif

  /* I better be holding at least one reference to the semaphore */

  DEBUGASSERT(g_holder == my_pid);

  /* Do I hold multiple references to the semphore */

  if (g_counts_held > 1)
    {
      /* Yes, just release one count and return */

      g_counts_held--;
      msemdbg("Holder=%d count=%d\n", g_holder, g_counts_held);
    }
  else
    {
      /* Nope, this is the last reference I have */

      msemdbg("PID=%d giving\n", my_pid);
      g_holder      = -1;
      g_counts_held = 0;
      ASSERT(sem_post(&g_mm_semaphore) == 0);
    }
}