/*
 * adLoker.cpp
 *
 *  Created on: 13. dec. 2012
 *      Author: Viacheslav Isaev
 */

#define UTS_MODULE_NAME "AD:Lockers"

#include "utsDebug.h"
#include "adLockKeeper.h"

namespace ad
{

MutexLocker::MutexLocker(epicsMutex* mutex):
		_mutex(mutex)
,_file("")
,_line(0)

{
	UTS_STK("Locking mutex");
	_mutex->lock();
}

MutexLocker::MutexLocker(epicsMutex* mutex, const std::string file, int line):
		_mutex(mutex)
	,_file(file)
	,_line(line)
{
	uts::StackLoger loger("Locking mutex", _file, _line);
	_mutex->lock();
}


MutexLocker::~MutexLocker()
{
	uts::StackLoger loger("Unlocking mutex", _file, _line);
	_mutex->unlock();
}

Locker::Locker( asynPortDriver *obj ):
		_obj(obj)
		,_file("")
		,_line(0)

{
	UTS_STK("Locking asynPortDriver");
	_obj->lock();
}

Locker::Locker( asynPortDriver *obj, const std::string file, int line):
_obj(obj)
,_file(file)
,_line(line)
{
	uts::StackLoger loger("Locking asynPortDriver", _file, _line);

	_obj->lock();
}

Locker::~Locker()
{
	uts::StackLoger loger("Unlocking asynPortDriver", _file, _line);
	_obj->unlock();
}

UnLocker::UnLocker( asynPortDriver *obj ):
		_obj(obj)
		,_file("")
		,_line(0)
{
	UTS_STK("Unlocking asynPortDriver");
	_obj->unlock();
}

UnLocker::UnLocker( asynPortDriver *obj, const std::string file, int line):
_obj(obj)
,_file(file)
,_line(line)
{
	uts::StackLoger loger("Unlocking asynPortDriver", _file, _line);
	_obj->unlock();
}

UnLocker::~UnLocker()
{
	uts::StackLoger loger("Locking asynPortDriver", _file, _line);
	_obj->lock();
}


} /* namespace ad */
