コード例 #1
0
ファイル: synch.c プロジェクト: waffleOS/waffle
/*! Tries to acquires LOCK and returns true if successful or false
    on failure.  The lock must not already be held by the current
    thread.

    This function will not sleep, so it may be called within an
    interrupt handler. */
bool lock_try_acquire(struct lock *lock) {
    bool success;

    ASSERT(lock != NULL);
    ASSERT(!lock_held_by_current_thread(lock));

    success = sema_try_down(&lock->semaphore);
    if (success)
      lock->holder = thread_current();

    return success;
}
コード例 #2
0
ファイル: synch.c プロジェクト: aashsach/pintos
/* Tries to acquires LOCK and returns true if successful or false
   on failure.  The lock must not already be held by the current
   thread.

   This function will not sleep, so it may be called within an
   interrupt handler. */
bool
lock_try_acquire (struct lock *lock)
{
  bool success;

  ASSERT (lock != NULL);
  ASSERT (!lock_held_by_current_thread (lock));

  success = sema_try_down (&lock->semaphore);
  //if (success){
  //  lock->holder = thread_current ();
   // list_push_back(&thread_current ()->lock_list,&lock->elem);
 // }
  return success;
}
コード例 #3
0
ファイル: synch.c プロジェクト: smssss/pintos-project1
/* Tries to acquires LOCK and returns true if successful or false
   on failure.  The lock must not already be held by the current
   thread.

   This function will not sleep, so it may be called within an
   interrupt handler. */
bool
lock_try_acquire (struct lock *lock)
{
  bool success;

  ASSERT (lock != NULL);
  ASSERT (!lock_held_by_current_thread (lock));

  success = sema_try_down (&lock->semaphore);
  if (success)
		{
    	lock->holder = thread_current ();
			list_push_back (&(lock->holder->hold_locks), &lock->hold_elem);
		}
  return success;
}
コード例 #4
0
ファイル: synch.c プロジェクト: naftaliharris/cs140
/* 
 --------------------------------------------------------------------
 Tries to acquires LOCK and returns true if successful or false
   on failure.  The lock must not already be held by the current
   thread.

   This function will not sleep, so it may be called within an
   interrupt handler. 
 NOTE: we add code to ensure that if the thread is successful 
    in aquiring the lock it is trying to aquire, that the lock
    is then added to the threads list of locks_held, so that the 
    system of proirity donation stays in tact. 
 --------------------------------------------------------------------
 */
bool
lock_try_acquire (struct lock *lock)
{
    bool success;
    
    ASSERT (lock != NULL);
    
    ASSERT (!lock_held_by_current_thread (lock));
    
    success = sema_try_down (&lock->semaphore);
    if (success) {
        if (!thread_mlfqs) {
            lock->priority = PRI_MIN;
            list_push_front(&(thread_current()->locks_held), &(lock->elem));
            thread_current()->lock_waiting_on = NULL;
        }
        lock->holder = thread_current ();
    }
    return success;
}
コード例 #5
0
ファイル: synch.c プロジェクト: xArchange/pintos-1
/* Tries to acquires LOCK and returns true if successful or false
   on failure.  The lock must not already be held by the current
   thread.

   This function will not sleep, so it may be called within an
   interrupt handler. */
bool
lock_try_acquire (struct lock *lock)
{
  bool success;

  ASSERT (lock != NULL);
  ASSERT (!lock_held_by_current_thread (lock));

  enum intr_level old_level = intr_disable ();

  success = sema_try_down (&lock->semaphore);
  if (success)
  {
    /* If the lock can be acquired, then the current thread
       is not waiting for it anymore. */
    thread_current ()->lock_to_acquire = NULL;
    lock->holder = thread_current ();
  }

  intr_set_level (old_level);

  return success;
}
コード例 #6
0
ファイル: synch.c プロジェクト: smssss/pintos-project1
/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

	if (!sema_try_down (&lock->semaphore))
  	{
			sema_down (&lock->sema_lock);
			thread_current ()->wait_lock = lock;			
			lock_donate_priority(thread_current(), lock);
			sema_up (&lock->sema_lock);

			sema_down (&lock->semaphore);
		}

  lock->holder = thread_current ();
  list_push_back (&(lock->holder->hold_locks), &lock->hold_elem);
 	
	sema_down (&lock->sema_lock);
	lock->holder->wait_lock = NULL;
  sema_up (&lock->sema_lock);
}