Files
mop3/libaux/mprintf.c
kamkow1 342f39b748
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 40s
Build documentation / build-and-deploy (push) Successful in 26s
Use static buffers for mprintf and debug_printf, cut down on library dependencies
2026-04-03 20:49:07 +02:00

39 lines
911 B
C

#include <mprintf.h>
#include <printf.h>
#include <process_self.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 ();
}