我偶然发现了似乎无效的代码,但显然是因为它在Mono 代码库中已经存在 2 年了。下面是小摘录。如何将宏“mono_atomic_load_acquire”的结果分配给unload_data_unref (..) 中的变量“count” 我假设 __tmp 是分配的内容,但我找不到在 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);
}