shithub: lwext4

Download patch

ref: 9195095bf35d65118fe69fd26906840bd5fcfc9f
parent: c1a9671e59bf4170d374242dbd86631ea48a14f1
author: ngkaho1234 <[email protected]>
date: Sun Dec 6 06:33:09 EST 2015

ext4_bcache: manipulate buffer refctr by two helpers

  - ext4_bcache_inc_ref
  - ext4_bcache_dec_ref

--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -180,7 +180,7 @@
 
 		}
 
-		buf->refctr++;
+		ext4_bcache_inc_ref(buf);
 
 		b->buf = buf;
 		b->data = buf->data;
@@ -198,7 +198,7 @@
 	/* 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 @@
 	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) {
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -166,6 +166,12 @@
 	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 = {                                   \