]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/CurrentThread.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / CurrentThread.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.threads;
17
18 import java.util.concurrent.Executor;
19
20
21 /**
22  * No thread switching
23  * 
24  * @Todo Rename to InvokerWorks
25  */
26 public class CurrentThread implements IThreadWorkQueue, Executor {
27
28         static CurrentThread INSTANCE = new CurrentThread();
29         
30         public static IThreadWorkQueue getThreadAccess()
31         {
32                 return INSTANCE;
33         }
34         
35         CurrentThread() {}
36         
37         @Override
38         public Thread asyncExec(Runnable runnable) {
39                 runnable.run();
40                 return Thread.currentThread();
41         }
42
43         @Override
44         public boolean syncExec(Runnable runnable) {
45                 runnable.run();
46                 return true;
47         }
48
49         @Override
50         public boolean currentThreadAccess() {
51                 return true;
52         }
53
54         @Override
55         public Thread getThread() {
56                 return Thread.currentThread();
57         }
58         
59         @Override
60         public String toString() {
61                 return "Current thread";
62         }
63
64         @Override
65         public void execute(Runnable command) {
66                 command.run();
67         }
68 }