【发布时间】:2013-07-01 16:32:48
【问题描述】:
我偶然发现了似乎无效的代码,但显然是因为它位于Mono codebase for already 2 years 中。下面是小摘录。如何将宏“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);
}
【问题讨论】:
-
我只是没见过这样的东西。它不是一个函数,而是一段代码,其中变量超出了它的范围。它如何返回一个值?
-
这阻止了我在 Visual Studio 2012 下编译单声道。我将如何在 Visual Studio 中编写它?