Add spinlocks
This commit is contained in:
parent
df630c1422
commit
acde39065c
4
Makefile
4
Makefile
@ -5,11 +5,13 @@ C_HEADERS = $(wildcard kernel/*.h kernel/cpu/$(PLAT)/*.h kernel/cpu/*.h kernel/t
|
||||
ASM = $(wildcard kernel/cpu/$(PLAT)/*.asm)
|
||||
S_ASM = $(wildcard kernel/cpu/$(PLAT)/*.s)
|
||||
LIBC_SOURCES = $(wildcard libc/*.c libc/*/*.c)
|
||||
LIBC_ASM_SOURCES = $(wildcard libc/*.asm libc/*/*.asm)
|
||||
LIBC_HEADERS = $(wildcard libc/*.h libc/*/*.h)
|
||||
OBJ = $(C_SOURCES:.c=.o kernel/cpu/$(PLAT)/boot.o)
|
||||
ASM_OBJ = $(S_ASM:.s=.o)
|
||||
S_ASM_OBJ = $(ASM:.asm=.o)
|
||||
LIBC_OBJ = $(LIBC_SOURCES:.c=.o)
|
||||
LIBC_ASM_OBJ = $(LIBC_ASM_SOURCES:.asm=.o)
|
||||
CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
||||
AS = $(shell cat psinfo/$(PLAT)/as.txt)
|
||||
AR = $(shell cat psinfo/$(PLAT)/ar.txt)
|
||||
@ -75,7 +77,7 @@ kernel/kernel.elf: $(OBJ) $(ASM_OBJ) $(S_ASM_OBJ) sysroot/usr/lib/libc.a
|
||||
|
||||
libc: sysroot/usr/lib/libc.a
|
||||
|
||||
sysroot/usr/lib/libc.a: $(LIBC_OBJ)
|
||||
sysroot/usr/lib/libc.a: $(LIBC_OBJ) $(LIBC_ASM_OBJ)
|
||||
@$(AR) rcs $@ $^
|
||||
|
||||
sysroot/usr/share/man: doc
|
||||
|
9
libc/__helpers.asm
Normal file
9
libc/__helpers.asm
Normal file
@ -0,0 +1,9 @@
|
||||
global __pthread_spin_lock_helper
|
||||
|
||||
__pthread_spin_lock_helper:
|
||||
mov ebx,[esp+4]
|
||||
mov eax,1
|
||||
xchg eax,[ebx]
|
||||
test eax, eax
|
||||
jnz __pthread_spin_lock_helper
|
||||
ret
|
7
libc/__helpers.h
Normal file
7
libc/__helpers.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef __HELPERS_H
|
||||
#define __HELPERS_H
|
||||
#include <pthread.h>
|
||||
|
||||
void __pthread_spin_lock_helper(pthread_spinlock_t* lock);
|
||||
|
||||
#endif
|
@ -1,6 +1,7 @@
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/syscalls.h>
|
||||
#include <__helpers.h>
|
||||
|
||||
#define QUAUX(X) #X
|
||||
#define QU(X) QUAUX(X)
|
||||
@ -21,3 +22,22 @@ void pthread_exit(void *value_ptr) {
|
||||
mov $" QU(SYSCALL_THREAD_EXIT) ", %eax; \
|
||||
int $80;");
|
||||
}
|
||||
|
||||
int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
|
||||
*lock=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_spin_lock(pthread_spinlock_t *lock) {
|
||||
__pthread_spin_lock_helper(lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_spin_unlock(pthread_spinlock_t *lock) {
|
||||
*lock=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_spin_destroy(pthread_spinlock_t *lock) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
typedef pid_t pthread_t; //!< Represents a thread
|
||||
typedef int pthread_attr_t; //!< Created as dummy
|
||||
typedef int pthread_spinlock_t; //!< Represents a spinlock
|
||||
|
||||
/**
|
||||
* Create a thread in the current process
|
||||
@ -28,4 +29,35 @@ int pthread_create(pthread_t *restrict thread,
|
||||
*/
|
||||
void pthread_exit(void *value_ptr);
|
||||
|
||||
/**
|
||||
* Initializes a spin lock
|
||||
* \param lock The spinlock to initialize
|
||||
* \param pshared Unused
|
||||
* \returns 0 on success, 1 on failure
|
||||
*/
|
||||
int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
|
||||
|
||||
/**
|
||||
* Locks a spin lock
|
||||
* \param lock The spinlock to lock
|
||||
* \returns 0 on success, 1 on failure
|
||||
*/
|
||||
int pthread_spin_lock(pthread_spinlock_t *lock);
|
||||
|
||||
/**
|
||||
* Unlocks a spin lock
|
||||
* \param lock The spinlock to unlock
|
||||
* \returns 0 on success, 1 on failure
|
||||
*/
|
||||
int pthread_spin_unlock(pthread_spinlock_t *lock);
|
||||
|
||||
/**
|
||||
* Destroys a spin lock
|
||||
* \param lock The spinlock to destroy
|
||||
* \returns 0 on success, 1 on failure
|
||||
*/
|
||||
int pthread_spin_destroy(pthread_spinlock_t *lock);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user