From 1a6347cd578620fb3a1614141ae925f12b4efece Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Thu, 31 Jan 2013 16:05:34 +0100 Subject: [PATCH] Turned SwapDir.flags, Format::Token.flags CossMemBuf.flags, CossState.flags, Fs::Ufs::RebuildState.flags to bool --- src/SwapDir.cc | 8 ++++---- src/SwapDir.h | 6 +++--- src/format/Token.cc | 6 +++--- src/format/Token.h | 12 ++++++------ src/fs/coss/store_coss.h | 11 ++++++----- src/fs/coss/store_dir_coss.cc | 2 +- src/fs/coss/store_io_coss.cc | 18 ++++++++---------- src/fs/ufs/RebuildState.cc | 10 +++++----- src/fs/ufs/RebuildState.h | 9 +++++---- src/store_dir.cc | 4 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/SwapDir.cc b/src/SwapDir.cc index 94e7de2d23..384125dc51 100644 --- a/src/SwapDir.cc +++ b/src/SwapDir.cc @@ -238,7 +238,7 @@ SwapDir::getOptionTree() const void SwapDir::parseOptions(int isaReconfig) { - unsigned int old_read_only = flags.read_only; + const bool old_read_only = flags.read_only; char *name, *value; ConfigOption *newOption = getOptionTree(); @@ -290,12 +290,12 @@ SwapDir::optionReadOnlyParse(char const *option, const char *value, int isaRecon if (strcmp(option, "no-store") != 0 && strcmp(option, "read-only") != 0) return false; - int read_only = 0; + bool read_only = 0; if (value) - read_only = xatoi(value); + read_only = (xatoi(value) != 0); else - read_only = 1; + read_only = true; flags.read_only = read_only; diff --git a/src/SwapDir.h b/src/SwapDir.h index 488cafca91..16e24ab870 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -192,9 +192,9 @@ public: int scanned; struct Flags { - Flags() : selected(0), read_only(0) {} - unsigned int selected:1; - unsigned int read_only:1; + Flags() : selected(false), read_only(false) {} + bool selected; + bool read_only; } flags; virtual void init() = 0; /* Initialise the fs */ virtual void create(); /* Create a new fs */ diff --git a/src/format/Token.cc b/src/format/Token.cc index 7c24bb0ce0..b9c0a63b31 100644 --- a/src/format/Token.cc +++ b/src/format/Token.cc @@ -322,12 +322,12 @@ Format::Token::parse(const char *def, Quoting *quoting) } if (*cur == '-') { - left = 1; + left = true; ++cur; } if (*cur == '0') { - zero = 1; + zero = false; ++cur; } @@ -403,7 +403,7 @@ Format::Token::parse(const char *def, Quoting *quoting) } if (*cur == ' ') { - space = 1; + space = true; ++cur; } diff --git a/src/format/Token.h b/src/format/Token.h index 07eb4e32a6..7579191f5a 100644 --- a/src/format/Token.h +++ b/src/format/Token.h @@ -32,9 +32,9 @@ public: widthMin(-1), widthMax(-1), quote(LOG_QUOTE_NONE), - left(0), - space(0), - zero(0), + left(false), + space(false), + zero(false), divisor(0), next(NULL) { data.string = NULL; } @@ -65,9 +65,9 @@ public: int widthMin; ///< minimum field width int widthMax; ///< maximum field width enum Quoting quote; - unsigned int left:1; - unsigned int space:1; - unsigned int zero:1; + bool left; + bool space; + bool zero; int divisor; Token *next; /* todo: move from linked list to array */ diff --git a/src/fs/coss/store_coss.h b/src/fs/coss/store_coss.h index 3d0b1aa657..acdb6dbf0b 100644 --- a/src/fs/coss/store_coss.h +++ b/src/fs/coss/store_coss.h @@ -36,8 +36,9 @@ public: char buffer[COSS_MEMBUF_SZ]; struct _cossmembuf_flags { - unsigned int full:1; - unsigned int writing:1; + _cossmembuf_flags() : full(false), writing(false) {} + bool full; + bool writing; } flags; }; @@ -68,9 +69,9 @@ public: size_t requestoffset; /* in blocks */ int64_t reqdiskoffset; /* in blocks */ - struct { - unsigned int reading:1; - unsigned int writing:1; + struct CossFlags { + bool reading; + bool writing; } flags; CossMemBuf *locked_membuf; diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 6dfd98e0af..72a592ced3 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -176,7 +176,7 @@ CossSwapDir::readCompleted(const char *buf, int len, int errflag, RefCountswap_filen << ", len " << len); - cstate->flags.reading = 0; + cstate->flags.reading = false; if (errflag) { ++ StoreFScoss::GetInstance().stats.read.fail; diff --git a/src/fs/coss/store_io_coss.cc b/src/fs/coss/store_io_coss.cc index 8aac78ee12..9135665803 100644 --- a/src/fs/coss/store_io_coss.cc +++ b/src/fs/coss/store_io_coss.cc @@ -87,7 +87,7 @@ CossSwapDir::allocate(const StoreEntry * e, int which) * back to the beginning */ ++ StoreFScoss::GetInstance().stats.disk_overflows; - current_membuf->flags.full = 1; + current_membuf->flags.full = true; current_membuf->diskend = current_offset; current_membuf->maybeWrite(this); current_offset = 0; /* wrap back to beginning */ @@ -102,7 +102,7 @@ CossSwapDir::allocate(const StoreEntry * e, int which) * Skip the blank space at the end of the stripe. start over. */ ++ StoreFScoss::GetInstance().stats.stripe_overflows; - current_membuf->flags.full = 1; + current_membuf->flags.full = true; current_offset = current_membuf->diskend; current_membuf->maybeWrite(this); debugs(79, 2, "CossSwapDir::allocate: New offset - " << current_offset); @@ -183,8 +183,8 @@ CossSwapDir::createStoreIO(StoreEntry &e, StoreIOState::STFNCB * file_callback, sio->callback_data = cbdataReference(callback_data); sio->e = &e; - cstate->flags.writing = 0; - cstate->flags.reading = 0; + cstate->flags.writing = false; + cstate->flags.reading = false; cstate->readbuffer = NULL; cstate->reqdiskoffset = -1; @@ -220,8 +220,8 @@ CossSwapDir::openStoreIO(StoreEntry & e, StoreIOState::STFNCB * file_callback, cstate->st_size = e.swap_file_sz; sio->e = &e; - cstate->flags.writing = 0; - cstate->flags.reading = 0; + cstate->flags.writing = false; + cstate->flags.reading = false; cstate->readbuffer = NULL; cstate->reqdiskoffset = -1; p = storeCossMemPointerFromDiskOffset(storeCossFilenoToDiskOffset(f), NULL); @@ -308,7 +308,7 @@ CossState::read_(char *buf, size_t size, off_t offset, STRCB * callback, void *c read.callback_data = cbdataReference(callback_data); debugs(79, 3, "storeCossRead: offset " << offset); offset_ = offset; - flags.reading = 1; + flags.reading = true; if ((offset + (off_t)size) > st_size) size = st_size - offset; @@ -542,7 +542,7 @@ CossMemBuf::write(CossSwapDir * SD) { ++ StoreFScoss::GetInstance().stats.stripe_write.ops; debugs(79, 3, "CossMemBuf::write: offset " << diskstart << ", len " << (diskend - diskstart)); - flags.writing = 1; + flags.writing = true; /* XXX Remember that diskstart/diskend are block offsets! */ SD->theFile->write(new CossWrite(WriteRequest((char const *)&buffer, diskstart, diskend - diskstart, NULL), this)); } @@ -562,8 +562,6 @@ CossSwapDir::createMemBuf(off_t start, sfileno curfn, int *collision) debugs(79, 3, "CossSwapDir::createMemBuf: creating new membuf at " << newmb->diskstart); debugs(79, 3, "CossSwapDir::createMemBuf: at " << newmb); newmb->diskend = newmb->diskstart + COSS_MEMBUF_SZ; - newmb->flags.full = 0; - newmb->flags.writing = 0; newmb->lockcount = 0; newmb->SD = this; /* XXX This should be reversed, with the new buffer last in the chain */ diff --git a/src/fs/ufs/RebuildState.cc b/src/fs/ufs/RebuildState.cc index eeb3d086e4..b3c2d0d090 100644 --- a/src/fs/ufs/RebuildState.cc +++ b/src/fs/ufs/RebuildState.cc @@ -63,7 +63,7 @@ Fs::Ufs::RebuildState::RebuildState(RefCount aSwapDir) : * use commonUfsDirRebuildFromDirectory() to open up each file * and suck in the meta data. */ - int clean = 0; + int clean = 0; //TODO: change to bool int zeroLengthLog = 0; FILE *fp = sd->openTmpSwapLog(&clean, &zeroLengthLog); @@ -78,11 +78,11 @@ Fs::Ufs::RebuildState::RebuildState(RefCount aSwapDir) : } else { fromLog = true; - flags.clean = (unsigned int) clean; + flags.clean = (clean != 0); } if (!clean) - flags.need_to_validate = 1; + flags.need_to_validate = true; debugs(47, DBG_IMPORTANT, "Rebuilding storage in " << sd->path << " (" << (clean ? "clean log" : (LogParser ? "dirty log" : "no log")) << ")"); @@ -444,12 +444,12 @@ Fs::Ufs::RebuildState::getNextFile(sfileno * filn_p, int *size) while (fd < 0 && done == 0) { fd = -1; - if (0 == flags.init) { /* initialize, open first file */ + if (!flags.init) { /* initialize, open first file */ done = 0; curlvl1 = 0; curlvl2 = 0; in_dir = 0; - flags.init = 1; + flags.init = true; assert(Config.cacheSwap.n_configured > 0); } diff --git a/src/fs/ufs/RebuildState.h b/src/fs/ufs/RebuildState.h index 552da45d31..6a89e055d4 100644 --- a/src/fs/ufs/RebuildState.h +++ b/src/fs/ufs/RebuildState.h @@ -62,10 +62,11 @@ public: int curlvl1; int curlvl2; - struct { - unsigned int need_to_validate:1; - unsigned int clean:1; - unsigned int init:1; + struct Flags { + Flags() : need_to_validate(false), clean(false), init(false) {} + bool need_to_validate; + bool clean; + bool init; } flags; int in_dir; int done; diff --git a/src/store_dir.cc b/src/store_dir.cc index be1337e097..73da882657 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -262,7 +262,7 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e) for (i = 0; i < Config.cacheSwap.n_configured; ++i) { SD = dynamic_cast(INDEXSD(i)); - SD->flags.selected = 0; + SD->flags.selected = false; if (!SD->canStore(*e, objsize, load)) continue; @@ -295,7 +295,7 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e) } if (dirn >= 0) - dynamic_cast(INDEXSD(dirn))->flags.selected = 1; + dynamic_cast(INDEXSD(dirn))->flags.selected = true; return dirn; } -- 2.47.3