Code Search for Developers
 
 
  

RedShedThreads.h from redshed at Krugle


Show RedShedThreads.h syntax highlighted

/****************************************************************************************
	RedShedThreads.h $Revision: 1.2 $
		<http://rentzsch.com/redshedthreads>
	
	Copyright © 1998-2002 Red Shed Software. All rights reserved.
	by Jonathan 'Wolf' Rentzsch (jon at redshed dot net)
	
	************************************************************************************/

#ifndef		_RedShedThreads_
#define		_RedShedThreads_

/**************************
*	
*	Includes
*	
**************************/
#pragma mark	(Includes)

#include	"RedShedThreadContext.h"
#include	"atomicity.h"
#include	"AtomicMessages.h"

/**************************
*	
*	Constants
*	
**************************/
#pragma mark	-
#pragma mark	(Constants)

//	RedShedThread flags.
#define	kRedShedThreadAutoDispose			kAtomicFlag1
#define	kRedShedThreadWaitingForMessage		kAtomicFlag2
#define	kRedShedThreadDisposing				kAtomicFlag3
#define	kRedShedThreadDisposerFired			kAtomicFlag4
#define	kRedShedThreadDestructorFired		kAtomicFlag5
#define	kRedShedThreadRunning				kAtomicFlag6
#define	kRedShedThreadWaitingForPulse		kAtomicFlag7
#define	kRedShedThreadGotPulse				kAtomicFlag8

typedef	enum	{
	kRedShedThreadValid						=	0,
	kRedShedThreadNil						=	1,
	kRedShedThreadNotAligned				=	2,
	kRedShedThreadFlagsNotAligned			=	3,
	kRedShedThreadMessageQueueNotAligned	=	4,
	kRedShedThreadInvalidContext			=	5,
	kRedShedThreadStackLimitNotAligned		=	6,
	kRedShedThreadInvalidStackSize			=	7,
	kRedShedThreadPulsarNotAligned			=	8,
	kRedShedThreadEntryNil					=	9,
	kRedShedThreadDisposerNil				=	10
}	ValidRedShedThreadCode;

/**************************
*	
*	Types
*	
**************************/
#pragma mark	-
#pragma mark	(Types)

typedef	struct	RedShedThread	RedShedThread;
typedef	void	(*RedShedThreadProc)( RedShedThread *thread );

struct	RedShedThread	{
	AtomicFlags				flags;			//	Must be 4 byte aligned.
	AtomicMessageQueue		messageQueue;	//	Must be 4 byte aligned.
	
	RedShedThreadContext	*context;
	UInt32					contextSize;
	char					*stackLimit;
	UInt32					stackSize;
	
	RedShedThreadContext	*pulsar;
	UInt32					startPulseTime;
	
	RedShedThreadProc		entry;
	RedShedThreadProc		disposer;
	RedShedThreadProc		suspender;
	RedShedThreadProc		resumer;
	
	void					*param;
	void					*refCon;
};

#ifdef		__cplusplus
extern	"C"	{
#endif	//	__cplusplus

/**************************
*	
*	Thread Creation/Destruction Interfaces
*	
**************************/
#pragma mark	-
#pragma mark	(Thread Creation/Destruction Interfaces)

	extern
	RedShedThread*
NewRedShedThread(
	RedShedThread			*thread,
	RedShedThreadContextID	contextID );

	extern
	void
DisposeRedShedThread(
	RedShedThread	*thread );

	extern
	void
RedShedThreadDisposer(
	RedShedThread	*thread );

	extern
	ValidRedShedThreadCode
IsValidRedShedThread(
	RedShedThread	*thread );

	extern
	Boolean
IsCurrentRedShedThread(
	RedShedThread	*thread );

//	The following macros are handy if you're using requirements...
#define	RequireRedShedThread( THREAD )	\
			RequireEqual( IsValidRedShedThread( THREAD ), kRedShedThreadValid )

#define	RequireCurrentRedShedThread( THREAD )										\
			RequireEqual( IsValidRedShedThread( THREAD ), kRedShedThreadValid );	\
			Require( IsCurrentRedShedThread( THREAD ) )

/**************************
*	
*	Thread Scheduling Interfaces
*	
**************************/
#pragma mark	-
#pragma mark	(Thread Scheduling Interfaces)

	extern
	void
PulseRedShedThread(
	RedShedThread	*thread );

	extern
	void
YieldRedShedThread(
	RedShedThread	*thread );

	extern
	void
ReadyRedShedThread(
	RedShedThread	*thread );

	extern
	void
BlockRedShedThread(
	RedShedThread	*thread );

/**************************
*	
*	Thread Messaging Interfaces
*	
**************************/
#pragma mark	-
#pragma mark	(Thread Messaging Interfaces)

	extern
	Boolean
SendRedShedThreadMessage(
	RedShedThread			*toThread,
	AtomicMessageElement	*message );

	extern
	OSErr
NewRedShedThreadMessage(
	RedShedThread	*toThread,
	AtomicMessage	message,
	long			data1,
	long			data2,
	long			data3 );

	extern
	AtomicMessage
PeekRedShedThreadMessage(
	RedShedThread		*thread,
	AtomicMessageProc	filterProc,
	AtomicMessage		filterValue,
	long				*data1,
	long				*data2,
	long				*data3 );

	extern
	AtomicMessage
ReceiveRedShedThreadMessage(
	RedShedThread		*thread,
	AtomicMessageProc	filterProc,
	AtomicMessage		filterValue,
	long				*data1,
	long				*data2,
	long				*data3 );

	extern
	AtomicMessage
WaitPeekRedShedThreadMessage(
	RedShedThread		*thread,
	AtomicMessageProc	filterProc,
	AtomicMessage		filterValue,
	long				*data1,
	long				*data2,
	long				*data3 );

	extern
	AtomicMessage
WaitReceiveRedShedThreadMessage(
	RedShedThread		*thread,
	AtomicMessageProc	filterProc,
	AtomicMessage		filterValue,
	long				*data1,
	long				*data2,
	long				*data3 );

#ifdef	__cplusplus
}
#endif

#endif	//	_RedShedThreads_



See more files for this project here

redshed

Code for Mac+WebObjects.

Project homepage: http://sourceforge.net/projects/redshed
Programming language(s): C,Java,Objective C
License: other

  RedShedThreadContext.c
  RedShedThreadContext.h
  RedShedThreads.c
  RedShedThreads.h