Team Fortress 2 Source Code as on 22/4/2020
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.

69 lines
2.4 KiB

  1. //========= Copyright 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. typedef void (__cdecl *CoroutineFunc_t )(void *);
  19. // handle to a coroutine
  20. typedef int32 HCoroutine;
  21. // creates a new coroutine
  22. // no coroutine code is executed until Coroutine_Continue() is called
  23. VSTDLIB_INTERFACE HCoroutine Coroutine_Create( CoroutineFunc_t pFunc, void *pvParam );
  24. // continues the specified coroutine
  25. // returns true if the coroutine is still running, false otherwise
  26. VSTDLIB_INTERFACE bool Coroutine_Continue( HCoroutine hCoroutine, const char *pchName = NULL );
  27. // cancels a currently running coroutine
  28. VSTDLIB_INTERFACE void Coroutine_Cancel( HCoroutine hCoroutine );
  29. // 'load' a coroutine only to debug it - immediately breaks into debugger
  30. // when continued, pops back to the prior coroutine
  31. VSTDLIB_INTERFACE void Coroutine_DebugBreak( HCoroutine hCoroutine );
  32. // Load a coroutine and generate an assert. Used to get a minidump of a job
  33. VSTDLIB_INTERFACE void Coroutine_DebugAssert( HCoroutine hCoroutine, const char *pchMsg );
  34. // called from the coroutine to return control to the main thread
  35. VSTDLIB_INTERFACE void Coroutine_YieldToMain();
  36. // returns true if the code is currently running inside of a coroutine
  37. VSTDLIB_INTERFACE bool Coroutine_IsActive();
  38. // returns a handle the currently active coroutine
  39. VSTDLIB_INTERFACE HCoroutine Coroutine_GetCurrentlyActive();
  40. // call when a thread is quiting to release any per-thread memory
  41. VSTDLIB_INTERFACE void Coroutine_ReleaseThreadMemory();
  42. // runs a self-test of the coroutine system
  43. VSTDLIB_INTERFACE bool Coroutine_Test();
  44. // memory validation
  45. VSTDLIB_INTERFACE void Coroutine_ValidateGlobals( class CValidator &validator );
  46. // for debugging purposes - returns stack depth of current coroutine
  47. VSTDLIB_INTERFACE size_t Coroutine_GetStackDepth();
  48. #endif // COROUTINE_H