/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#include "Lock.h"

namespace Blinker {

/// constructor
Lock::Lock():
  m_locked(false)
{
}

/// destructor
Lock::~Lock()
{
}

/**
 * @brief check if locked
 * @return whether lock is taken
 */
bool Lock::islocked() const
{
  return m_locked;
}

/**
 * @brief lock if not locked
 * @return whether lock could be acquired
 */
bool Lock::trylock()
{
  if (m_locked) {
    return false;
  }
  m_locked = true;
  return true;
}

/// unlock (if locked)
void Lock::unlock()
{
  m_locked = false;
}

} // namespace Blinker

