Files
mop3/libu/mprintf.c
kamkow1 6c01de8b0d
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 40s
Build documentation / build-and-deploy (push) Successful in 26s
Merge all libs into libu
2026-04-12 13:45:37 +02:00

39 lines
906 B
C

#include <mprintf.h>
#include <printf.h>
#include <process.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <streams.h>
#include <string.h>
#include <system.h>
static char mprintf_buffer[MPRINTF_BUF_MAX];
static atomic_flag mprintf_buffer_lock1 = ATOMIC_FLAG_INIT;
static void mprintf_buffer_lock (void) {
while (atomic_flag_test_and_set_explicit (&mprintf_buffer_lock1, memory_order_acquire)) {
#if defined(__x86_64__)
__asm__ volatile ("pause" ::: "memory");
#endif
}
}
static void mprintf_buffer_unlock (void) {
atomic_flag_clear_explicit (&mprintf_buffer_lock1, memory_order_release);
}
void mprintf (const char* fmt, ...) {
va_list args;
va_start (args, fmt);
mprintf_buffer_lock ();
int len = vsnprintf (mprintf_buffer, MPRINTF_BUF_MAX, fmt, args);
va_end (args);
stream_write (process_get_pgid (), STREAM_OUT, mprintf_buffer, len);
mprintf_buffer_unlock ();
}