ciarancummins -> RE: nanosleep (Feb. 28, '06, 12:54:44 PM) |
Hi,
I am trying to implement this nanosleep function for my code but I am getting errors, probably because I am implementing it incorrectly...
struct timespec is defined in an included header file already, and I have defined nanosleep in this file.
#include <sys/time.h>
#include "vars.h"
#include "eventgen.h"
#include "flowop.h"
#include "ipc.h"
void
eventgen_usage()
{
fprintf(stderr, "eventgen rate=<rate>\n");
fprintf(stderr, "\n");
}
/* Producer side of rate eventgen */
void
eventgen_thread(void)
{
struct timespec sleeptime ;
hrtime_t last;
hrtime_t delta;
int count;
#define nanosleep(x,y) usleep( ((x)->tv_sec)*1000000 + ((y)->tv_nsec)/10
00 )
last = gethrtime();
while(1) {
if (filebench_shm->eventgen_hz == 0) {
sleep(1);
continue;
}
/* Sleep for 10xperiod */
sleeptime.tv_sec = 0;
sleeptime.tv_nsec = 10000000000UL / filebench_shm->eventgen_hz;
if (sleeptime.tv_nsec < 1000UL)
sleeptime.tv_nsec = 1000UL;
sleeptime.tv_sec = sleeptime.tv_nsec / 1000000000UL;
if (sleeptime.tv_sec > 0)
sleeptime.tv_nsec -= (sleeptime.tv_sec * 1000000000UL);
nanosleep(&sleeptime, NULL);
.
.
Error on compile:
source='eventgen.c' object='eventgen.o' libtool=no \
depfile='.deps/eventgen.Po' tmpdepfile='.deps/eventgen.TPo' \
depmode=gcc3 /bin/sh ../config/depcomp \
gcc -D_REENTRANT -I. -I. -I.. -I../intl -I/usr/local/include/gsl -DFILEBENCHDIR
=\"/usr/local/filebench\" -g -O2 -D_POSIX_C_SOURCE=19309 -D_ALL_SOURCE -DYYDE
BUG=1 -c `test -f eventgen.c || echo './'`eventgen.c
eventgen.c: In function `eventgen_thread':
eventgen.c:40: warning: integer constant is too large for "unsigned long" type
eventgen.c:46: warning: dereferencing `void *' pointer
eventgen.c:46: error: request for member `tv_nsec' in something not a structure
or union
make: *** [eventgen.o] Error 1
% make
What am I doing wrong?
Thanks for any help,
Ciaran |
|
|
|