1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.threads;
15 * IThreadAccess is an interface for thread context switching.
17 * TODO Yield that makes the thread do other tasks in queue
19 * @Todo Queue open method + QueueClosed exception
23 * @author Toni Kalajainen
25 public interface IThreadWorkQueue {
28 * Execute runnable asynchronously.
31 * Do not call this method directly unless the instance has been wrapped with
32 * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.asyncExec.
36 * @return the thread that is processing the runnable or null if thread refused to accept event
38 Thread asyncExec(Runnable runnable);
41 * Execute runnable synchronously.
42 * This invocation will block until runnable has been executed.
44 * Do not call this method directly unless the instance has been wrapped with
45 * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.syncExec.
48 * @return true if thread accepted the event, false if not
50 boolean syncExec(Runnable runnable);
53 * Is the current thread the same as this access
54 * @return <code>true</code> if current thread is the same as this queue uses
56 boolean currentThreadAccess();
59 * Get the thread. May return null if the thread has not been initialized.
60 * The returned thread may also change right after call if no runnables are
63 * @return thread or null