diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/utils/common/threads.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/utils/common/threads.h')
| -rw-r--r-- | mp/src/utils/common/threads.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/mp/src/utils/common/threads.h b/mp/src/utils/common/threads.h new file mode 100644 index 00000000..e29e9aab --- /dev/null +++ b/mp/src/utils/common/threads.h @@ -0,0 +1,65 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $Workfile: $
+// $Date: $
+//
+//-----------------------------------------------------------------------------
+// $Log: $
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef THREADS_H
+#define THREADS_H
+#pragma once
+
+
+// Arrays that are indexed by thread should always be MAX_TOOL_THREADS+1
+// large so THREADINDEX_MAIN can be used from the main thread.
+#define MAX_TOOL_THREADS 16
+#define THREADINDEX_MAIN (MAX_TOOL_THREADS)
+
+
+extern int numthreads;
+
+// If set to true, then all the threads that are created are low priority.
+extern bool g_bLowPriorityThreads;
+
+typedef void (*ThreadWorkerFn)( int iThread, int iWorkItem );
+typedef void (*RunThreadsFn)( int iThread, void *pUserData );
+
+
+enum ERunThreadsPriority
+{
+ k_eRunThreadsPriority_UseGlobalState=0, // Default.. uses g_bLowPriorityThreads to decide what to set the priority to.
+ k_eRunThreadsPriority_Normal, // Doesn't touch thread priorities.
+ k_eRunThreadsPriority_Idle // Sets threads to idle priority.
+};
+
+
+// Put the process into an idle priority class so it doesn't hog the UI.
+void SetLowPriority();
+
+void ThreadSetDefault (void);
+int GetThreadWork (void);
+
+void RunThreadsOnIndividual ( int workcnt, qboolean showpacifier, ThreadWorkerFn fn );
+
+void RunThreadsOn ( int workcnt, qboolean showpacifier, RunThreadsFn fn, void *pUserData=NULL );
+
+// This version doesn't track work items - it just runs your function and waits for it to finish.
+void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority=k_eRunThreadsPriority_UseGlobalState );
+void RunThreads_End();
+
+void ThreadLock (void);
+void ThreadUnlock (void);
+
+
+#ifndef NO_THREAD_NAMES
+#define RunThreadsOn(n,p,f) { if (p) printf("%-20s ", #f ":"); RunThreadsOn(n,p,f); }
+#define RunThreadsOnIndividual(n,p,f) { if (p) printf("%-20s ", #f ":"); RunThreadsOnIndividual(n,p,f); }
+#endif
+
+#endif // THREADS_H
|