瀏覽代碼

htable: wrapped maco code in do {} while(0)

Daniel-Constantin Mierla 7 月之前
父節點
當前提交
65a296b347
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      src/modules/htable/ht_api.h

+ 15 - 6
src/modules/htable/ht_api.h

@@ -144,10 +144,19 @@ ht_cell_t *ht_iterator_get_current(str *iname);
 void ht_slot_lock(ht_t *ht, int idx);
 void ht_slot_unlock(ht_t *ht, int idx);
 
-#define HT_UPDATE_EXPIRE(ht, it, now)                               \
-	if(ht->updateexpire || (now && it->expire && it->expire < now)) \
-	it->expire = now + ht->htexpire
-#define HT_COPY_EXPIRE(ht, it, now, src) \
-	HT_UPDATE_EXPIRE(ht, it, now);       \
-	else it->expire = src->expire
+#define HT_UPDATE_EXPIRE(ht, it, now)                                     \
+	do {                                                                  \
+		if(ht->updateexpire || (now && it->expire && it->expire < now)) { \
+			it->expire = now + ht->htexpire;                              \
+		}                                                                 \
+	} while(0)
+#define HT_COPY_EXPIRE(ht, it, now, src)                                  \
+	do {                                                                  \
+		if(ht->updateexpire || (now && it->expire && it->expire < now)) { \
+			it->expire = now + ht->htexpire;                              \
+		} else {                                                          \
+			it->expire = src->expire;                                     \
+		}                                                                 \
+	} while(0)
+
 #endif