]>
git.saurik.com Git - apple/cf.git/blob - CFWindowsUtilities.c
2996b718cd26419a376992b9a218ca5f7c4de2f7
2 * Copyright (c) 2014 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 Copyright (c) 2008-2013, Apple Inc. All rights reserved.
27 Responsibility: Tony Parker
30 #if DEPLOYMENT_TARGET_WINDOWS
32 #include <CoreFoundation/CFArray.h>
33 #include <CoreFoundation/CFString.h>
34 #include "CFInternal.h"
41 CF_EXPORT
bool OSAtomicCompareAndSwapPtr(void *oldp
, void *newp
, void *volatile *dst
)
43 return oldp
== InterlockedCompareExchangePointer(dst
, newp
, oldp
);
46 CF_EXPORT
bool OSAtomicCompareAndSwapLong(long oldl
, long newl
, long volatile *dst
)
48 return oldl
== InterlockedCompareExchange(dst
, newl
, oldl
);
51 CF_EXPORT
bool OSAtomicCompareAndSwapPtrBarrier(void *oldp
, void *newp
, void *volatile *dst
)
53 return oldp
== InterlockedCompareExchangePointer(dst
, newp
, oldp
);
56 CF_EXPORT
int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst
)
58 return InterlockedDecrement((volatile long *)dst
);
61 CF_EXPORT
int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst
)
63 return InterlockedIncrement((volatile long *)dst
);
66 CF_EXPORT
int32_t OSAtomicAdd32Barrier( int32_t theAmount
, volatile int32_t *theValue
) {
67 return (InterlockedExchangeAdd((volatile LONG
*)theValue
, theAmount
) + theAmount
);
70 CF_EXPORT
bool OSAtomicCompareAndSwap32Barrier(int32_t oldValue
, int32_t newValue
, volatile int32_t *theValue
) {
71 return oldValue
== InterlockedCompareExchange((long *)theValue
, newValue
, oldValue
);
74 CF_EXPORT
int32_t OSAtomicAdd32( int32_t theAmount
, volatile int32_t *theValue
) {
75 return (InterlockedExchangeAdd((volatile LONG
*)theValue
, theAmount
) + theAmount
);
78 CF_EXPORT
int32_t OSAtomicIncrement32(volatile int32_t *theValue
) {
79 return InterlockedIncrement((volatile long *)theValue
);
82 CF_EXPORT
int32_t OSAtomicDecrement32(volatile int32_t *theValue
) {
83 return InterlockedDecrement((volatile long *)theValue
);
86 // These 64-bit versions of InterlockedCompareExchange are only available on client Vista and later, so we can't use them (yet).
88 CF_EXPORT bool OSAtomicCompareAndSwap64( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue ) {
89 return __oldValue == InterlockedCompareExchange64((volatile LONGLONG *)__theValue, __newValue, __oldValue);
92 CF_EXPORT bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue ) {
93 return __oldValue == InterlockedCompareExchange64((volatile LONGLONG *)__theValue, __newValue, __oldValue);
96 CF_EXPORT int64_t OSAtomicAdd64( int64_t __theAmount, volatile int64_t *__theValue ) {
97 return (InterlockedExchangeAdd64((volatile LONGLONG *)__theValue, __theAmount) + __theAmount);
100 CF_EXPORT int64_t OSAtomicAdd64Barrier( int64_t __theAmount, volatile int64_t *__theValue ) {
101 retun (InterlockedExchangeAdd64((volatile LONGLONG *)__theValue, __theAmount) + __theAmount);
105 void OSMemoryBarrier() {
109 void _CFGetFrameworkPath(wchar_t *path
, int maxLength
) {
111 // might be nice to get this from the project file at some point
112 wchar_t *DLLFileName
= L
"CoreFoundation_debug.dll";
114 wchar_t *DLLFileName
= L
"CoreFoundation.dll";
116 path
[0] = path
[1] = 0;
119 HMODULE ourModule
= GetModuleHandleW(DLLFileName
);
121 CFAssert(ourModule
, __kCFLogAssertion
, "GetModuleHandle failed");
123 wResult
= GetModuleFileNameW(ourModule
, path
, maxLength
);
124 CFAssert1(wResult
> 0, __kCFLogAssertion
, "GetModuleFileName failed: %d", GetLastError());
125 CFAssert1(wResult
< maxLength
, __kCFLogAssertion
, "GetModuleFileName result truncated: %s", path
);
127 // strip off last component, the DLL name
128 for (idx
= wResult
- 1; idx
; idx
--) {
129 if ('\\' == path
[idx
]) {