2024-11-10 22:11:29 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <intrin.h>
|
|
|
|
|
|
2025-02-26 18:46:36 +01:00
|
|
|
typedef struct {
|
|
|
|
|
void *handle;
|
|
|
|
|
void *param;
|
|
|
|
|
void (*func)(void *param);
|
2025-03-09 17:02:12 +01:00
|
|
|
} iron_thread_impl_t;
|
2025-02-26 18:46:36 +01:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
void *DebugInfo;
|
2025-10-15 13:06:40 +02:00
|
|
|
long LockCount;
|
|
|
|
|
long RecursionCount;
|
2025-02-26 18:46:36 +01:00
|
|
|
void *OwningThread;
|
|
|
|
|
void *LockSemaphore;
|
|
|
|
|
unsigned long __w64 SpinCount;
|
2025-03-09 17:02:12 +01:00
|
|
|
} iron_microsoft_critical_section_t;
|
2025-02-26 18:46:36 +01:00
|
|
|
|
|
|
|
|
typedef struct {
|
2025-03-09 17:02:12 +01:00
|
|
|
iron_microsoft_critical_section_t criticalSection;
|
|
|
|
|
} iron_mutex_impl_t;
|
2025-02-26 18:46:36 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline bool iron_atomic_compare_exchange(volatile int32_t *pointer, int32_t old_value, int32_t new_value) {
|
2024-11-10 22:11:29 +01:00
|
|
|
return _InterlockedCompareExchange((volatile long *)pointer, new_value, old_value) == old_value;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_COMPARE_EXCHANGE(pointer, oldValue, newValue) (iron_atomic_compare_exchange(pointer, oldValue, newValue))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline bool iron_atomic_compare_exchange_pointer(void *volatile *pointer, void *old_value, void *new_value) {
|
2024-11-10 22:11:29 +01:00
|
|
|
return _InterlockedCompareExchangePointer(pointer, new_value, old_value) == old_value;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_COMPARE_EXCHANGE_POINTER(pointer, oldValue, newValue) (iron_atomic_compare_exchange_pointer(pointer, oldValue, newValue))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline int32_t iron_atomic_increment(volatile int32_t *pointer) {
|
2024-11-10 22:11:29 +01:00
|
|
|
return _InterlockedIncrement((volatile long *)pointer) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_INCREMENT(pointer) (iron_atomic_increment(pointer))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline int32_t iron_atomic_decrement(volatile int32_t *pointer) {
|
2024-11-10 22:11:29 +01:00
|
|
|
return _InterlockedDecrement((volatile long *)pointer) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_DECREMENT(pointer) (iron_atomic_decrement(pointer))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline void iron_atomic_exchange(volatile int32_t *pointer, int32_t value) {
|
2024-11-10 22:11:29 +01:00
|
|
|
_InterlockedExchange((volatile long *)pointer, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_EXCHANGE_32(pointer, value) (iron_atomic_exchange(pointer, value))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline void iron_atomic_exchange_float(volatile float *pointer, float value) {
|
2024-11-10 22:11:29 +01:00
|
|
|
_InterlockedExchange((volatile long *)pointer, *(long *)&value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_EXCHANGE_FLOAT(pointer, value) (iron_atomic_exchange_float(pointer, value))
|
2024-11-10 22:11:29 +01:00
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
static inline void iron_atomic_exchange_double(volatile double *pointer, double value) {
|
2024-11-10 22:11:29 +01:00
|
|
|
_InterlockedExchange64((volatile __int64 *)pointer, *(__int64 *)&value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 17:02:12 +01:00
|
|
|
#define IRON_ATOMIC_EXCHANGE_DOUBLE(pointer, value) (iron_atomic_exchange_double(pointer, value))
|