command stage 1

This commit is contained in:
2024-11-22 05:59:14 +01:00
parent 533ec30597
commit 10c8f6d0ca
3 changed files with 95 additions and 30 deletions
+19 -4
View File
@@ -4,8 +4,16 @@
#include <pthread.h>
#include <time.h>
typedef struct {
void* element;
void* sender;
void* receiver;
boolean_t running;
} LArgs;
extern boolean_t render(void* element);
extern void *event_loop(void* element);
extern void *cmd_loop(void* element);
void sleep_ms(long milliseconds)
{
@@ -15,16 +23,23 @@ void sleep_ms(long milliseconds)
nanosleep(&ts, NULL);
}
boolean_t c_run(void* element)
boolean_t c_run(void* element, void* sender, void* receiver)
{
pthread_t thread;
pthread_t event_thread;
pthread_t cmd_thread;
LArgs args = { .element = element, .sender = sender, .receiver = receiver, .running = 1 };
if (pthread_create(&thread, NULL, event_loop, element) != 0)
if (pthread_create(&event_thread, NULL, event_loop, &args) != 0)
{
perror("Failed to create thread");
}
while (render(element))
if (pthread_create(&cmd_thread, NULL, cmd_loop, &args) != 0)
{
perror("Failed to create thread");
}
while (render(element) && args.running)
{
sleep_ms(20);
}