+ -
当前位置:首页 → 问答吧 → 为什么高手都喜欢把锁存到结构中,有什么优点吗?

为什么高手都喜欢把锁存到结构中,有什么优点吗?

时间:2010-08-12

来源:互联网

本帖最后由 zhangsuozhu 于 2010-08-12 15:52 编辑
  1. struct nf_conn {
  2.         /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
  3.            plus 1 for any connection(s) we are `master' for */
  4.         struct nf_conntrack ct_general;

  5.         spinlock_t lock;

  6.         /* XXX should I move this to the tail ? - Y.K */
  7.         /* These are my tuples; original and reply */
  8.         struct nf_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];

  9.         /* Have we seen traffic both ways yet? (bitset) */
  10.         unsigned long status;

  11.         /* If we were expected by an expectation, this will be it */
  12.         struct nf_conn *master;

  13.         /* Timer function; drops refcnt when it goes off. */
  14.         struct timer_list timeout;

  15. #if defined(CONFIG_NF_CONNTRACK_MARK)
  16.         u_int32_t mark;
  17. #endif

  18. #ifdef CONFIG_NF_CONNTRACK_SECMARK
  19.         u_int32_t secmark;
  20. #endif

  21.         /* Storage reserved for other modules: */
  22.         union nf_conntrack_proto proto;

  23.         /* Extensions */
  24.         struct nf_ct_ext *ext;
  25. #ifdef CONFIG_NET_NS
  26.         struct net *ct_net;
  27. #endif
  28. };
复制代码
见spinlock_t lock;

作者: zhangsuozhu   发布时间: 2010-08-12

表示这个锁,是对这个结构的一致性起作用的,很好阿。

作者: peidright   发布时间: 2010-08-12

突然觉的这个问题问的很菜。哈哈

作者: zhangsuozhu   发布时间: 2010-08-12

与结构相关的都应该放在一起,而不是分开

作者: wenkai169   发布时间: 2010-08-12

与结构相关的锁不放在结构中,放在哪里呢?

作者: mirnshi   发布时间: 2010-08-12

结构化,一致性

作者: @sky   发布时间: 2010-08-12