ext4_bcache: manipulate buffer refctr by two helpers
authorngkaho1234 <ngkaho1234@gmail.com>
Sun, 6 Dec 2015 03:33:09 +0000 (11:33 +0800)
committerngkaho1234 <ngkaho1234@gmail.com>
Sun, 6 Dec 2015 03:34:53 +0000 (11:34 +0800)
  - ext4_bcache_inc_ref
  - ext4_bcache_dec_ref

lwext4/ext4_bcache.c
lwext4/ext4_bcache.h

index 0a2e2a510c4d793a849d7cc60a64f0352fcc8e12..ab19c177c619a66dc45c48e4da572a8d5eb866ac 100644 (file)
@@ -180,7 +180,7 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
 
                }
 
-               buf->refctr++;
+               ext4_bcache_inc_ref(buf);
 
                b->buf = buf;
                b->data = buf->data;
@@ -198,7 +198,7 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
        /* One more buffer in bcache now. :-) */
        bc->ref_blocks++;
 
-       buf->refctr = 1;
+       ext4_bcache_inc_ref(buf);
        /* Assign new value to LRU id and increment LRU counter
         * by 1*/
        buf->lru_id = ++bc->lru_ctr;
@@ -226,7 +226,7 @@ int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b)
        ext4_assert(buf->refctr);
 
        /*Just decrease reference counter*/
-       buf->refctr--;
+       ext4_bcache_dec_ref(buf);
 
        /* We are the last one touching this buffer, do the cleanups. */
        if (!buf->refctr) {
index bb6e6ca4baba234de6000a20847b6d3a78d45802..40431d2d9f0e486cb44babbf1765ef174fb45fec 100644 (file)
@@ -166,6 +166,12 @@ static inline void ext4_bcache_clear_dirty(struct ext4_buf *buf) {
        ext4_bcache_clear_flag(buf, BC_DIRTY);
 }
 
+/**@brief   Increment reference counter of buf by 1.*/
+#define ext4_bcache_inc_ref(buf) ((buf)->refctr++)
+
+/**@brief   Decrement reference counter of buf by 1.*/
+#define ext4_bcache_dec_ref(buf) ((buf)->refctr--)
+
 /**@brief   Static initializer of block cache structure.*/
 #define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize)                 \
        static struct ext4_bcache __name = {                                   \