T********i 发帖数: 2416 | 1 #if defined(_MSC_VER)
# pragma once
#include
inline long long InterlockedIncrement(long long volatile *ptr) {
return InterlockedIncrement64(ptr);
}
inline long long InterlockedDecrement(long long volatile *ptr) {
return InterlockedDecrement64(ptr);
}
#else
#include
template
inline T InterlockedIncrement(T volatile *ptr) {
return __sync_add_and_fetch(ptr, 1);
}
template
inline T InterlockedDecrement(T volatile *ptr) {
return __sync_add_and_fetch(ptr, (T)(long long)-1);
}
template
inline T InterlockedAdd(T volatile *ptr, T value) {
return __sync_add_and_fetch(ptr, value);
}
template
inline T InterlockedCompareExchange(T volatile* Destination, T Exchange, T
Comparand) {
return __sync_val_compare_and_swap(Destination, Comparand, Exchange);
}
#endif | T********i 发帖数: 2416 | 2 这段代码,Windows和Linux通吃。
goodbug,看懂了一定要写读后感欧。 |
|