Show EventTasks.h syntax highlighted
/****************************************************************************************
EventTasks.h $Revision: 22 $
<http://rentzsch.com/eventTasks>
Copyright © 1999-2002 Red Shed Software. All rights reserved.
by Jonathan 'Wolf' Rentzsch (jon at redshed dot net)
************************************************************************************/
#ifndef _EventTasks_
#define _EventTasks_
#include "atomicity.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**************************
*
* Types
*
**************************/
#pragma mark (Types)
typedef struct EventTask EventTask;
typedef void (*EventTaskProc)( EventTask *task );
struct EventTask { // Offset Size Total
GuardedAtomicElement element; // 0 8 8 (must be 4 byte aligned)
UInt32 wakeup; // 8 4 12
EventTaskProc proc; // 12 4 16
void *refCon; // 16 4 20
};
/**************************
*
* Constants
*
**************************/
#pragma mark -
#pragma mark (Constants)
#define kForever 0
#define kPriority 1
#define kEventLoop 2
#define kFirstScheduled 3
#define kProcessorBound 4 // May have different value in the future.
/**************************
*
* Globals
*
**************************/
#pragma mark -
#pragma mark (Globals)
// In an effort to be lightweight, EventTasks makes you take responsiblity
// for providing it with a the current process' serial number.
//
// I recommend you put the following line of code in your application's main file:
// ProcessSerialNumber *gThisProcessSerialNumber = nil;
//
// Later on in your application's initialization, try to set this global variable to
// the correct value. EventTasks will still work if you don't, but it will lose its
// ability to tell the Process Manager to wake up the your process when an EventTask
// is scheduled when your application isn't frontmost.
//
// Losing this ability increases your application's latency, especially if your app
// is a Faceless Background Application (FBA).
extern ProcessSerialNumber *gThisProcessSerialNumber;
/**************************
*
* Interface
*
**************************/
#pragma mark -
#pragma mark (Interface)
extern
void
InitializeEventTask(
EventTask *task );
extern
Boolean
ScheduleEventTask(
EventTask *task,
UInt32 sleep );
extern
UInt32
PerformEventTasks(
UInt32 maxTaskTime );
/**************************
*
* TEventTask
*
**************************/
#pragma mark -
#pragma mark (TEventTask)
#ifdef __cplusplus
class TEventTask : public EventTask {
public:
TEventTask(
UInt32 sleep = kForever );
virtual
~TEventTask();
virtual
Boolean
ScheduleEventTask(
UInt32 sleep );
virtual
void
HandleEventTask();
private:
static
void
HandleEventTask_(
EventTask *task );
};
#endif
#ifdef __cplusplus
}
#endif
#endif // _EventTasks_
See more files for this project here