Skeleton Event Loop Ready

This commit is contained in:
2024-06-03 16:03:05 +05:30
parent c4c3b013c0
commit 6114206eb7
6 changed files with 289 additions and 4 deletions

11
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,11 @@
set(EVENT_LOOP_APP evloop_app)
set(EV_LOOP_APP_SRC "evloop_app.c")
add_executable(${EVENT_LOOP_APP}
${EV_LOOP_APP_SRC})
target_link_libraries(${EVENT_LOOP_APP} PUBLIC
${EVENT_LOOP_LIB})
target_link_directories(${EVENT_LOOP_APP} PUBLIC
${HEADER_DIR})

72
test/evloop_app.c Normal file
View File

@@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <event_loop.h>
event_loop_t el;
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int
sum(int arr[], int n) {
int i, sum = 0;
for (i = 0; i < n; i++) {
sum += arr[i];
}
return sum;
}
int
mul(int arr[], int n) {
int i, mul = 1;
for (i = 0; i < n; i++) {
mul *= arr[i];
}
return mul;
}
typedef struct arg_obj_ {
int* arr;
int n;
} arg_obj_t;
void
sum_wrapper(void* arg) {
arg_obj_t* arg_obj = (arg_obj_t*)arg;
printf("sum = %d\n", sum(arg_obj->arr, arg_obj->n));
}
void
mul_wrapper(void* arg) {
arg_obj_t* arg_obj = (arg_obj_t*)arg;
printf("mul = %d\n", mul(arg_obj->arr, arg_obj->n));
}
int
main(int argc, char** argv) {
event_loop_init(&el);
event_loop_run(&el);
sleep(1);
arg_obj_t* arg_obj1 = (arg_obj_t*)calloc(1, sizeof(arg_obj_t));
arg_obj1->arr = arr;
arg_obj1->n = sizeof(arr) / sizeof(arr[0]);
task_t* task_sum = task_create_new_job(&el, sum_wrapper, (void*)arg_obj1);
arg_obj_t* arg_obj2 = (arg_obj_t*)calloc(1, sizeof(arg_obj_t));
arg_obj2->arr = arr;
arg_obj2->n = sizeof(arr) / sizeof(arr[0]);
task_t* task_mul = task_create_new_job(&el, mul_wrapper, (void*)arg_obj2);
printf("End of main\n");
scanf("\n");
}