CFWindowsUtilities.c [plain text]
#if DEPLOYMENT_TARGET_WINDOWS
#include <CoreFoundation/CFArray.h>
#include <CoreFoundation/CFString.h>
#include "CFInternal.h"
#include "CFPriv.h"
#include <shlobj.h>
#include <sys/stat.h>
CF_EXPORT bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst)
{
return oldp == InterlockedCompareExchangePointer(dst, newp, oldp);
}
CF_EXPORT bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
{
return oldl == InterlockedCompareExchange(dst, newl, oldl);
}
CF_EXPORT bool OSAtomicCompareAndSwapPtrBarrier(void *oldp, void *newp, void *volatile *dst)
{
return oldp == InterlockedCompareExchangePointer(dst, newp, oldp);
}
CF_EXPORT int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst)
{
return InterlockedDecrement((volatile long *)dst);
}
CF_EXPORT int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst)
{
return InterlockedIncrement((volatile long *)dst);
}
CF_EXPORT int32_t OSAtomicAdd32Barrier( int32_t theAmount, volatile int32_t *theValue ) {
return (InterlockedExchangeAdd((volatile LONG *)theValue, theAmount) + theAmount);
}
CF_EXPORT bool OSAtomicCompareAndSwap32Barrier(int32_t oldValue, int32_t newValue, volatile int32_t *theValue) {
return oldValue == InterlockedCompareExchange((long *)theValue, newValue, oldValue);
}
CF_EXPORT int32_t OSAtomicAdd32( int32_t theAmount, volatile int32_t *theValue ) {
return (InterlockedExchangeAdd((volatile LONG *)theValue, theAmount) + theAmount);
}
CF_EXPORT int32_t OSAtomicIncrement32(volatile int32_t *theValue) {
return InterlockedIncrement((volatile long *)theValue);
}
CF_EXPORT int32_t OSAtomicDecrement32(volatile int32_t *theValue) {
return InterlockedDecrement((volatile long *)theValue);
}
void OSMemoryBarrier() {
MemoryBarrier();
}
void _CFGetFrameworkPath(wchar_t *path, int maxLength) {
#ifdef _DEBUG
wchar_t *DLLFileName = L"CoreFoundation_debug.dll";
#else
wchar_t *DLLFileName = L"CoreFoundation.dll";
#endif
path[0] = path[1] = 0;
DWORD wResult;
CFIndex idx;
HMODULE ourModule = GetModuleHandleW(DLLFileName);
CFAssert(ourModule, __kCFLogAssertion, "GetModuleHandle failed");
wResult = GetModuleFileNameW(ourModule, path, maxLength);
CFAssert1(wResult > 0, __kCFLogAssertion, "GetModuleFileName failed: %d", GetLastError());
CFAssert1(wResult < maxLength, __kCFLogAssertion, "GetModuleFileName result truncated: %s", path);
for (idx = wResult - 1; idx; idx--) {
if ('\\' == path[idx]) {
path[idx] = '\0';
break;
}
}
}
#endif