patron hace 8 meses
padre
commit
4c37ba230c
Se han modificado 2 ficheros con 33 adiciones y 3 borrados
  1. 29 0
      timerfd/Makefile
  2. 4 3
      timerfd/main.c

+ 29 - 0
timerfd/Makefile

@@ -0,0 +1,29 @@
+ifneq ($(SCHED),)
+	CFLAGS+=-DEDF
+endif
+
+CFLAGS+=-Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-security -Wimplicit-fallthrough=3
+CFLAGS+=-Wtraditional-conversion -Wconversion -fno-strict-aliasing
+CFLAGS+=-Wno-unused-parameter -Wcast-qual -Wformat-signedness -Wshadow -Wtrampolines
+CFLAGS+=-Wshift-overflow=2 -Wstringop-overflow=4 -Wstrict-overflow=4 -Warray-bounds=2
+CFLAGS+=-Wlogical-op -Wduplicated-cond -Wduplicated-branches -Wcast-align=strict -Wswitch-default -Wswitch-enum
+CFLAGS+=-D_FORTIFY_SOURCE=2 -O2 -Wall
+
+SOURCES=main.c
+OBJ=${SOURCES:.c=.o}
+
+PROG=tfd
+
+.PHONY:	all
+all: $(PROG)
+
+$(PROG): $(OBJ)
+	$(CC) $^ -o $@ 
+.c:
+	$(CC) $(CFLAGS) $< -o $@
+
+.PHONY:	clean
+clean:
+	rm -f $(PROG) *.o
+
+

+ 4 - 3
timerfd/main.c

@@ -81,7 +81,7 @@ static int deadline(size_t period_ms)
 		err(-1, "timerfd");
 
 	itval.it_interval.tv_sec = 0;
-	itval.it_interval.tv_nsec = period_ms * 1000 * 1000;
+	itval.it_interval.tv_nsec = (int)period_ms * 1000 * 1000;
 	itval.it_value.tv_sec = 0;
 	itval.it_value.tv_nsec = itval.it_interval.tv_nsec;
 	rc = timerfd_settime(tfd, 0, &itval, NULL);
@@ -89,7 +89,7 @@ static int deadline(size_t period_ms)
 		err(-1, "timerfd_settime");
 	do {
 		static unsigned long long overrun;
-		rc = read(tfd, &overrun, sizeof overrun);
+		rc = (int)read(tfd, &overrun, sizeof overrun);
 		if (rc == -1) {
 			err(-1, "Timer read");
 		}
@@ -128,6 +128,7 @@ static int deadline(size_t period_ms)
 #endif
 
 	printf("last counter => %zu.\n", loops);
+	return 0;
 }
 
 #define SEC_NSEC	1000000000U
@@ -176,7 +177,7 @@ int main(int argc, char *argv[])
 
 	printf("[%d] Starting deadline thread.\n", getpid());
 	clock_gettime(CLOCK_MONOTONIC, &t0);
-	rc = deadline(5);
+	rc = deadline(5LLU);
 	clock_gettime(CLOCK_MONOTONIC, &t1);
 
 	size_t to = timespec_sub_to_ns(t1, t0) / 1000000;