1 /* 2 * Copyright 2021, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SMP_H_ 6 #define _SMP_H_ 7 8 9 #include <SupportDefs.h> 10 11 12 struct Mutex 13 { 14 int32 fLock; 15 16 Mutex(): fLock(0) {} 17 18 bool TryLock() 19 { 20 return atomic_test_and_set(&fLock, -1, 0) == 0; 21 } 22 23 bool Lock() 24 { 25 while (!TryLock()) {} 26 if (atomic_add(&fLock, -1) < 0) { 27 } 28 return true; 29 } 30 31 void Unlock() 32 { 33 atomic_add(&fLock, 1); 34 } 35 }; 36 37 38 struct CpuInfo 39 { 40 uint32 phandle; 41 uint32 hartId; 42 uint32 plicContext; 43 }; 44 45 46 CpuInfo* smp_find_cpu(uint32 phandle); 47 48 void smp_init_other_cpus(void); 49 void smp_boot_other_cpus(uint64 pageTable, uint64 kernel_entry); 50 51 void smp_init(); 52 53 54 #endif // _SMP_H_ 55