Hi Stipe Patch attached.
Werner -----Original Message----- From: Stipe Tolj [mailto:[EMAIL PROTECTED] Sent: 02 July 2008 16:18 To: Werner Coetzee Cc: devel@kannel.org Subject: Re: PATCH: Microsecond sleep time Werner Coetzee schrieb: > Hi > > Can anyone explain why gwthread is using the poll function to sleep (using > milliseconds as timeout), and not maybe the select function (using > microseconds as timeout)? > > We have the requirement to be able to sleep for less than a millisecond, > which the current gwthread_sleep can't provide. > > Below is a patch to do just that, using the select function. > I have tested it, so if anyone has any comments, please let me hear them. > > The diff is from our own SVN repository, but as far as I know, it is > up-to-date with the cvs. Hi Werner, I'm +0 for applying the patch to CVS, since it's an additive feature and doesn't hurt any existing core bricks of the gwlib. The calls should be POSIX.1 compliant and portable hence I guess. Werner, could you do me a favor and resend the patch in a single file as mail attachment please. This ensures we don't get truncated end of line chars etc, which is a mess to correct by hand while patching ;) And thanks a lot for contributing. Stipe ------------------------------------------------------------------- Kölner Landstrasse 419 40589 Düsseldorf, NRW, Germany tolj.org system architecture Kannel Software Foundation (KSF) http://www.tolj.org/ http://www.kannel.org/ mailto:st_{at}_tolj.org mailto:stolj_{at}_kannel.org -------------------------------------------------------------------
/* gwthread.h */ /* Sleep until "seconds" seconds have elapsed, or until another thread * calls gwthread_wakeup on us. Fractional seconds are allowed. */ void gwthread_sleep_micro(double dseconds); /* gwthread-pthread.c */ void gwthread_sleep_micro(double dseconds) { fd_set fd_set_recv; struct threadinfo *threadinfo; int fd; int ret; threadinfo = getthreadinfo(); fd = threadinfo->wakefd_recv; FD_ZERO(&fd_set_recv); FD_SET(fd, &fd_set_recv); if (dseconds < 0) { ret = select(fd + 1, &fd_set_recv, NULL, NULL, NULL); } else { struct timeval timeout; timeout.tv_sec = dseconds; timeout.tv_usec = (dseconds - timeout.tv_sec) * 1000000; ret = select(fd + 1, &fd_set_recv, NULL, NULL, &timeout); } if (ret < 0) { if (errno != EINTR && errno != EAGAIN) { warning(errno, "gwthread_sleep_micro: error in select()"); } } if (FD_ISSET(fd, &fd_set_recv)) { flushpipe(fd); } }