Create simple thread library
This commit is contained in:
1 parent
3d538eaa2c
commit
507db80fb1
7 files changed
+63
-4
No files matched your search
@@ -589,7 +589,7 @@ void draw_frame()
|
||||
return;
|
||||
}
|
||||
|
||||
update_uniform_buffer();
|
||||
update_uniform_buffers();
|
||||
|
||||
/* Only reset the fence if we are submitting work */
|
||||
vkResetFences(g_vulkan_state.device, 1, &g_in_flight_fences[g_vulkan_state.current_frame]);
|
||||
|
||||
@@ -304,7 +304,7 @@ uint8_t allocate_command_buffers()
|
||||
* @brief Update uniform buffers
|
||||
*
|
||||
*/
|
||||
void update_uniform_buffer()
|
||||
void update_uniform_buffers()
|
||||
{
|
||||
struct rse_uniform_buffer_object_t ubo = {};
|
||||
struct vec3_t eye = {0};
|
||||
|
||||
@@ -4,4 +4,5 @@ target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
rse_graphics)
|
||||
rse_graphics
|
||||
rse_utilities)
|
||||
@@ -1,12 +1,15 @@
|
||||
#include "graphics/rse_graphics.h"
|
||||
#include "utilities/rse_task.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
rse_thread_t graphics_task;
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
rse_graphics_init();
|
||||
rse_graphics_run();
|
||||
rse_create_task(&graphics_task, (thread_worker_t)rse_graphics_run, NULL);
|
||||
|
||||
rse_task_join(&graphics_task);
|
||||
return 0;
|
||||
}
|
||||
@@ -7,4 +7,8 @@ target_include_directories(rse_utilities PRIVATE
|
||||
target_sources(rse_utilities PRIVATE
|
||||
src/file_utils.c
|
||||
src/logger.c
|
||||
src/rse_task_linux.c
|
||||
)
|
||||
|
||||
target_link_libraries(rse_utilities PRIVATE
|
||||
pthread)
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file rse_task.h
|
||||
* @author Piotr Krygier (everyonecancode@gmail.com)
|
||||
* @brief Threads wrapper
|
||||
* @version 0.1
|
||||
* @date 2023-08-14
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSE_THREADS_H
|
||||
#define RSE_THREADS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <pthread.h>
|
||||
typedef pthread_t rse_thread_t;
|
||||
#endif
|
||||
|
||||
typedef void*(*thread_worker_t)(void*);
|
||||
|
||||
uint8_t rse_create_task(rse_thread_t* thread_id, thread_worker_t callback, void* args);
|
||||
uint8_t rse_task_join(rse_thread_t* thread_id);
|
||||
void rse_task_delay(void);
|
||||
|
||||
|
||||
#endif /* RSE_THREADS_H */
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "rse_task.h"
|
||||
|
||||
uint8_t rse_create_task(rse_thread_t* thread_id, thread_worker_t callback, void* args)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
result = pthread_create(thread_id, NULL, callback, args);
|
||||
|
||||
return result; //TODO: Do error handling
|
||||
}
|
||||
|
||||
uint8_t rse_task_join(rse_thread_t* thread_id)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
result = pthread_join(*thread_id, NULL);
|
||||
|
||||
return result; //TODO: Do error handling
|
||||
}
|
||||
|
||||
void rse_task_delay(void)
|
||||
{}
|
||||
Reference in new issue
Block a user