
// ::Platform::Windows::Memory::Start::

rawptr pMemAlloc(usize size)
{
	return (rawptr)VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
}

rawptr pMemAllocZeroed(usize size)
{
	rawptr mem = pMemAlloc(size);
	MemZero(mem, size);
	return mem;
}

void pMemFree(rawptr ptr, usize size)
{
	Assert(VirtualFree(ptr, size, MEM_RELEASE), "pMemFree failure");
}

// ::Platform::Windows::Memory::End::



// ::Platform::Windows::Print::Start::

i32 pWriteStdOut(rawptr buf, i32 len)
{
	return WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buf, len, NULL, NULL);
}

i32 pWriteStdErr(rawptr buf, i32 len)
{
	return WriteConsole(GetStdHandle(STD_ERROR_HANDLE), buf, len, NULL, NULL);
}

// ::Platform::Windows::Print::End::



// ::Platform::Functions::Directory::Start::

b32 pDirNavigate(c8 *dir)
{
	return !(b32)SetCurrentDirectory(dir);
}

// ::Platform::Functions::Directory::End::



// ::Platform::Windows::Profiling::Functions::Start::

static inline u64 pCPUTimerRead()
{
	return __rdtsc();
}

// ::Platform::Windows::Profiling::Functions::End::



// ::Platform::Windows::Async::Start::

static pThread pThreadInit(rawptr proc, rawptr param)
{
	pThread thread = {0};
	CreateThread(NULL, 0, proc, param, 0, NULL);

	return thread;
}

static void pThreadSuspend(pThread *thread)
{
	SuspendThread(thread->handle);
}

static void pThreadWake(pThread *thread)
{
	ResumeThread(thread->handle);
}

static void pThreadKill()
{
	ExitThread(0);
}

// ::Platform::Windows::Async::End::



// ::Platform::Windows::Atomics::Start::


static inline void pAtomicSignalFenceSeqCst()
{
	_ReadWriteBarrier();
}

static inline u32 pAtomicFetchSubU32(u32 volatile *ptr, u32 count)
{
	LONG decrement = (LONG)count;
	return (u32)InterlockedAddAcquire((LONG volatile *)ptr, -decrement) + decrement; 
}

static inline u32 pAtomicFetchIncrU32(u32 volatile *ptr)
{
	return (u32)InterlockedIncrementAcquire((LONG volatile *)ptr) - 1;
}

static inline void pAtomicIncrU32(u32 volatile *ptr)
{
	InterlockedIncrementRelease((LONG volatile *)ptr);
}

static inline u32 pAtomicLoadU32(u32 volatile *ptr)
{
	return (u32)InterlockedOrAcquire((LONG volatile *)ptr, 0);
}

static inline void pAtomicStoreB32(b32 volatile *ptr, b32 value)
{
	_InterlockedExchange_HLERelease((LONG volatile *)ptr, (LONG)value);
}

static inline b32 pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expect, b32 desired)
{
	return (b32)InterlockedCompareExchangeAcquire((LONG volatile *)ptr, (LONG)desired, (LONG)*expect);
}

// ::Platform::Windows::Atomics::End::



// ::Platform::Windows::Files::Start::

static b8 pDirIsVisible(c8 *dir_name)
{
	WIN32_FIND_DATA find_data;
	HANDLE handle;
	return (handle = FindFirstFile(dir_name, &find_data)) != INVALID_HANDLE_VALUE;
}

// ::Platform::Windows::Files::End::
