1  /*
   2   * \brief  Locking primitives
   3   * \author Norman Feske
   4   * \date   2006-07-26
   5   */

   6  
   7  /*
   8   * Copyright (C) 2006-2013 Genode Labs GmbH
   9   *
  10   * This file is part of the Genode OS framework, which is distributed
  11   * under the terms of the GNU General Public License version 2.
  12   */

  13  
  14  #ifndef _INCLUDE__BASE__LOCK_H_
  15  #define _INCLUDE__BASE__LOCK_H_
  16  
  17  #include <base/cancelable_lock.h>
  18  
  19  namespace Genode { class Lock; }
  20  
  21  
  22  struct Genode::Lock : Cancelable_lock
  23  {
  24     /**
  25      * Constructor
  26      */

  27     explicit Lock(State initial = UNLOCKED) : Cancelable_lock(initial) { }

  28  
  29     void lock()
  30     {
  31        while (1)
  32           try {
  33              Cancelable_lock::lock();
  34              return;

  35           }
 catch (Blocking_canceled) { }

  36     }

  37  
  38     /**
  39      * Lock guard
  40      */

  41     typedef Lock_guard<Lock> Guard;

  42  }
;

  43  
  44  #endif /* _INCLUDE__BASE__LOCK_H_ */