Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2012-01-23 09:28:01 +0000
committerAnton Leherbauer2012-01-23 09:28:01 +0000
commit6f047bf6a21dcc9be9bf444da123e8b32834da52 (patch)
tree22cc2972f8bfa7a3693aa514ecef25581dd2dd32 /python/src/tcf/EventQueue.py
parenta1b540e1272eda3d1b09f3232512db9cc0f1d168 (diff)
downloadorg.eclipse.tcf-6f047bf6a21dcc9be9bf444da123e8b32834da52.tar.gz
org.eclipse.tcf-6f047bf6a21dcc9be9bf444da123e8b32834da52.tar.xz
org.eclipse.tcf-6f047bf6a21dcc9be9bf444da123e8b32834da52.zip
TCF Python: Unify line endings.
Diffstat (limited to 'python/src/tcf/EventQueue.py')
-rw-r--r--python/src/tcf/EventQueue.py162
1 files changed, 81 insertions, 81 deletions
diff --git a/python/src/tcf/EventQueue.py b/python/src/tcf/EventQueue.py
index 0efc5f60c..cc38aa245 100644
--- a/python/src/tcf/EventQueue.py
+++ b/python/src/tcf/EventQueue.py
@@ -1,81 +1,81 @@
-# *******************************************************************************
-# * Copyright (c) 2011 Wind River Systems, Inc. and others.
-# * All rights reserved. This program and the accompanying materials
-# * are made available under the terms of the Eclipse Public License v1.0
-# * which accompanies this distribution, and is available at
-# * http://www.eclipse.org/legal/epl-v10.html
-# *
-# * Contributors:
-# * Wind River Systems - initial API and implementation
-# *******************************************************************************
-
-import threading
-import protocol
-
-class EventQueue(object):
-
- def __init__(self, on_shutdown=None):
- self.__thread = threading.Thread(target=self, name="TCF Event Dispatcher")
- self.__thread.daemon = True
- self.__is_waiting = False
- self.__is_shutdown = False
- self.__on_shutdown = on_shutdown
- self.__lock = threading.Condition()
- self.__queue = []
-
- def start(self):
- self.__thread.start()
-
- def shutdown(self):
- try:
- if self.__on_shutdown:
- self.__on_shutdown()
- with self.__lock:
- self.__is_shutdown = True
- if self.__is_waiting:
- self.__is_waiting = False
- self.__lock.notifyAll()
- self.__thread.join()
- except Exception as e:
- protocol.log("Failed to shutdown TCF event dispatch thread", e)
-
- def isShutdown(self):
- with self._lock:
- return self.__is_shutdown
-
- def __error(self, x):
- protocol.log("Unhandled exception in TCF event dispatch", x)
-
- def __call__(self):
- while True:
- try:
- with self.__lock:
- while not self.__queue:
- if self.__is_shutdown: return
- self.__is_waiting = True
- self.__lock.wait()
- r, args, kwargs = self.__queue.pop(0)
- r(*args, **kwargs)
- except Exception as x:
- self.__error(x)
-
- def invokeLater(self, r, *args, **kwargs):
- assert r
- with self.__lock:
- if self.__is_shutdown: raise RuntimeError("TCF event dispatcher has shut down")
- self.__queue.append((r, args, kwargs))
- if self.__is_waiting:
- self.__is_waiting = False
- self.__lock.notifyAll()
-
- def isDispatchThread(self):
- return threading.currentThread() is self.__thread
-
- def getCongestion(self):
- with self.__lock:
- job_cnt = 0
- l0 = job_cnt / 10 - 100
- l1 = len(self.__queue) / 10 - 100
- if l1 > l0: l0 = l1
- if l0 > 100: l0 = 100
- return l0
+# *******************************************************************************
+# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Wind River Systems - initial API and implementation
+# *******************************************************************************
+
+import threading
+import protocol
+
+class EventQueue(object):
+
+ def __init__(self, on_shutdown=None):
+ self.__thread = threading.Thread(target=self, name="TCF Event Dispatcher")
+ self.__thread.daemon = True
+ self.__is_waiting = False
+ self.__is_shutdown = False
+ self.__on_shutdown = on_shutdown
+ self.__lock = threading.Condition()
+ self.__queue = []
+
+ def start(self):
+ self.__thread.start()
+
+ def shutdown(self):
+ try:
+ if self.__on_shutdown:
+ self.__on_shutdown()
+ with self.__lock:
+ self.__is_shutdown = True
+ if self.__is_waiting:
+ self.__is_waiting = False
+ self.__lock.notifyAll()
+ self.__thread.join()
+ except Exception as e:
+ protocol.log("Failed to shutdown TCF event dispatch thread", e)
+
+ def isShutdown(self):
+ with self._lock:
+ return self.__is_shutdown
+
+ def __error(self, x):
+ protocol.log("Unhandled exception in TCF event dispatch", x)
+
+ def __call__(self):
+ while True:
+ try:
+ with self.__lock:
+ while not self.__queue:
+ if self.__is_shutdown: return
+ self.__is_waiting = True
+ self.__lock.wait()
+ r, args, kwargs = self.__queue.pop(0)
+ r(*args, **kwargs)
+ except Exception as x:
+ self.__error(x)
+
+ def invokeLater(self, r, *args, **kwargs):
+ assert r
+ with self.__lock:
+ if self.__is_shutdown: raise RuntimeError("TCF event dispatcher has shut down")
+ self.__queue.append((r, args, kwargs))
+ if self.__is_waiting:
+ self.__is_waiting = False
+ self.__lock.notifyAll()
+
+ def isDispatchThread(self):
+ return threading.currentThread() is self.__thread
+
+ def getCongestion(self):
+ with self.__lock:
+ job_cnt = 0
+ l0 = job_cnt / 10 - 100
+ l1 = len(self.__queue) / 10 - 100
+ if l1 > l0: l0 = l1
+ if l0 > 100: l0 = 100
+ return l0

Back to the top