Descent3/lib/TaskSystem.h

105 lines
2.4 KiB
C
Raw Normal View History

2024-04-16 03:43:29 +00:00
/*
* $Logfile: /DescentIII/Main/lib/TaskSystem.h $
* $Revision: 3 $
* $Date: 9/14/98 4:02p $
* $Author: Samir $
*
* Task manager
*
* $Log: /DescentIII/Main/lib/TaskSystem.h $
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 3 9/14/98 4:02p Samir
* allow variable lengths of blocking for tasks.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 2 8/10/98 5:54p Samir
* added mutexes.
2024-04-16 18:56:40 +00:00
*
2024-04-16 03:43:29 +00:00
* 1 5/23/97 4:07p Samir
* Initial revision.
*
* $NoKeywords: $
*/
#ifndef TASKSYSTEM_H
#define TASKSYSTEM_H
#include "pstypes.h"
2024-04-16 18:56:40 +00:00
typedef enum tTaskPriority { TASKPRIORITY_HIGHEST, TASKPRIORITY_NORMAL, TASKPRIORITY_LOWEST } tTaskPriority;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// Since this system handles concepts such as multitasking, and the such,
2024-04-16 03:43:29 +00:00
// we will define the event structures differently, since different systems
// handle multitasking differently.
2024-04-16 18:56:40 +00:00
class osEvent {
2024-04-16 03:43:29 +00:00
#if defined(DD_ACCESS_RING)
public:
#else
private:
2024-04-16 18:56:40 +00:00
#endif // DD_ACCESS_RING_0
2024-04-16 03:43:29 +00:00
#if defined(WIN32)
2024-04-16 18:56:40 +00:00
unsigned event_os_handle; // this is the Win32 Event Handle
#endif // WIN32
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
osEvent(char *name);
~osEvent();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool error() const; // reports error
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void signal(); // signal the event so blocking can stop
void clear(); // clear the event so blocking can continue
bool block(int timeout = -1); // block until signaled (-1 = full blocking, else time in ms to block)
2024-04-16 03:43:29 +00:00
};
2024-04-16 18:56:40 +00:00
class osTask {
2024-04-16 03:43:29 +00:00
#if defined(DD_ACCESS_RING)
public:
#else
private:
2024-04-16 18:56:40 +00:00
#endif // DD_ACCESS_RING_0
2024-04-16 03:43:29 +00:00
#if defined(WIN32)
2024-04-16 18:56:40 +00:00
unsigned task_os_handle; // This is the Win32 EventHandle
unsigned task_os_id; // Win32 Thread ID
#endif // WIN32
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
osTask(unsigned (*func)(void *), tTaskPriority priority, void *parm = NULL);
~osTask();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool error() const; // reports error
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void suspend(); // suspends task
void resume(); // resumes task
2024-04-16 03:43:29 +00:00
};
2024-04-16 18:56:40 +00:00
// This establishes a mutual exclusion object. once one thread locks the object,
2024-04-16 03:43:29 +00:00
// any code in another thread that contains a mutex check will block or skip that code until
// the locking thread unlocks it.
2024-04-16 18:56:40 +00:00
class osMutex {
2024-04-16 03:43:29 +00:00
#if defined(DD_ACCESS_RING)
public:
#else
private:
#endif
#if defined(WIN32)
2024-04-16 18:56:40 +00:00
unsigned mutex_os_handle;
2024-04-16 03:43:29 +00:00
#endif
public:
2024-04-16 18:56:40 +00:00
osMutex();
~osMutex();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool Create(); // creates a mutex object.
void Destroy(); // destroys a mutex object
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// calling thread will attempt to acquire mutex (wait until timeout in ms.) if timeout == -1, wait forever...
bool Acquire(int timeout = -1);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// calling thread releases control of mutex.
void Release();
};
2024-04-16 03:43:29 +00:00
#endif