{* *}
code teams

UsecSleep



/********************************************************************
* Function: usec_sleep
*
* Author: Stefan Willmert
*
* Description: Use this method to sleep without a busy wait cycle
*     on the cpu. Pass in the number of usecs to sleep. 
*     1 second = 1000000 usecs
*     returns 0 for success -1 for failure
*
*********************************************************************/
int usec_sleep(long usecs)
{
    /*
     * Sleep for a little while.  Using select() so we don't busy-
     *  wait for this long.
     */

    struct timeval sleeptime;
    int tmperrno;


    sleeptime.tv_sec = usecs / 1000000;
    sleeptime.tv_usec = usecs % 1000000;

    if (select(0, NULL, NULL, NULL, &sleeptime) < 0) {
	tmperrno = errno;
	perror("select");
	errno = tmperrno;
        return -1;
    }
	
    return 0;
}