]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/IThreadWorkQueue.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / IThreadWorkQueue.java
diff --git a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/IThreadWorkQueue.java b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/IThreadWorkQueue.java
new file mode 100644 (file)
index 0000000..a7114f9
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.utils.threads;\r
+\r
+/**\r
+ * IThreadAccess is an interface for thread context switching.\r
+ * \r
+ * TODO Yield that makes the thread do other tasks in queue\r
+ * \r
+ * @Todo Queue open method + QueueClosed exception\r
+ * @see SWTThread\r
+ * @see AWTThread\r
+ * @see CurrentThread\r
+ * @author Toni Kalajainen\r
+ */\r
+public interface IThreadWorkQueue {\r
+\r
+       /**\r
+        * Execute runnable asynchronously.\r
+        * <p>\r
+        * Note!\r
+        * Do not call this method directly unless the instance has been wrapped with \r
+        * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.asyncExec.\r
+        * \r
+        * \r
+        * @param runnable\r
+        * @return the thread that is processing the runnable or null if thread refused to accept event\r
+        */\r
+       Thread asyncExec(Runnable runnable);\r
+       \r
+       /**\r
+        * Execute runnable synchronously. \r
+        * This invocation will block until runnable has been executed.\r
+        * Note!\r
+        * Do not call this method directly unless the instance has been wrapped with \r
+        * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.syncExec.\r
+        * \r
+        * @param runnable\r
+        * @return true if thread accepted the event, false if not\r
+        */\r
+       boolean syncExec(Runnable runnable);\r
+       \r
+       /**\r
+        * Is the current thread the same as this access\r
+        * @return <code>true</code> if current thread is the same as this queue uses\r
+        */\r
+       boolean currentThreadAccess();\r
+       \r
+       /**\r
+        * Get the thread. May return null if the thread has not been initialized.\r
+        * The returned thread may also change right after call if no runnables are\r
+        * in queue.\r
+        * \r
+        * @return thread or null\r
+        */\r
+       Thread getThread();\r
+\r
+}\r