Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.5 KiB

  1. //====== Copyright 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: setjmp/longjmp based cooperative multitasking system
  4. //
  5. //=============================================================================
  6. #ifndef COROUTINE_H
  7. #define COROUTINE_H
  8. #pragma once
  9. #include "vstdlib/vstdlib.h"
  10. // enable this to do coroutine tracing
  11. // this will tell coroutine API users to set coroutine names
  12. // #define COROUTINE_TRACE
  13. //-----------------------------------------------------------------------------
  14. // Purpose: handles running coroutines
  15. // setjmp/longjmp based cooperative multitasking system
  16. //-----------------------------------------------------------------------------
  17. // coroutine callback
  18. #ifdef POSIX
  19. typedef void (*CoroutineFunc_t )(void *);
  20. #else
  21. typedef void (__cdecl *CoroutineFunc_t )(void *);
  22. #endif
  23. // handle to a coroutine
  24. typedef int32 HCoroutine;
  25. // creates a new coroutine
  26. // no coroutine code is executed until Coroutine_Continue() is called
  27. VSTDLIB_INTERFACE HCoroutine Coroutine_Create( CoroutineFunc_t pFunc, void *pvParam );
  28. // continues the specified coroutine
  29. // returns true if the coroutine is still running, false otherwise
  30. VSTDLIB_INTERFACE bool Coroutine_Continue( HCoroutine hCoroutine, const char *pchName = NULL );
  31. // cancels a currently running coroutine
  32. VSTDLIB_INTERFACE void Coroutine_Cancel( HCoroutine hCoroutine );
  33. // 'load' a coroutine only to debug it - immediately breaks into debugger
  34. // when continued, pops back to the prior coroutine
  35. VSTDLIB_INTERFACE void Coroutine_DebugBreak( HCoroutine hCoroutine );
  36. // Load a coroutine and generate an assert. Used to get a minidump of a job
  37. VSTDLIB_INTERFACE void Coroutine_DebugAssert( HCoroutine hCoroutine, const char *pchMsg );
  38. // called from the coroutine to return control to the main thread
  39. VSTDLIB_INTERFACE void Coroutine_YieldToMain();
  40. // returns true if the code is currently running inside of a coroutine
  41. VSTDLIB_INTERFACE bool Coroutine_IsActive();
  42. // returns a handle the currently active coroutine
  43. VSTDLIB_INTERFACE HCoroutine Coroutine_GetCurrentlyActive();
  44. // call when a thread is quiting to release any per-thread memory
  45. VSTDLIB_INTERFACE void Coroutine_ReleaseThreadMemory();
  46. // runs a self-test of the coroutine system
  47. VSTDLIB_INTERFACE bool Coroutine_Test();
  48. // memory validation
  49. VSTDLIB_INTERFACE void Coroutine_ValidateGlobals( class CValidator &validator );
  50. // for debugging purposes - returns stack depth of current coroutine
  51. VSTDLIB_INTERFACE size_t Coroutine_GetStackDepth();
  52. #endif // COROUTINE_H