From 7c68f34483d40d75f98f9959484ca921d51d2ff1 Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Sun, 19 Jan 2003 11:35:38 +0000
Subject: [PATCH] From Bertrand: Here is TWinNTSystem.cxx who solves the
 problem of 100% CPU usage in batch mode...and speeds up benchmarks.c executed
 in batch mode as : root -b -q benchmarks.c

git-svn-id: http://root.cern.ch/svn/root/trunk@5938 27541ba8-7e3a-0410-8455-c3a389f83636
---
 winnt/src/TWinNTSystem.cxx | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/winnt/src/TWinNTSystem.cxx b/winnt/src/TWinNTSystem.cxx
index 9396b219396..90cd9d78b71 100644
--- a/winnt/src/TWinNTSystem.cxx
+++ b/winnt/src/TWinNTSystem.cxx
@@ -1,4 +1,4 @@
-// @(#)root/winnt:$Name:  $:$Id: TWinNTSystem.cxx,v 1.37 2002/12/10 17:26:48 rdm Exp $
+// @(#)root/winnt:$Name:  $:$Id: TWinNTSystem.cxx,v 1.38 2002/12/10 21:39:44 brun Exp $
 // Author: Fons Rademakers   15/09/95
 
 /*************************************************************************
@@ -322,9 +322,11 @@ Bool_t TWinNTSystem::Init()
    fhTermInputEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
 
 #ifdef GDK_WIN32
-    hEvent1 = CreateEvent(NULL, TRUE, FALSE, NULL);
-    hThread1 = (HANDLE)_beginthreadex( NULL, 0, &HandleConsoleThread, fhTermInputEvent, 0,
-        &thread1ID );
+    if (!gROOT->IsBatch()) {
+        hEvent1 = CreateEvent(NULL, TRUE, FALSE, NULL);
+        hThread1 = (HANDLE)_beginthreadex( NULL, 0, &HandleConsoleThread, fhTermInputEvent, 0,
+            &thread1ID );
+    }
 
 #endif
 
@@ -708,6 +710,14 @@ void TWinNTSystem::DispatchOneEvent(Bool_t pendingOnly)
 {
  // Dispatch a single event via Command thread
 
+   if (gROOT->IsBatch()) {
+      if (!gApplication->HandleTermInput()) {
+          // wait ExitLoop()
+          WaitForSingleObject(fhTermInputEvent,INFINITE);
+          ResetEvent(fhTermInputEvent);
+      }
+      return;
+   }
    while (1) {
       fReadready  = fReadmask;
       fWriteready = fWritemask;
-- 
GitLab