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.

65 lines
2.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef THREADS_H
  14. #define THREADS_H
  15. #pragma once
  16. // Arrays that are indexed by thread should always be MAX_TOOL_THREADS+1
  17. // large so THREADINDEX_MAIN can be used from the main thread.
  18. #define MAX_TOOL_THREADS 16
  19. #define THREADINDEX_MAIN (MAX_TOOL_THREADS)
  20. extern int numthreads;
  21. // If set to true, then all the threads that are created are low priority.
  22. extern bool g_bLowPriorityThreads;
  23. typedef void (*ThreadWorkerFn)( int iThread, int iWorkItem );
  24. typedef void (*RunThreadsFn)( int iThread, void *pUserData );
  25. enum ERunThreadsPriority
  26. {
  27. k_eRunThreadsPriority_UseGlobalState=0, // Default.. uses g_bLowPriorityThreads to decide what to set the priority to.
  28. k_eRunThreadsPriority_Normal, // Doesn't touch thread priorities.
  29. k_eRunThreadsPriority_Idle // Sets threads to idle priority.
  30. };
  31. // Put the process into an idle priority class so it doesn't hog the UI.
  32. void SetLowPriority();
  33. void ThreadSetDefault (void);
  34. int GetThreadWork (void);
  35. void RunThreadsOnIndividual ( int workcnt, qboolean showpacifier, ThreadWorkerFn fn );
  36. void RunThreadsOn ( int workcnt, qboolean showpacifier, RunThreadsFn fn, void *pUserData=NULL );
  37. // This version doesn't track work items - it just runs your function and waits for it to finish.
  38. void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority=k_eRunThreadsPriority_UseGlobalState );
  39. void RunThreads_End();
  40. void ThreadLock (void);
  41. void ThreadUnlock (void);
  42. #ifndef NO_THREAD_NAMES
  43. #define RunThreadsOn(n,p,f) { if (p) printf("%-20s ", #f ":"); RunThreadsOn(n,p,f); }
  44. #define RunThreadsOnIndividual(n,p,f) { if (p) printf("%-20s ", #f ":"); RunThreadsOnIndividual(n,p,f); }
  45. #endif
  46. #endif // THREADS_H