+/* 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
+ interupt handler. */
+bool
+lock_try_acquire (struct lock *lock)
+{
+ enum intr_level old_level;
+ bool success;
+
+ ASSERT (lock != NULL);
+ ASSERT (!lock_held_by_current_thread (lock));
+
+ old_level = intr_disable ();
+ success = sema_try_down (&lock->semaphore);
+ if (success)
+ lock->holder = thread_current ();
+ intr_set_level (old_level);
+
+ return success;
+}
+