Skip to content

Commit 8e0d4b2

Browse files
authored
Merge pull request swiftlang#2612 from 3405691582/Prefix_ExposeMachAbsoluteTime
[CF] Expose mach_absolute_time for BSD.
2 parents fcdda6c + d04d8f5 commit 8e0d4b2

File tree

1 file changed

+29
-44
lines changed

1 file changed

+29
-44
lines changed

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,39 @@ typedef int boolean_t;
161161
#include <sys/stat.h> // mode_t
162162
#endif
163163

164-
#if TARGET_OS_LINUX || TARGET_OS_BSD
164+
#if TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32
165165
// Implemented in CFPlatform.c
166-
bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst);
167-
bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst);
168-
bool OSAtomicCompareAndSwapPtrBarrier(void *oldp, void *newp, void *volatile *dst);
169-
bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
166+
CF_EXPORT bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst);
167+
CF_EXPORT bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst);
168+
CF_EXPORT bool OSAtomicCompareAndSwapPtrBarrier(void *oldp, void *newp, void *volatile *dst);
169+
CF_EXPORT bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
170+
171+
CF_EXPORT int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst);
172+
CF_EXPORT int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst);
173+
CF_EXPORT int32_t OSAtomicIncrement32(volatile int32_t *theValue);
174+
CF_EXPORT int32_t OSAtomicDecrement32(volatile int32_t *theValue);
170175

171-
int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst);
172-
int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst);
173-
int32_t OSAtomicIncrement32(volatile int32_t *theValue);
174-
int32_t OSAtomicDecrement32(volatile int32_t *theValue);
176+
CF_EXPORT int32_t OSAtomicAdd32( int32_t theAmount, volatile int32_t *theValue );
177+
CF_EXPORT int32_t OSAtomicAdd32Barrier( int32_t theAmount, volatile int32_t *theValue );
178+
CF_EXPORT bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, volatile int32_t *theValue );
175179

176-
int32_t OSAtomicAdd32( int32_t theAmount, volatile int32_t *theValue );
177-
int32_t OSAtomicAdd32Barrier( int32_t theAmount, volatile int32_t *theValue );
178-
bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, volatile int32_t *theValue );
180+
CF_EXPORT void OSMemoryBarrier();
179181

180-
void OSMemoryBarrier();
181-
#endif // TARGET_OS_LINUX || TARGET_OS_BSD
182+
#include <time.h>
183+
184+
CF_INLINE uint64_t mach_absolute_time() {
185+
#if TARGET_OS_WIN32
186+
LARGE_INTEGER count;
187+
QueryPerformanceCounter(&count);
188+
// mach_absolute_time is unsigned, but this function returns a signed value.
189+
return (uint64_t)count.QuadPart;
190+
#else
191+
struct timespec ts;
192+
clock_gettime(CLOCK_MONOTONIC, &ts);
193+
return (uint64_t)ts.tv_nsec + (uint64_t)ts.tv_sec * 1000000000UL;
194+
#endif
195+
}
196+
#endif // TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32
182197

183198
#if TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__)
184199
#define strtod_l(a,b,locale) strtod(a,b)
@@ -219,13 +234,6 @@ CF_INLINE size_t malloc_size(void *memblock) {
219234
return malloc_usable_size(memblock);
220235
}
221236

222-
#include <time.h>
223-
CF_INLINE uint64_t mach_absolute_time() {
224-
struct timespec ts;
225-
clock_gettime(CLOCK_MONOTONIC, &ts);
226-
return (uint64_t)ts.tv_nsec + (uint64_t)ts.tv_sec * 1000000000UL;
227-
}
228-
229237
#define malloc_default_zone() (void *)0
230238

231239
#endif
@@ -341,13 +349,6 @@ CF_INLINE size_t malloc_size(void *memblock) {
341349
return _msize(memblock);
342350
}
343351

344-
CF_INLINE uint64_t mach_absolute_time() {
345-
LARGE_INTEGER count;
346-
QueryPerformanceCounter(&count);
347-
// mach_absolute_time is unsigned, but this function returns a signed value.
348-
return (uint64_t)count.QuadPart;
349-
}
350-
351352
CF_INLINE long long llabs(long long v) {
352353
if (v < 0) return -v;
353354
return v;
@@ -362,22 +363,6 @@ CF_INLINE long long llabs(long long v) {
362363

363364
#define issetugid() 0
364365

365-
// CF exports these useful atomic operation functions on Windows
366-
CF_EXPORT bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst);
367-
CF_EXPORT bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst);
368-
CF_EXPORT bool OSAtomicCompareAndSwapPtrBarrier(void *oldp, void *newp, void *volatile *dst);
369-
370-
CF_EXPORT int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst);
371-
CF_EXPORT int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst);
372-
CF_EXPORT int32_t OSAtomicIncrement32(volatile int32_t *theValue);
373-
CF_EXPORT int32_t OSAtomicDecrement32(volatile int32_t *theValue);
374-
375-
CF_EXPORT int32_t OSAtomicAdd32( int32_t theAmount, volatile int32_t *theValue );
376-
CF_EXPORT int32_t OSAtomicAdd32Barrier( int32_t theAmount, volatile int32_t *theValue );
377-
CF_EXPORT bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, volatile int32_t *theValue );
378-
379-
void OSMemoryBarrier();
380-
381366
#include <io.h>
382367
#include <fcntl.h>
383368
#include <errno.h>

0 commit comments

Comments
 (0)