Files
zinnia/servers/unix/main.c
T
2026-08-11 17:48:20 +02:00

73 lines
1.7 KiB
C

#include <zinnia/channel.h>
#include <zinnia/handle.h>
#include <zinnia/mem.h>
#include <zinnia/status.h>
#include <zinnia/system.h>
#include <zinnia/thread.h>
#include <common/compiler.h>
#include <common/utils.h>
#include <errno.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/auxv.h>
#include <threads.h>
thread_local char buf[1024];
[[__format(printf, 1, 2)]]
static void zn_printf(const char* msg, ...) {
va_list args;
va_start(args, msg);
int32_t len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
zn_log(buf, len);
}
zn_handle_t channel;
struct message {
size_t id;
};
#define MSG_HI \
IPC_START \
IPC_STRING \
IPC_END
int other_fn(void* arg) {
zn_printf("unix: Hello from the other thread named \"%s\"!\n", (const char*)arg);
channel = getauxval(0x1000);
struct message msg = {.id = 1};
char name[] = "posixd";
zn_status_t status = zn_channel_write(channel, nullptr, &msg, 0, sizeof(msg) + sizeof(name));
if (status != ZN_OK) {
zn_printf("unix: %s\n", zn_status_to_string(status));
}
return 69;
}
int main(int argc, char* argv[], char* envp[]) {
zn_printf("unix: starting...\n");
const char* thread_name = "unix_second_thread";
thrd_t thread;
int res = thrd_create(&thread, other_fn, (void*)thread_name);
if (res != thrd_success)
zn_printf("unix: errno: %s\n", strerror(errno));
zn_printf("unix: second thread created\n");
int res2;
zn_printf("unix: waiting on second thread...\n");
thrd_join(thread, &res2);
zn_printf("unix: second thread exited with: %i\n", res2);
return 0;
}