All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jclarion.clarion.runtime.concurrent.ICriticalSection Maven / Gradle / Ivy

The newest version!
package org.jclarion.clarion.runtime.concurrent;

public class ICriticalSection extends ISyncObject 
{
    private Thread  lockHolder;
    private int     lockCount;

    @Override
    public void Kill() 
    {
        synchronized(this) {
            lockCount=0;
            notifyAll();
        }
    }

    @Override
    public void Release() {
        synchronized(this) {
            if (lockCount>0) lockCount--;
            notifyAll();
        }
    }

    @Override
    public void Wait() {
        synchronized(this) {
            if (lockCount>0 && lockHolder!=Thread.currentThread()) { 
                while (lockCount>0) {
                    try {
                        wait();
                    } catch (InterruptedException e) {
                    }
                }
            }
            lockCount=1;
            lockHolder=Thread.currentThread();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy