spinlock #14

Merged
xamidev merged 4 commits from spinlock into main 2026-03-15 09:55:46 +01:00
2 changed files with 34 additions and 2 deletions
Showing only changes of commit 22fea378b4 - Show all commits

View File

@@ -34,7 +34,7 @@ struct spinlock_t term_lock = {0};
extern int panic_count;
/*
* _putchar - Writes a character to terminal
* _putchar - Writes a character to terminal (DEPRECATED)
* @character: character to write
*/
void _putchar(char character)
@@ -43,6 +43,14 @@ void _putchar(char character)
flanterm_write(ft_ctx, &character, 1);
}
/*
* internal_putc - Internal putchar function
* @c: char to print
* @_: (unused, for nanoprintf)
*
* Prints a character to the terminal if it's ready,
* and also to the serial interface if it's ready.
*/
void internal_putc(int c, void *_)
{
(void)_;
@@ -58,7 +66,6 @@ void internal_putc(int c, void *_)
}
}
if (init.serial) {
if (ch == '\n') {
skputc('\r');
@@ -67,6 +74,16 @@ void internal_putc(int c, void *_)
}
}
/*
* printf - Fromatted printing
* @fmt: format string
* @...: variadic arguments
*
* Wrapper for nanoprintf
*
* Return:
* <ret> - number of characters sent to the callback
*/
int printf(const char* fmt, ...)
{
va_list args;

View File

@@ -9,6 +9,13 @@
#include "kernel.h"
#include "spinlock.h"
/*
* spinlock_acquire - Lock a lock
* @lock: pointer to desired spinlock
*
* Saves the RFLAGS register, then acquires a lock.
* Pause instruction is used to ease the CPU.
*/
void spinlock_acquire(struct spinlock_t* lock)
{
uint64_t rflags;
@@ -21,6 +28,14 @@ void spinlock_acquire(struct spinlock_t* lock)
lock->rflags = rflags;
}
/*
* spinlock_release - Unlock a lock
* @lock: pointer to desired spinlock
*
* Gets saved RFLAGS register from the lock and
* unlocks it (clears locked state).
* RFLAGS is then restored.
*/
void spinlock_release(struct spinlock_t* lock)
{
uint64_t rflags = lock->rflags;