Update files

This commit is contained in:
Alex
2022-10-08 04:33:53 +03:00
parent 6d5f7e9372
commit 8652d781ce
53 changed files with 7413 additions and 10 deletions

53
include/lock.hpp Normal file
View File

@ -0,0 +1,53 @@
#ifndef __FENNIX_KERNEL_LOCK_H__
#define __FENNIX_KERNEL_LOCK_H__
#include <types.h>
#include <cpu.hpp>
#ifdef __cplusplus
class LockClass
{
private:
bool IsLocked = false;
public:
int Lock()
{
while (!__sync_bool_compare_and_swap(&IsLocked, false, true))
CPU::Pause();
__sync_synchronize();
return 0;
}
int Unlock()
{
__sync_synchronize();
__atomic_store_n(&IsLocked, false, __ATOMIC_SEQ_CST);
IsLocked = false;
return 0;
}
};
#define NEWLOCK(Name) LockClass Name
class SmartLock
{
private:
LockClass *LockPointer = nullptr;
public:
SmartLock(LockClass &Lock)
{
this->LockPointer = &Lock;
this->LockPointer->Lock();
}
~SmartLock() { this->LockPointer->Unlock(); }
};
#define SL_CONCAT(x, y) x##y
#define SMARTLOCK(LockClassName) SmartLock SL_CONCAT(lock##_, __COUNTER__)(LockClassName)
#endif
#endif // !__FENNIX_KERNEL_LOCK_H__