Basic Header file ready

This commit is contained in:
2024-06-03 12:10:29 +05:30
commit c4c3b013c0
7 changed files with 197 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
*.sln
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
x64
.vs
build
.vscode

37
CMakeLists.txt Normal file
View File

@@ -0,0 +1,37 @@
# CMakeList.txt : CMake project for Event Loop ( Async Programming ), include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project(Event-Loop VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
#Output file structure
#Scheme 1
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/$<CONFIG>")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/$<CONFIG>")
#Scheme 2
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/bin")
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/lib")
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/lib")
#Library Name...
set(EVENT_LOOP_LIB evloop)
#Header file directory...
set(HEADER_DIR ${CMAKE_SOURCE_DIR}/include)
#Source file directory...
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
#Adding Sub-directory having CMakeLists.txt...
add_subdirectory(src)
#add_subdirectory(test)

101
CMakePresets.json Normal file
View File

@@ -0,0 +1,101 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
]
}

1
README.md Normal file
View File

@@ -0,0 +1 @@
# Event-Loop-in-C

43
include/event_loop.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef __EV_LOOP__
#define __EV_LOOP__
typedef struct task_ task_t;
typedef struct event_loop_ event_loop_t;
typedef EL_RES_T(*event_cbk)(void*);
struct task_ {
event_cbk cbk;
void* arg;
struct task_* left, * right;
};
typedef enum {
EV_LOOP_IDLE,
EV_LOOP_BUSY
} EV_LOOP_STATE;
struct event_loop_ {
/* head to the start of the task array */
struct task_* task_array_head[TASK_PRIORITY_MAX];
/* Mutex to enforce Mutual exclusion enqueue/Deque
* Operation in task array. Also used to update event loop
* attributes in mutual exclusive way
*/
pthread_mutex_t ev_loop_mutex;
/* State of event loop */
EV_LOOP_STATE ev_loop_state;
/* CV to suspened event loop thread */
pthread_cond_t ev_loop_cv;
/* Event loop thread */
pthread_t* thread;
/* Current task which event loop thread is executing.
* NULL if event loop is resting in peace*/
struct task_* current_task;
};
#endif

7
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,7 @@
set(EVENT_LOOP_SRC "event_loop.c")
add_library(${EVENT_LOOP_LIB} STATIC
${EVENT_LOOP_SRC})
target_include_directories(${EVENT_LOOP_LIB} PUBLIC
${HEADER_DIR})

0
src/event_loop.c Normal file
View File