Java 类edu.wpi.first.wpilibj.communication.Semaphore 实例源码

项目:wpilibj    文件:JaguarCANDriver.java   
/**
 * Start waiting for a message to be received from the CAN bus.
 * @param messageID MessageID filter to specify what message ID to be expected.
 * @param sem Semaphore that indicates that the receive call has completed.
 * @param timeout Number of seconds to wait for the expected message.
 * @return Data available now... call complete
 */
public boolean receiveMessageStart(int messageID, Semaphore sem, double timeout) throws CANTimeoutException {
    int retVal = 0;
    IntByReference recvStatus = new IntByReference(0);
    recvStatus.setValue(0);
    retVal = receiveMessageStart_semFn.call4(messageID, sem.getPointer(), (int) (timeout * 1000.0), recvStatus.getPointer().address().toUWord().toPrimitive());
    int statusValue = recvStatus.getValue();
    recvStatus.free();
    CANExceptionFactory.checkStatus(statusValue, messageID);
    return retVal != 0;
}
项目:Iapetus2014    文件:Subsystem.java   
private void acquireResources() throws SemaphoreException {
    Enumeration e = resources.elements();
    while (e.hasMoreElements()) {
        Semaphore s = (Semaphore) e.nextElement();
        s.takeMillis(500);
    }
}
项目:Iapetus2014    文件:Subsystem.java   
private void releaseResources() {
    Enumeration e = resources.elements();
    while (e.hasMoreElements()) {
        Semaphore s = (Semaphore) e.nextElement();
        try {
            s.give();
        } catch (final SemaphoreException se) {
        }
    }
}
项目:wpilib-java    文件:JaguarCANDriver.java   
/**
 * Start waiting for a message to be received from the CAN bus.
 * @param messageID MessageID filter to specify what message ID to be expected.
 * @param sem Semaphore that indicates that the receive call has completed.
 * @param timeout Number of seconds to wait for the expected message.
 * @return Data available now... call complete
 */
public boolean receiveMessageStart(int messageID, Semaphore sem, double timeout) throws CANTimeoutException {
    int retVal = 0;
    IntByReference recvStatus = new IntByReference(0);
    recvStatus.setValue(0);
    retVal = receiveMessageStart_semFn.call4(messageID, sem.getPointer(), (int) (timeout * 1000.0), recvStatus.getPointer().address().toUWord().toPrimitive());
    int statusValue = recvStatus.getValue();
    recvStatus.free();
    CANExceptionFactory.checkStatus(statusValue, messageID);
    return retVal != 0;
}