/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#include <ddthreadrunnable.h>
#include <ddthread.h>


/**
	Constructor.
*/

ddthreadrunnable::ddthreadrunnable()
:	_owner( 0 )
{

}

/**
	Constructor.
*/

ddthreadrunnable::ddthreadrunnable( const ddstring& name )
:  ddbasenamedobject( name ), _owner( 0 )
{

}

/**
	Destructor.
*/

ddthreadrunnable::~ddthreadrunnable()
{

}


/**
 Derived classes must implement this method. This is
 the main body of the thread.
*/

void ddthreadrunnable::run()
{
	
}


/**
	Create and start the peer thread of this runnable.
*/

void ddthreadrunnable::start_thread()
{
	ddthreadfactory::create_thread( this, get_name() );
	get_thread()->start();
}


/**
	Create and start the peer thread of this runnable.
*/

void ddthreadrunnable::cancel_thread()
{
	get_thread()->cancel();
}


/**
	Unconditional wait. Puts the owning thread to sleep
	until another thread signals it.
*/

void ddthreadrunnable::wait()
{
	_owner->wait();
}


/**
	Conditional wait. If the thread is not signalled
	before the timeout expires, then this method returns
	ETIMEDOUT.
*/

int ddthreadrunnable::wait( unsigned secs )
{
	return _owner->wait( secs );
}


/**
	Notify (==wakeup) the waiting owner thread.
*/

void ddthreadrunnable::notify()
{
	ddthread::notify( _owner );
}


/**
	Terminates the owning thread.
*/

void ddthreadrunnable::exit()
{
	_owner->exit();
}


