aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/vstdlib/coroutine.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/public/vstdlib/coroutine.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/public/vstdlib/coroutine.h')
-rw-r--r--sp/src/public/vstdlib/coroutine.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/sp/src/public/vstdlib/coroutine.h b/sp/src/public/vstdlib/coroutine.h
new file mode 100644
index 00000000..c367ffa2
--- /dev/null
+++ b/sp/src/public/vstdlib/coroutine.h
@@ -0,0 +1,69 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: setjmp/longjmp based cooperative multitasking system
+//
+//=============================================================================
+
+#ifndef COROUTINE_H
+#define COROUTINE_H
+#pragma once
+
+#include "vstdlib/vstdlib.h"
+
+// enable this to do coroutine tracing
+// this will tell coroutine API users to set coroutine names
+// #define COROUTINE_TRACE
+
+//-----------------------------------------------------------------------------
+// Purpose: handles running coroutines
+// setjmp/longjmp based cooperative multitasking system
+//-----------------------------------------------------------------------------
+
+// coroutine callback
+typedef void (__cdecl *CoroutineFunc_t )(void *);
+
+// handle to a coroutine
+typedef int32 HCoroutine;
+
+// creates a new coroutine
+// no coroutine code is executed until Coroutine_Continue() is called
+VSTDLIB_INTERFACE HCoroutine Coroutine_Create( CoroutineFunc_t pFunc, void *pvParam );
+
+// continues the specified coroutine
+// returns true if the coroutine is still running, false otherwise
+VSTDLIB_INTERFACE bool Coroutine_Continue( HCoroutine hCoroutine, const char *pchName = NULL );
+
+// cancels a currently running coroutine
+VSTDLIB_INTERFACE void Coroutine_Cancel( HCoroutine hCoroutine );
+
+// 'load' a coroutine only to debug it - immediately breaks into debugger
+// when continued, pops back to the prior coroutine
+VSTDLIB_INTERFACE void Coroutine_DebugBreak( HCoroutine hCoroutine );
+
+// Load a coroutine and generate an assert. Used to get a minidump of a job
+VSTDLIB_INTERFACE void Coroutine_DebugAssert( HCoroutine hCoroutine, const char *pchMsg );
+
+// called from the coroutine to return control to the main thread
+VSTDLIB_INTERFACE void Coroutine_YieldToMain();
+
+// returns true if the code is currently running inside of a coroutine
+VSTDLIB_INTERFACE bool Coroutine_IsActive();
+
+// returns a handle the currently active coroutine
+VSTDLIB_INTERFACE HCoroutine Coroutine_GetCurrentlyActive();
+
+// call when a thread is quiting to release any per-thread memory
+VSTDLIB_INTERFACE void Coroutine_ReleaseThreadMemory();
+
+// runs a self-test of the coroutine system
+VSTDLIB_INTERFACE bool Coroutine_Test();
+
+// memory validation
+VSTDLIB_INTERFACE void Coroutine_ValidateGlobals( class CValidator &validator );
+
+// for debugging purposes - returns stack depth of current coroutine
+VSTDLIB_INTERFACE size_t Coroutine_GetStackDepth();
+
+
+
+#endif // COROUTINE_H