Beispiel #1
0
void Mutex::release(pointer called_by)
{
  if(unlikely(system_state != RUNNING))
    return;
  if(!called_by)
    called_by = getCalledBefore(1);
//  debug(LOCK, "Mutex::release:  Mutex: %s (%p), currentThread: %s (%p).\n",
//           getName(), this, currentThread->getName(), currentThread);
//  if(kernel_debug_info)
//  {
//    debug(LOCK, "The release is called by: ");
//    kernel_debug_info->printCallInformation(called_by);
//  }
  checkInvalidRelease("Mutex::release");
  removeFromCurrentThreadHoldingList();
  last_accessed_at_ = called_by;
  held_by_ = 0;
  mutex_ = 0;
  // Wake up a sleeping thread. It is okay that the mutex is not held by the current thread any longer.
  // In worst case a new thread is woken up. Otherwise (first wake up, then release),
  // it could happen that a thread is going to sleep after the this one is trying to wake up one.
  // Then we are dead... (the thread may sleep forever, in case no other thread is going to acquire this mutex again).
  lockWaitersList();
  Thread* thread_to_be_woken_up = popBackThreadFromWaitersList();
  unlockWaitersList();
  if(thread_to_be_woken_up)
  {
    Scheduler::instance()->wake(thread_to_be_woken_up);
  }
}
Beispiel #2
0
void Mutex::release(const char* debug_info)
{
  if(unlikely(system_state != RUNNING))
    return;
  //debug(LOCK, "Mutex::release:  Mutex: %s (%p), currentThread: %s (%p).\n",
  //         getName(), this, currentThread->getName(), currentThread);
  checkInvalidRelease("Mutex::release", debug_info);
  removeFromCurrentThreadHoldingList();
  held_by_ = 0;
  mutex_ = 0;
  // Wake up a sleeping thread. It is okay that the mutex is not held by the current thread any longer.
  // In worst case a new thread is woken up. Otherwise (first wake up, then release),
  // it could happen that a thread is going to sleep after the this one is trying to wake up one.
  // Then we are dead... (the thread may sleep forever, in case no other thread is going to acquire this mutex again).
  lockWaitersList();
  Thread* thread_to_be_woken_up = popBackThreadFromWaitersList();
  unlockWaitersList();
  if(thread_to_be_woken_up)
  {
    Scheduler::instance()->wake(thread_to_be_woken_up);
  }
}