// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:43:27
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/app/Semaphore

package com.macromedia.generator.app;


public class Semaphore
{

    public Semaphore(int i)
    {
        _fld0102 = 0;
        _fld0103 = 0;
        _fld0102 = i;
        _fld0103 = 0;
    }

    public synchronized void release()
    {
        _fld0102++;
        if(_fld0103 > 0)
            notify();
    }

    public synchronized boolean take()
        throws InterruptedException
    {
        return take(0);
    }

    public synchronized boolean take(int i)
        throws InterruptedException
    {
        while(_fld0102 < 1) 
        {
            try
            {
                _fld0103++;
                wait(i);
            }
            finally
            {
                _fld0103--;
            }
            if(i != 0 && _fld0102 < 1)
                return false;
        }
        _fld0102--;
        return true;
    }

    private int _fld0102;
    private int _fld0103;
}