mirror of
https://github.com/Hizenberg469/Event-Loop-in-C.git
synced 2026-04-20 01:02:23 +03:00
Project Finished
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
set(EVENT_LOOP_APP evloop_app)
|
||||
set(EVENT_LOOP_CONCURRENCY_APP evloop_concurrency_app)
|
||||
set(EV_LOOP_APP_SRC "evloop_app.c")
|
||||
set(EV_LOOP_CONCURRENCY_APP_SRC "evloop_concurreny_app.c")
|
||||
|
||||
add_executable(${EVENT_LOOP_APP}
|
||||
${EV_LOOP_APP_SRC})
|
||||
|
||||
add_executable(${EVENT_LOOP_CONCURRENCY_APP}
|
||||
${EV_LOOP_CONCURRENCY_APP_SRC})
|
||||
|
||||
target_link_libraries(${EVENT_LOOP_APP} PUBLIC
|
||||
${EVENT_LOOP_LIB})
|
||||
|
||||
target_link_libraries(${EVENT_LOOP_CONCURRENCY_APP} PUBLIC
|
||||
${EVENT_LOOP_LIB})
|
||||
|
||||
target_link_directories(${EVENT_LOOP_APP} PUBLIC
|
||||
${HEADER_DIR})
|
||||
|
||||
|
||||
target_link_directories(${EVENT_LOOP_CONCURRENCY_APP} PUBLIC
|
||||
${HEADER_DIR})
|
||||
@@ -33,18 +33,21 @@ typedef struct arg_obj_ {
|
||||
} arg_obj_t;
|
||||
|
||||
|
||||
void
|
||||
EL_RES_T
|
||||
sum_wrapper(void* arg) {
|
||||
|
||||
arg_obj_t* arg_obj = (arg_obj_t*)arg;
|
||||
printf("sum = %d\n", sum(arg_obj->arr, arg_obj->n));
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
void
|
||||
EL_RES_T
|
||||
mul_wrapper(void* arg) {
|
||||
|
||||
arg_obj_t* arg_obj = (arg_obj_t*)arg;
|
||||
printf("mul = %d\n", mul(arg_obj->arr, arg_obj->n));
|
||||
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,13 +61,13 @@ main(int argc, char** argv) {
|
||||
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);
|
||||
task_t* task_sum = task_create_new_job(&el, sum_wrapper, (void*)arg_obj1, TASK_PRIORITY_LOW);
|
||||
|
||||
|
||||
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);
|
||||
task_t* task_mul = task_create_new_job(&el, mul_wrapper, (void*)arg_obj2, TASK_PRIORITY_LOW);
|
||||
|
||||
|
||||
printf("End of main\n");
|
||||
|
||||
59
test/evloop_concurreny_app.c
Normal file
59
test/evloop_concurreny_app.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include "event_loop.h"
|
||||
|
||||
event_loop_t el;
|
||||
static int upload = 0;
|
||||
static int download = 0;
|
||||
|
||||
static EL_RES_T
|
||||
upload_fn(void* arg) {
|
||||
|
||||
while (upload < 100) {
|
||||
|
||||
upload += 2;
|
||||
//sleep(4);
|
||||
printf("upload percent-age = %d\n", upload);
|
||||
if (upload % 10 == 0 && upload != 100) {
|
||||
|
||||
return EL_CONTINUE;
|
||||
/* task_create_new_job(&el, upload_fn, NULL);
|
||||
return ;*/
|
||||
}
|
||||
}
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
static EL_RES_T
|
||||
download_fn(void* arg) {
|
||||
|
||||
while (download < 100) {
|
||||
|
||||
download += 2;
|
||||
printf("download percent-age = %d\n", download);
|
||||
if (download % 10 == 0 && download != 100) {
|
||||
|
||||
return EL_CONTINUE;
|
||||
/*task_create_new_job(&el, download_fn, NULL);
|
||||
return;*/
|
||||
}
|
||||
}
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv) {
|
||||
|
||||
event_loop_init(&el);
|
||||
event_loop_run(&el);
|
||||
sleep(1);
|
||||
|
||||
task_create_new_job(&el, upload_fn, NULL, TASK_PRIORITY_LOW);
|
||||
task_create_new_job(&el, download_fn, NULL, TASK_PRIORITY_HIGH);
|
||||
|
||||
printf("End of main\n");
|
||||
scanf("\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user