]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/CurrentThread.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / CurrentThread.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 /*\r
13  *\r
14  * @author Toni Kalajainen\r
15  */\r
16 package org.simantics.utils.threads;\r
17 \r
18 import java.util.concurrent.Executor;\r
19 \r
20 \r
21 /**\r
22  * No thread switching\r
23  * \r
24  * @Todo Rename to InvokerWorks\r
25  */\r
26 public class CurrentThread implements IThreadWorkQueue, Executor {\r
27 \r
28         static CurrentThread INSTANCE = new CurrentThread();\r
29         \r
30         public static IThreadWorkQueue getThreadAccess()\r
31         {\r
32                 return INSTANCE;\r
33         }\r
34         \r
35         CurrentThread() {}\r
36         \r
37         @Override\r
38         public Thread asyncExec(Runnable runnable) {\r
39                 runnable.run();\r
40                 return Thread.currentThread();\r
41         }\r
42 \r
43         @Override\r
44         public boolean syncExec(Runnable runnable) {\r
45                 runnable.run();\r
46                 return true;\r
47         }\r
48 \r
49         @Override\r
50         public boolean currentThreadAccess() {\r
51                 return true;\r
52         }\r
53 \r
54         @Override\r
55         public Thread getThread() {\r
56                 return Thread.currentThread();\r
57         }\r
58         \r
59         @Override\r
60         public String toString() {\r
61                 return "Current thread";\r
62         }\r
63 \r
64         @Override\r
65         public void execute(Runnable command) {\r
66                 command.run();\r
67         }\r
68 }\r