1 16 19 package com.sun.org.apache.xml.internal.dtm.ref; 20 21 import java.util.BitSet ; 22 23 import com.sun.org.apache.xml.internal.res.XMLErrorResources; 24 import com.sun.org.apache.xml.internal.res.XMLMessages; 25 26 27 104 public class CoroutineManager 105 { 106 111 BitSet m_activeIDs=new BitSet (); 112 113 119 static final int m_unreasonableId=1024; 120 121 147 Object m_yield=null; 148 149 final static int NOBODY=-1; 151 final static int ANYBODY=-1; 152 153 158 int m_nextCoroutine=NOBODY; 159 160 182 public synchronized int co_joinCoroutineSet(int coroutineID) 183 { 184 if(coroutineID>=0) 185 { 186 if(coroutineID>=m_unreasonableId || m_activeIDs.get(coroutineID)) 187 return -1; 188 } 189 else 190 { 191 coroutineID=0; 194 while(coroutineID<m_unreasonableId) 195 { 196 if(m_activeIDs.get(coroutineID)) 197 ++coroutineID; 198 else 199 break; 200 } 201 if(coroutineID>=m_unreasonableId) 202 return -1; 203 } 204 205 m_activeIDs.set(coroutineID); 206 return coroutineID; 207 } 208 209 224 public synchronized Object co_entry_pause(int thisCoroutine) throws java.lang.NoSuchMethodException 225 { 226 if(!m_activeIDs.get(thisCoroutine)) 227 throw new java.lang.NoSuchMethodException (); 228 229 while(m_nextCoroutine != thisCoroutine) 230 { 231 try 232 { 233 wait(); 234 } 235 catch(java.lang.InterruptedException e) 236 { 237 } 240 } 241 242 return m_yield; 243 } 244 245 259 public synchronized Object co_resume(Object arg_object,int thisCoroutine,int toCoroutine) throws java.lang.NoSuchMethodException 260 { 261 if(!m_activeIDs.get(toCoroutine)) 262 throw new java.lang.NoSuchMethodException (XMLMessages.createXMLMessage(XMLErrorResources.ER_COROUTINE_NOT_AVAIL, new Object []{Integer.toString(toCoroutine)})); 264 m_yield=arg_object; 267 m_nextCoroutine=toCoroutine; 268 269 notify(); 270 while(m_nextCoroutine != thisCoroutine || m_nextCoroutine==ANYBODY || m_nextCoroutine==NOBODY) 271 { 272 try 273 { 274 wait(); 276 } 277 catch(java.lang.InterruptedException e) 278 { 279 } 282 } 283 284 if(m_nextCoroutine==NOBODY) 285 { 286 co_exit(thisCoroutine); 288 throw new java.lang.NoSuchMethodException (XMLMessages.createXMLMessage(XMLErrorResources.ER_COROUTINE_CO_EXIT, null)); } 292 293 return m_yield; 294 } 295 296 309 public synchronized void co_exit(int thisCoroutine) 310 { 311 m_activeIDs.clear(thisCoroutine); 312 m_nextCoroutine=NOBODY; notify(); 314 } 315 316 328 public synchronized void co_exit_to(Object arg_object,int thisCoroutine,int toCoroutine) throws java.lang.NoSuchMethodException 329 { 330 if(!m_activeIDs.get(toCoroutine)) 331 throw new java.lang.NoSuchMethodException (XMLMessages.createXMLMessage(XMLErrorResources.ER_COROUTINE_NOT_AVAIL, new Object []{Integer.toString(toCoroutine)})); 333 m_yield=arg_object; 336 m_nextCoroutine=toCoroutine; 337 338 m_activeIDs.clear(thisCoroutine); 339 340 notify(); 341 } 342 } 343 | Popular Tags |