[sheepdog] [PATCH 0/8] improve reference counting of data structures

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Jul 9 04:36:34 CEST 2013


Current sheep uses raw int and uatomic_{inc,dec} for reference
counting of data structures. This is not a good practice because:
1. We can simply increment or decrement with ++ or -- operators of C
   because these counters has a type of int. It causes typical
   multithreading programming errors.
2. In sheep, only main thread is allowed to operate reference counts
   of some data structures (e.g. client_info and request). But in
   current sheep, reference counters for these structs also employ
   uatomic_{inc,dec}. This is not necessary and confusing.

This patch implements two new data structures for reference counting:
refcnt_t and main_refcnt_t. refcnt_t can be used for structs which can
be get or put by multiple threads. main_refcnt_t can be used for
structs which can be used by the main thread. These types leverage
compiler support for detecting bad operations and manipulated safely
than previous reference counters whose types are raw integer.

And in the last patch of this series, one bug is removed which is
found by this feature.

Hitoshi Mitake (8):
  util: clean assert
  util: introduce a new data type refcnt_t for reference counting
  sheep: use refcnt_t in object cache
  util: introduce a new data type main_refcnt_t for reference counting
  sheep: use main_refcnt_t for vnode_info
  sheep: use main_refcnt_t for client_info
  sheep: use main_refcnt_t for request
  sheep: initialize reference count of local request

 collie/treeview.c     |    1 +
 include/logger.h      |    6 +++++
 include/sheep.h       |    3 ++-
 include/util.h        |   71 ++++++++++++++++++++++++++++++++++++++-----------
 include/work.h        |   46 ++++++++++++++++++++++++++++++++
 sheep/group.c         |   10 +++----
 sheep/object_cache.c  |    8 +++---
 sheep/request.c       |   18 +++++++------
 sheep/sheep_priv.h    |    4 +--
 sheep/vdi.c           |    2 +-
 sheepfs/shadow_file.c |    1 +
 11 files changed, 134 insertions(+), 36 deletions(-)

-- 
1.7.10.4




More information about the sheepdog mailing list