/*	Copyright  (c)	Günter Woigk  1990-2000
  					mailto:kio@little-bat.de

 	This program is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

 	Permission to use, copy, modify, distribute, and sell this software and
 	its documentation for any purpose is hereby granted without fee, provided
 	that the above copyright notice appear in all copies and that both that
 	copyright notice and this permission notice appear in supporting
 	documentation, and that the name of the copyright holder not be used
 	in advertising or publicity pertaining to distribution of the software
 	without specific, written prior permission.  The copyright holder makes no
 	representations about the suitability of this software for any purpose.
 	It is provided "as is" without express or implied warranty.

 	THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 	INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 	EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 	CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 	DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 	TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 	PERFORMANCE OF THIS SOFTWARE.
*/


#ifdef  _disp_h_		// this file should only be included by disp.h


/* ----	Interrupts --------------------------------------------------
		Irpt.flag	>  0	triggered
		Irpt.flag	<= 0	not yet triggered
*/
class Irpt
{
friend 	class Twsp;
friend	static bool Switch ( Tid );

		long		flag;		// interrupt cell
		Tid			wait;		// linked list of waiting threads

		void		_trigger	( int n=1 );
		
public:
					Irpt		( )		{ flag=0; wait=0; }	// create cleared interrupt
					~Irpt		( );						// destructor: unlink waiting tasks!
					Irpt		( const Irpt& );			// prohibit
					operator=	( const Irpt& );			// prohibit

		bool		IsTriggered	( ) const			{ return flag>0;  }	// interrupts pending ?
		bool		IsNotTriggered()const			{ return flag<=0; }	// no interrupts pending ?
		long		Interrupts	( ) const			{ return flag; 	  }	// num. of pending irpts (may be neg.)
		bool		IsWaiting	( ) const			{ return wait!=0; }	// s.o. waiting ?

		void		Clear		( )					{ flag=0; 		  }	// reset to initial state
		void		Clear		( int n )			{ if(n>0)flag-=n; }	// clear n interrupts
		void		AsyncTrigger( int n=1 );		// trigger interrupt asynchronously
		void		Trigger		( int n=1 );		// trigger interrupt
		void		Shedule		( );				// shedule for interrupt
		void		Shedule		( long timeout );	// shedule with timeout
};











#endif
