-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiber_job_system.cpp
More file actions
40 lines (34 loc) · 1.08 KB
/
fiber_job_system.cpp
File metadata and controls
40 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "fiber_job_system.h"
#include "mutex.h"
// Job specific
bool FiberJobThread_LockMutex( Mutex* mutex, unsigned long msTimeout )
{
bool result = mutex->lock( 0 ); // Try and get the mutex immediately
if ( !result )
{
// Implementation specific but needs to switch the thread to another fiber if it cannot lock the mutex rather than waiting
// so other work can run until the mutex is available
result = Job_WaitOnMutex( mutex, msTimeout );
}
return false;
}
void FiberJobThread_Sleep( unsigned long msTimeout )
{
// Yield the fiber for the provided time in milliseconds
Job_Sleep( msTimeout );
}
ThreadFunctionTable g_fiberJobThreadFunctionTable =
{
&FiberJobThread_LockMutex,
&FiberJobThread_Sleep,
};
// Dummy implementations of job work just to indicate different program flow
void Job_Sleep( unsigned long )
{
OutputDebugString( "Yielding fiber" );
}
bool Job_WaitOnMutex( Mutex*, unsigned long )
{
OutputDebugString( "Yielding fiber until mutex is available" );
return false;
}