From 976a96d1824ea1a84bb3a12023033cf2fed81761 Mon Sep 17 00:00:00 2001 From: batt Date: Sat, 3 Jul 2010 13:28:13 +0000 Subject: [PATCH] Set cache_dirty flag to be a bitmask; add accessors and update code. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3993 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/io/kblock.c | 16 ++++++++++++---- bertos/io/kblock.h | 11 +++++++++-- bertos/io/kblock_file.c | 1 - 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bertos/io/kblock.c b/bertos/io/kblock.c index fb70ef94..487cfcd1 100644 --- a/bertos/io/kblock.c +++ b/bertos/io/kblock.c @@ -84,6 +84,14 @@ INLINE int kblock_store(struct KBlock *b, block_idx_t index) return b->priv.vt->store(b, b->priv.blk_start + index); } +INLINE void kblock_setDirty(struct KBlock *b, bool dirty) +{ + if (dirty) + b->priv.flags |= KB_CACHE_DIRTY; + else + b->priv.flags &= ~KB_CACHE_DIRTY; +} + size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size) @@ -104,11 +112,11 @@ int kblock_flush(struct KBlock *b) { ASSERT(b); - if (b->priv.cache_dirty) + if (kblock_cacheDirty(b)) { LOG_INFO("flushing block %d\n", b->priv.curr_blk); if (kblock_store(b, b->priv.curr_blk) == 0) - b->priv.cache_dirty = false; + kblock_setDirty(b, false); else return EOF; } @@ -144,7 +152,7 @@ size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t o if (!kblock_loadPage(b, idx)) return 0; - b->priv.cache_dirty = true; + kblock_setDirty(b, true); return kblock_writeBuf(b, buf, offset, size); } @@ -158,7 +166,7 @@ int kblock_copy(struct KBlock *b, block_idx_t idx1, block_idx_t idx2) return EOF; b->priv.curr_blk = idx2; - b->priv.cache_dirty = true; + kblock_setDirty(b, true); return 0; } diff --git a/bertos/io/kblock.h b/bertos/io/kblock.h index abc0fcb2..14a5b88e 100644 --- a/bertos/io/kblock.h +++ b/bertos/io/kblock.h @@ -92,7 +92,8 @@ typedef struct KBlockVTable } KBlockVTable; -#define KB_BUFFERED BV(0) +#define KB_BUFFERED BV(0) +#define KB_CACHE_DIRTY BV(1) /** * KBlock private members. @@ -106,7 +107,6 @@ typedef struct KBlockPriv void *buf; block_idx_t blk_start; ///< Start block number when the device is trimmed. \sa kblock_trim() block_idx_t curr_blk; - bool cache_dirty; const struct KBlockVTable *vt; ///< Virtual table of interface functions. } KBlockPriv; @@ -240,6 +240,12 @@ INLINE int kblock_readBlock(struct KBlock *b, block_idx_t index, void *buf) return b->priv.vt->readBlock(b, b->priv.blk_start + index, buf); } +INLINE bool kblock_cacheDirty(struct KBlock *b) +{ + ASSERT(b); + return (b->priv.flags & KB_CACHE_DIRTY); +} + INLINE block_idx_t kblock_cachedBlock(struct KBlock *b) { return b->priv.curr_blk; @@ -251,6 +257,7 @@ INLINE bool kblock_buffered(struct KBlock *b) return (b->priv.flags & KB_BUFFERED); } + size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, size_t size); int kblock_flush(struct KBlock *b); diff --git a/bertos/io/kblock_file.c b/bertos/io/kblock_file.c index c445612e..69e9e12c 100644 --- a/bertos/io/kblock_file.c +++ b/bertos/io/kblock_file.c @@ -188,7 +188,6 @@ void kblockfile_init(KBlockFile *f, FILE *fp, bool hwbuf, void *buf, size_t bloc f->b.priv.vt = &kblockfile_swbuffered_vt; kblockfile_load(&f->b, 0); f->b.priv.curr_blk = 0; - f->b.priv.cache_dirty = false; } else f->b.priv.vt = &kblockfile_unbuffered_vt; -- 2.25.1