annotate org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Lock.d @ 113:fb3aa8075988

D2 support for the linux port.
author Jacob Carlborg <doob@me.com>
date Wed, 06 Apr 2011 21:57:23 +0200
parents 0ecb2b338560
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module org.eclipse.swt.internal.Lock;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 22
diff changeset
15 import java.lang.all;
19
52184e4b815c no more direct tango.core.Thread. Rename JThread to java.lang.Thread.
Frank Benoit <benoit@tionex.de>
parents: 0
diff changeset
16 import java.lang.Thread;
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
17 version(Tango){
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
18 import tango.core.sync.Mutex;
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
19 import tango.core.sync.Condition;
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
20 } else {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
21 import core.sync.mutex;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
22 import core.sync.condition;
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
23 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 /**
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 * Instance of this represent a recursive monitor.
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 */
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 public class Lock {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 int count, waitCount;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 Thread owner;
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
31 Mutex mutex;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
32 Condition cond;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 public this() {
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
35 mutex = new Mutex;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
36 cond = new Condition(mutex);
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 }
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
38 /**
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
39 * Locks the monitor and returns the lock count. If
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
40 * the lock is owned by another thread, wait until
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
41 * the lock is released.
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
42 *
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
43 * @return the lock count
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
44 */
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
45 public int lock() {
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
46 synchronized (mutex) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
47 Thread current = Thread.currentThread();
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
48 if (owner !is current) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
49 waitCount++;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
50 while (count > 0) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
51 try {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
52 cond.wait();
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
53 } catch (SyncException e) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
54 /* Wait forever, just like synchronized blocks */
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
55 }
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
56 }
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
57 --waitCount;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
58 owner = current;
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
59 }
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
60 return ++count;
22
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
61 }
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
62 }
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
63
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
64 /**
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
65 * Unlocks the monitor. If the current thread is not
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
66 * the monitor owner, do nothing.
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
67 */
4642ab680468 some work on dwt-win for tango/phobos
Frank Benoit <benoit@tionex.de>
parents: 19
diff changeset
68 public void unlock() {
113
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
69 synchronized (mutex) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
70 Thread current = Thread.currentThread();
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
71 if (owner is current) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
72 if (--count is 0) {
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
73 owner = null;
fb3aa8075988 D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents: 39
diff changeset
74 if (waitCount > 0) cond.notifyAll();
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 }