this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: DriverServices and DriverSynchronization APIs

+314 -1
+2
src/CoreServices/CMakeLists.txt
··· 26 26 FixMath.cpp 27 27 ToolUtils.cpp 28 28 Math64.cpp 29 + DriverSynchronization.cpp 30 + DriverServices.cpp 29 31 ) 30 32 31 33 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling")
+81
src/CoreServices/DriverServices.cpp
··· 1 + #include "DriverServices.h" 2 + #include "time.h" 3 + #include <sys/sysinfo.h> 4 + 5 + AbsoluteTime UpTime() 6 + { 7 + struct sysinfo si; 8 + sysinfo(&si); 9 + return si.uptime * 1000000000ll; 10 + } 11 + 12 + Nanoseconds AbsoluteToNanoseconds(AbsoluteTime absTime) 13 + { 14 + return absTime; 15 + } 16 + 17 + Duration AbsoluteToDuration(AbsoluteTime absTime) 18 + { 19 + return Duration(absTime / 1000000ll); 20 + } 21 + 22 + AbsoluteTime NanosecondsToAbsolute(Nanoseconds ns) 23 + { 24 + return ns; 25 + } 26 + 27 + AbsoluteTime DurationToAbsolute(Duration duration) 28 + { 29 + return duration * 1000000ll; 30 + } 31 + 32 + AbsoluteTime AddAbsoluteToAbsolute(AbsoluteTime time1, AbsoluteTime time2) 33 + { 34 + return time1+time2; 35 + } 36 + 37 + AbsoluteTime SubAbsoluteFromAbsolute(AbsoluteTime time1, AbsoluteTime time2) 38 + { 39 + return time1-time2; 40 + } 41 + 42 + AbsoluteTime AddNanosecondsToAbsolute(Nanoseconds ns, AbsoluteTime absTime) 43 + { 44 + return absTime + NanosecondsToAbsolute(ns); 45 + } 46 + 47 + AbsoluteTime AddDurationToAbsolute(Duration duration, AbsoluteTime absTime) 48 + { 49 + return absTime + DurationToAbsolute(duration); 50 + } 51 + 52 + AbsoluteTime SubNanosecondsFromAbsolute(Nanoseconds ns, AbsoluteTime absTime) 53 + { 54 + return absTime - NanosecondsToAbsolute(ns); 55 + } 56 + 57 + AbsoluteTime SubDurationFromAbsolute(Duration duration, AbsoluteTime absTime) 58 + { 59 + return absTime - DurationToAbsolute(duration); 60 + } 61 + 62 + Nanoseconds AbsoluteDeltaToNanoseconds(AbsoluteTime time1, AbsoluteTime time2) 63 + { 64 + return AbsoluteToNanoseconds(time1 - time2); 65 + } 66 + 67 + Duration AbsoluteDeltaToDuration(AbsoluteTime time1, AbsoluteTime time2) 68 + { 69 + return AbsoluteToDuration(time1 - time2); 70 + } 71 + 72 + Nanoseconds DurationToNanoseconds(Duration duration) 73 + { 74 + return duration * 1000000ll; 75 + } 76 + 77 + Duration NanosecondsToDuration(Nanoseconds ns) 78 + { 79 + return Duration(ns / 1000000ll); 80 + } 81 +
+59
src/CoreServices/DriverServices.h
··· 1 + #ifndef DRIVERSERVICES_H 2 + #define DRIVERSERVICES_H 3 + #include "MacTypes.h" 4 + #include <climits> 5 + 6 + #ifdef __cplusplus 7 + extern "C" { 8 + #endif 9 + 10 + typedef UnsignedWide Nanoseconds; 11 + 12 + enum 13 + { 14 + durationMicrosecond = -1L, 15 + durationMillisecond = 1, 16 + durationSecond = 1000, 17 + durationMinute = 60*1000, 18 + durationHour = 60*60*1000, 19 + durationDay = 60*60*1000*24, 20 + durationNoWait = 0, 21 + durationForever = INT_MAX 22 + }; 23 + 24 + AbsoluteTime UpTime(); 25 + 26 + Nanoseconds AbsoluteToNanoseconds(AbsoluteTime absTime); 27 + 28 + Duration AbsoluteToDuration(AbsoluteTime absTime); 29 + 30 + AbsoluteTime NanosecondsToAbsolute(Nanoseconds ns); 31 + 32 + AbsoluteTime DurationToAbsolute(Duration duration); 33 + 34 + AbsoluteTime AddAbsoluteToAbsolute(AbsoluteTime time1, AbsoluteTime time2); 35 + 36 + AbsoluteTime SubAbsoluteFromAbsolute(AbsoluteTime time1, AbsoluteTime time2); 37 + 38 + AbsoluteTime AddNanosecondsToAbsolute(Nanoseconds ns, AbsoluteTime absTime); 39 + 40 + AbsoluteTime AddDurationToAbsolute(Duration duration, AbsoluteTime absTime); 41 + 42 + AbsoluteTime SubNanosecondsFromAbsolute(Nanoseconds ns, AbsoluteTime absTime); 43 + 44 + AbsoluteTime SubDurationFromAbsolute(Duration duration, AbsoluteTime absTime); 45 + 46 + Nanoseconds AbsoluteDeltaToNanoseconds(AbsoluteTime time1, AbsoluteTime time2); 47 + 48 + Duration AbsoluteDeltaToDuration(AbsoluteTime time1, AbsoluteTime time2); 49 + 50 + Nanoseconds DurationToNanoseconds(Duration duration); 51 + 52 + Duration NanosecondsToDuration(Nanoseconds ns); 53 + 54 + #ifdef __cplusplus 55 + } 56 + #endif 57 + 58 + #endif 59 +
+110
src/CoreServices/DriverSynchronization.cpp
··· 1 + #include "DriverSynchronization.h" 2 + 3 + 4 + Boolean CompareAndSwap(UInt32 old, UInt32 _new, UInt32* ptr) 5 + { 6 + return __sync_bool_compare_and_swap(ptr, old, _new); 7 + } 8 + 9 + Boolean TestAndClear(UInt32 bit, UInt8* ptr) 10 + { 11 + unsigned long mask = (1 << bit); 12 + return !!(__sync_fetch_and_and((unsigned long*) ptr, ~mask) & mask); 13 + } 14 + 15 + Boolean TestAndSet(UInt32 bit, UInt8* ptr) 16 + { 17 + unsigned long mask = (1 << bit); 18 + return !!(__sync_fetch_and_or((unsigned long*) ptr, mask) & mask); 19 + } 20 + 21 + SInt8 IncrementAtomic8(SInt8* ptr) 22 + { 23 + return __sync_add_and_fetch(ptr, 1); 24 + } 25 + 26 + SInt8 DecrementAtomic8(SInt8* ptr) 27 + { 28 + return __sync_sub_and_fetch(ptr, 1); 29 + } 30 + 31 + SInt8 AddAtomic8(SInt32 val, SInt8* ptr) 32 + { 33 + return __sync_add_and_fetch(ptr, val); 34 + } 35 + 36 + UInt8 BitAndAtomic8(UInt32 val, UInt8* ptr) 37 + { 38 + return __sync_and_and_fetch(ptr, val); 39 + } 40 + 41 + UInt8 BitOrAtomic8(UInt32 val, UInt8* ptr) 42 + { 43 + return __sync_or_and_fetch(ptr, val); 44 + } 45 + 46 + UInt8 BitXorAtomic8(UInt32 val, UInt8* ptr) 47 + { 48 + return __sync_xor_and_fetch(ptr, val); 49 + } 50 + 51 + SInt16 IncrementAtomic16(SInt16* ptr) 52 + { 53 + return __sync_add_and_fetch(ptr, 1); 54 + } 55 + 56 + SInt16 DecrementAtomic16(SInt16* ptr) 57 + { 58 + return __sync_sub_and_fetch(ptr, 1); 59 + } 60 + 61 + SInt16 AddAtomic16(SInt32 val, SInt16* ptr) 62 + { 63 + return __sync_add_and_fetch(ptr, val); 64 + } 65 + 66 + UInt16 BitAndAtomic16(UInt32 val, UInt16* ptr) 67 + { 68 + return __sync_and_and_fetch(ptr, val); 69 + } 70 + 71 + UInt16 BitOrAtomic16(UInt32 val, UInt16* ptr) 72 + { 73 + return __sync_or_and_fetch(ptr, val); 74 + } 75 + 76 + UInt16 BitXorAtomic16(UInt32 val, UInt16* ptr) 77 + { 78 + return __sync_xor_and_fetch(ptr, val); 79 + } 80 + 81 + SInt32 IncrementAtomic(SInt32* ptr) 82 + { 83 + return __sync_add_and_fetch(ptr, 1); 84 + } 85 + 86 + SInt32 DecrementAtomic(SInt32* ptr) 87 + { 88 + return __sync_sub_and_fetch(ptr, 1); 89 + } 90 + 91 + SInt32 AddAtomic(SInt32 val, SInt32* ptr) 92 + { 93 + return __sync_add_and_fetch(ptr, val); 94 + } 95 + 96 + UInt32 BitAndAtomic(UInt32 val, UInt32* ptr) 97 + { 98 + return __sync_and_and_fetch(ptr, val); 99 + } 100 + 101 + UInt32 BitOrAtomic(UInt32 val, UInt32* ptr) 102 + { 103 + return __sync_or_and_fetch(ptr, val); 104 + } 105 + 106 + UInt32 BitXorAtomic(UInt32 val, UInt32* ptr) 107 + { 108 + return __sync_xor_and_fetch(ptr, val); 109 + } 110 +
+57
src/CoreServices/DriverSynchronization.h
··· 1 + #ifndef DRIVERSYNCHRONIZATION_H 2 + #define DRIVERSYNCHRONIZATION_H 3 + 4 + #include "MacTypes.h" 5 + 6 + #ifdef __cplusplus 7 + extern "C" { 8 + #endif 9 + 10 + Boolean CompareAndSwap(UInt32 old, UInt32 _new, UInt32* ptr); 11 + 12 + Boolean TestAndClear(UInt32 bit, UInt8* ptr); 13 + 14 + Boolean TestAndSet(UInt32 bit, UInt8* ptr) ; 15 + 16 + SInt8 IncrementAtomic8(SInt8* ptr); 17 + 18 + SInt8 DecrementAtomic8(SInt8* ptr); 19 + 20 + SInt8 AddAtomic8(SInt32 val, SInt8* ptr); 21 + 22 + UInt8 BitAndAtomic8(UInt32 val, UInt8* ptr); 23 + 24 + UInt8 BitOrAtomic8(UInt32 val, UInt8* ptr); 25 + 26 + UInt8 BitXorAtomic8(UInt32 val, UInt8* ptr); 27 + 28 + SInt16 IncrementAtomic16(SInt16* ptr); 29 + 30 + SInt16 DecrementAtomic16(SInt16* ptr); 31 + 32 + SInt16 AddAtomic16(SInt32 val, SInt16* ptr); 33 + 34 + UInt16 BitAndAtomic16(UInt32 val, UInt16* ptr); 35 + 36 + UInt16 BitOrAtomic16(UInt32 val, UInt16* ptr); 37 + 38 + UInt16 BitXorAtomic16(UInt32 val, UInt16* ptr); 39 + 40 + SInt32 IncrementAtomic(SInt32* ptr); 41 + 42 + SInt32 DecrementAtomic(SInt32* ptr); 43 + 44 + SInt32 AddAtomic(SInt32 val, SInt32* ptr); 45 + 46 + UInt32 BitAndAtomic(UInt32 val, UInt32* ptr); 47 + 48 + UInt32 BitOrAtomic(UInt32 val, UInt32* ptr); 49 + 50 + UInt32 BitXorAtomic(UInt32 val, UInt32* ptr); 51 + 52 + #ifdef __cplusplus 53 + } 54 + #endif 55 + 56 + #endif 57 +
+5 -1
src/CoreServices/MacTypes.h
··· 2 2 #define MACTYPES_H 3 3 #include <stdint.h> 4 4 5 + typedef int8_t SInt8; 6 + typedef uint8_t UInt8; 5 7 typedef int16_t SInt16; 6 8 typedef uint16_t UInt16; 7 9 typedef int32_t SInt32; ··· 19 21 typedef ShortFixed * ShortFixedPtr; // 8/8 20 22 typedef int64_t wide; 21 23 typedef uint64_t UnsignedWide; 22 - 24 + typedef uint64_t AbsoluteTime; 25 + typedef int32_t Duration; // milliseconds 26 + typedef uint8_t Boolean; 23 27 24 28 #endif 25 29