Implementing timeout for system calls - VxWorks

This is a discussion on Implementing timeout for system calls - VxWorks ; Hi, I wonder whether I can implement timeout for VxWorks system calls as following. Also, I want to know whether this implementation could corrupt VxWorks semaphore data structures. I cannot use the original VxWorks semaphore with timeout in my program. ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Implementing timeout for system calls

  1. Implementing timeout for system calls

    Hi,
    I wonder whether I can implement timeout for VxWorks system calls as
    following. Also, I want to know whether this implementation could
    corrupt VxWorks semaphore data structures.

    I cannot use the original VxWorks semaphore with timeout in my
    program.

    Thanks,
    Aung

    /* I adapted this example from Richard Stevens's Advanced Programming
    in the UNIX Environment book */

    /* timer interrupt handler will send a signal when timeout */
    void sig_timeout(int signo) {
    longjmp(env_timeout, 1);
    }

    int rr_semTakeTimeout(SEM_ID sem_id, int timeout) {
    STATUS volatile status = ERROR;

    signal(SIGUSR1, sig_timeout) == SIG_ERR;

    if (setjmp(env_timeout) == 0) {
    setHardwareTimer(timeout);
    status = semTake(sem_id, WAIT_FOREVER);
    deleteHardwareTimer(0);
    }
    return status;
    }


  2. Re: Implementing timeout for system calls


    Aung wrote:
    > Hi,
    > I wonder whether I can implement timeout for VxWorks system calls as
    > following. Also, I want to know whether this implementation could
    > corrupt VxWorks semaphore data structures.
    >
    > I cannot use the original VxWorks semaphore with timeout in my
    > program.
    >
    > Thanks,
    > Aung
    >
    > /* I adapted this example from Richard Stevens's Advanced Programming
    > in the UNIX Environment book */
    >
    > /* timer interrupt handler will send a signal when timeout */
    > void sig_timeout(int signo) {
    > longjmp(env_timeout, 1);
    > }
    >
    > int rr_semTakeTimeout(SEM_ID sem_id, int timeout) {
    > STATUS volatile status = ERROR;
    >
    > signal(SIGUSR1, sig_timeout) == SIG_ERR;
    >
    > if (setjmp(env_timeout) == 0) {
    > setHardwareTimer(timeout);
    > status = semTake(sem_id, WAIT_FOREVER);
    > deleteHardwareTimer(0);
    > }
    > return status;
    > }



  3. Re: Implementing timeout for system calls

    That last reply didn't go well, did it? ;-)

    It comes down to whether you have the ability to clean up the semaphore
    and the blocked task from within the interrupt context. If that's not
    possible, then try a blocking option, if that's acceptable.

    Do the semTake() with NO_WAIT and spin through a while() loop during
    the timeout period, returning ERROR and setting errno to
    S_objlib_Timeout if you can't get the semaphore. That way, it is
    functionally equivalent to the semTake behavior, though with one
    glaring deficiency; task is blocked during the timeout period.

    There's a second option that would at least stay VxWorks portable and
    that would be to use the watchdog library. check the docs for the exact
    call, but it would be something along the lines of:

    WD_ID wdog = wdCreate();
    wdStart(wdog, timeoutTicks, timeoutFunc)
    return semTake(sem_id, WAIT_FOREVER);

    Same deal. You'll have to cleanup semaphore and task from timeoutFunc()
    in an interrupt context.


+ Reply to Thread