- 论坛徽章:
- 0
|
从新写一段清楚的代码
ipsec_rcv.c543行(freeswan中的文件)
- if(tdbprev == NULL) {
- spin_lock(&tdb_lock);
- }
-
- #ifdef CONFIG_IPSEC_IPCOMP
- if (proto == IPPROTO_COMP) {
- unsigned int flags = 0;
- if (tdbp == NULL) {
- spin_unlock(&tdb_lock);
- KLIPS_PRINT(debug_rcv,
- "klips_debug:ipsec_rcv: "
- "Incoming packet with outer IPCOMP header SA:%s:
- not yet supported by KLIPS, dropped\n",
- sa_len ? sa : " (error)");
复制代码
spin_lock(&tdb_lock)和spin_unlock(&tdb_lock)的定义:
#define spin_lock(lock) (void)(lock) /* Not "unused variable". */
#define spin_unlock(lock) do { } while(0)
其它相关定义:
spinlock_t tdb_lock;
#if (__GNUC__ >; 2)
typedef struct { } spinlock_t;
#elif (DEBUG_SPINLOCKS < 2)
typedef struct {
volatile unsigned long lock;
} spinlock_t;
这段代码的lock和unlock比较清楚,斑竹给解释一下lock具体工作原理
目前do{}while(0)还是很不理解,不可能unlock什么也不做阿 |
|