我偶然發現了一些看似不合理的代碼,但顯然是因爲它坐在Mono codebase for already 2 years中。下面是小節選。如何將宏「mono_atomic_load_acquire」的結果分配給unload_data_unref(..)中的變量「count」我假設__tmp是正在分配的內容,但是我找不到任何有關在C中使用此方法範圍的信息。是否有人可以解釋或給一些有用的鏈接?從範圍塊中分配了返回值的C變量?
#define mono_atomic_load_acquire(target) ({ \
typeof (*target) __tmp = *target; \
LOAD_ACQUIRE_FENCE; \
__tmp; })
#define LOAD_ACQUIRE_FENCE MEMORY_BARRIER
#define MEMORY_BARRIER mono_memory_barrier()
static inline void mono_memory_barrier (void)
{
// platform specific code
}
unload_data_unref (unload_data *data)
{
gint32 count;
do {
count = mono_atomic_load_acquire (&data->refcount);
g_assert (count >= 1 && count <= 2);
if (count == 1) {
g_free (data);
return;
}
} while (InterlockedCompareExchange (&data->refcount, count, count - 1) != count);
}
我只是還沒有看到類似的東西。這不是一個函數,而是一個代碼塊,其中的變量超出了範圍。它如何返回一個值? – voldemarz
這阻止了我在Visual Studio 2012下編譯單聲道。如何在Visual Studio中編寫它? –