Fast reader-writer lock in C

I ported my fast reader-writer lock from C# to C for Process Hacker 2. Here it is. #include <windows.h> #include <intrin.h> // Put this in a header file. typedef struct _PH_FAST_LOCK { ULONG Value; HANDLE ExclusiveWakeEvent; HANDLE SharedWakeEvent; } PH_FAST_LOCK, *PPH_FAST_LOCK; #define PH_LOCK_OWNED 0x1 #define PH_LOCK_EXCLUSIVE_WAKING 0x2 #define PH_LOCK_SHARED_OWNERS_SHIFT 2 #define PH_LOCK_SHARED_OWNERS_MASK 0x3ff #define PH_LOCK_SHARED_OWNERS_INC […]

Continue reading →