git-svn-id: file:///svnroot/lcore/trunk@5 b1de8a11-f9be-4011-bde0-cc7ace90066a
authorbeware <beware@bircd.org>
Sun, 30 Mar 2008 00:45:46 +0000 (00:45 +0000)
committerbeware <beware@bircd.org>
Sun, 30 Mar 2008 00:45:46 +0000 (00:45 +0000)
unitsettc.pas [new file with mode: 0644]

diff --git a/unitsettc.pas b/unitsettc.pas
new file mode 100644 (file)
index 0000000..7dc1229
--- /dev/null
@@ -0,0 +1,53 @@
+{ Copyright (C) 2005 Bas Steendijk and Peter Green\r
+  For conditions of distribution and use, see copyright notice in zlib_license.txt\r
+  which is included in the package\r
+  ----------------------------------------------------------------------------- }\r
+\r
+unit Unitsettc;\r
+\r
+interface\r
+\r
+procedure settc;\r
+procedure unsettc;\r
+\r
+implementation\r
+\r
+uses\r
+  windows,\r
+  sysutils;\r
+\r
+var\r
+  classpriority,threadpriority:integer;\r
+  refcount:integer=0;\r
+\r
+procedure settc;\r
+var\r
+  hprocess,hthread:integer;\r
+begin\r
+  if (refcount = 0) then begin\r
+    hProcess := GetCurrentProcess;\r
+    hThread := GetCurrentThread;\r
+    ClassPriority := GetPriorityClass(hProcess);\r
+    ThreadPriority := GetThreadPriority(hThread);\r
+    SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);\r
+    SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);\r
+  end;\r
+  inc(refcount);\r
+end;\r
+\r
+procedure unsettc;\r
+var\r
+  hprocess,hthread:integer;\r
+begin\r
+  dec(refcount);\r
+  if (refcount < 0) then refcount := 0;\r
+  if (refcount = 0) then begin\r
+    hProcess := GetCurrentProcess;\r
+    hThread := GetCurrentThread;\r
+    SetPriorityClass(hProcess, ClassPriority);\r
+    SetThreadPriority(hThread,  ThreadPriority);\r
+  end;\r
+end;\r
+\r
+end.\r
+\r