mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
feat(fs): add eventfd syscall support (#858)
* feat(fs): add eventfd syscall support
This commit is contained in:
1
user/apps/test_eventfd/.gitignore
vendored
Normal file
1
user/apps/test_eventfd/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
test_eventfd
|
20
user/apps/test_eventfd/Makefile
Normal file
20
user/apps/test_eventfd/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
ifeq ($(ARCH), x86_64)
|
||||
CROSS_COMPILE=x86_64-linux-musl-
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
CROSS_COMPILE=riscv64-linux-musl-
|
||||
endif
|
||||
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
|
||||
.PHONY: all
|
||||
all: main.c
|
||||
$(CC) -static -o test_eventfd main.c
|
||||
|
||||
.PHONY: install clean
|
||||
install: all
|
||||
mv test_eventfd $(DADK_CURRENT_BUILD_DIR)/test_eventfd
|
||||
|
||||
clean:
|
||||
rm test_eventfd *.o
|
||||
|
||||
fmt:
|
52
user/apps/test_eventfd/main.c
Normal file
52
user/apps/test_eventfd/main.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int efd;
|
||||
uint64_t u;
|
||||
ssize_t s;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <num>...\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
efd = eventfd(0, 0);
|
||||
if (efd == -1)
|
||||
err(EXIT_FAILURE, "eventfd");
|
||||
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
for (size_t j = 1; j < argc; j++) {
|
||||
printf("Child writing %s to efd\n", argv[j]);
|
||||
u = strtoull(argv[j], NULL, 0);
|
||||
/* strtoull() allows various bases */
|
||||
s = write(efd, &u, sizeof(uint64_t));
|
||||
if (s != sizeof(uint64_t))
|
||||
err(EXIT_FAILURE, "write");
|
||||
}
|
||||
printf("Child completed write loop\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
default:
|
||||
sleep(2);
|
||||
|
||||
printf("Parent about to read\n");
|
||||
s = read(efd, &u, sizeof(uint64_t));
|
||||
if (s != sizeof(uint64_t))
|
||||
err(EXIT_FAILURE, "read");
|
||||
printf("Parent read %"PRIu64" (%#"PRIx64") from efd\n", u, u);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case -1:
|
||||
err(EXIT_FAILURE, "fork");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user