]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.utils.threads;\r
13 \r
14 /**\r
15  * IThreadAccess is an interface for thread context switching.\r
16  * \r
17  * TODO Yield that makes the thread do other tasks in queue\r
18  * \r
19  * @Todo Queue open method + QueueClosed exception\r
20  * @see SWTThread\r
21  * @see AWTThread\r
22  * @see CurrentThread\r
23  * @author Toni Kalajainen\r
24  */\r
25 public interface IThreadWorkQueue {\r
26 \r
27         /**\r
28          * Execute runnable asynchronously.\r
29          * <p>\r
30          * Note!\r
31          * Do not call this method directly unless the instance has been wrapped with \r
32          * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.asyncExec.\r
33          * \r
34          * \r
35          * @param runnable\r
36          * @return the thread that is processing the runnable or null if thread refused to accept event\r
37          */\r
38         Thread asyncExec(Runnable runnable);\r
39         \r
40         /**\r
41          * Execute runnable synchronously. \r
42          * This invocation will block until runnable has been executed.\r
43          * Note!\r
44          * Do not call this method directly unless the instance has been wrapped with \r
45          * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.syncExec.\r
46          * \r
47          * @param runnable\r
48          * @return true if thread accepted the event, false if not\r
49          */\r
50         boolean syncExec(Runnable runnable);\r
51         \r
52         /**\r
53          * Is the current thread the same as this access\r
54          * @return <code>true</code> if current thread is the same as this queue uses\r
55          */\r
56         boolean currentThreadAccess();\r
57         \r
58         /**\r
59          * Get the thread. May return null if the thread has not been initialized.\r
60          * The returned thread may also change right after call if no runnables are\r
61          * in queue.\r
62          * \r
63          * @return thread or null\r
64          */\r
65         Thread getThread();\r
66 \r
67 }\r