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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.utils.threads;
\r
15 * IThreadAccess is an interface for thread context switching.
\r
17 * TODO Yield that makes the thread do other tasks in queue
\r
19 * @Todo Queue open method + QueueClosed exception
\r
22 * @see CurrentThread
\r
23 * @author Toni Kalajainen
\r
25 public interface IThreadWorkQueue {
\r
28 * Execute runnable asynchronously.
\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
36 * @return the thread that is processing the runnable or null if thread refused to accept event
\r
38 Thread asyncExec(Runnable runnable);
\r
41 * Execute runnable synchronously.
\r
42 * This invocation will block until runnable has been executed.
\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
48 * @return true if thread accepted the event, false if not
\r
50 boolean syncExec(Runnable runnable);
\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
56 boolean currentThreadAccess();
\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
63 * @return thread or null
\r