01: /*
02: * $RCSfile: MasterControlThread.java,v $
03: *
04: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06: *
07: * This code is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License version 2 only, as
09: * published by the Free Software Foundation. Sun designates this
10: * particular file as subject to the "Classpath" exception as provided
11: * by Sun in the LICENSE file that accompanied this code.
12: *
13: * This code is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: * version 2 for more details (a copy is included in the LICENSE file that
17: * accompanied this code).
18: *
19: * You should have received a copy of the GNU General Public License version
20: * 2 along with this work; if not, write to the Free Software Foundation,
21: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22: *
23: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24: * CA 95054 USA or visit www.sun.com if you need additional information or
25: * have any questions.
26: *
27: * $Revision: 1.6 $
28: * $Date: 2008/02/28 20:17:26 $
29: * $State: Exp $
30: */
31:
32: package javax.media.j3d;
33:
34: /**
35: * Master control thread. The MasterControlThread object and thread
36: * are created dynamically whenever needed. Once created, the thread
37: * runs until all other threads are terminated. Then the master
38: * control thread terminates. There is never more than one
39: * MasterControl object or thread in existence at any one time.
40: */
41: class MasterControlThread extends Thread {
42:
43: private static int numInstances = 0;
44: private int instanceNum = -1;
45:
46: private static synchronized int newInstanceNum() {
47: return (++numInstances);
48: }
49:
50: private int getInstanceNum() {
51: if (instanceNum == -1)
52: instanceNum = newInstanceNum();
53: return instanceNum;
54: }
55:
56: MasterControlThread(ThreadGroup threadGroup) {
57: super (threadGroup, "");
58: setName("J3D-MasterControl-" + getInstanceNum());
59: VirtualUniverse.mc.createMCThreads();
60: this .start();
61: }
62:
63: public void run() {
64:
65: do {
66: while (VirtualUniverse.mc.running) {
67: VirtualUniverse.mc.doWork();
68:
69: // NOTE: no need to call Thread.yield(), since we will
70: // call wait() if there is no work to do (yield seems
71: // to be a no-op on Windows anyway)
72: }
73: } while (!VirtualUniverse.mc.mcThreadDone());
74:
75: if (J3dDebug.devPhase) {
76: J3dDebug.doDebug(J3dDebug.masterControl, J3dDebug.LEVEL_1,
77: "MC: MasterControl Thread Terminate");
78: }
79: }
80: }
|