Skip to content

Commit f8ec221

Browse files
committed
Fix -Wswitch warning
+ constexpr
1 parent b11fd80 commit f8ec221

File tree

3 files changed

+51
-45
lines changed

3 files changed

+51
-45
lines changed

src/jrd/cch.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ static void recentlyUsed(BufferDesc* bdb);
197197
static void requeueRecentlyUsed(BufferControl* bcb);
198198

199199

200-
const ULONG MIN_BUFFER_SEGMENT = 65536;
200+
constexpr ULONG MIN_BUFFER_SEGMENT = 65536;
201201

202202
// Given pointer a field in the block, find the block
203203

204204
#define BLOCK(fld_ptr, type, fld) (type*)((SCHAR*) fld_ptr - offsetof(type, fld))
205205

206-
const int PRE_SEARCH_LIMIT = 256;
207-
const int PRE_EXISTS = -1;
208-
const int PRE_UNKNOWN = -2;
206+
constexpr int PRE_SEARCH_LIMIT = 256;
207+
constexpr int PRE_EXISTS = -1;
208+
constexpr int PRE_UNKNOWN = -2;
209209

210210
namespace Jrd
211211
{
@@ -546,7 +546,7 @@ bool CCH_exclusive_attachment(thread_db* tdbb, USHORT level, SSHORT wait_flag, S
546546
* return false.
547547
*
548548
**************************************/
549-
const int CCH_EXCLUSIVE_RETRY_INTERVAL = 10; // retry interval in milliseconds
549+
constexpr int CCH_EXCLUSIVE_RETRY_INTERVAL = 10; // retry interval in milliseconds
550550

551551
SET_TDBB(tdbb);
552552
Database* const dbb = tdbb->getDatabase();
@@ -807,6 +807,9 @@ pag* CCH_fetch(thread_db* tdbb, WIN* window, int lock_type, SCHAR page_type, int
807807

808808
switch (lockState)
809809
{
810+
case lsLockedHavePage:
811+
// page available
812+
break;
810813
case lsLocked:
811814
CCH_TRACE(("FE PAGE %d:%06d", window->win_page.getPageSpaceID(), window->win_page.getPageNum()));
812815
CCH_fetch_page(tdbb, window, read_shadow); // must read page from disk
@@ -817,6 +820,9 @@ pag* CCH_fetch(thread_db* tdbb, WIN* window, int lock_type, SCHAR page_type, int
817820
case lsLatchTimeout:
818821
case lsLockTimeout:
819822
return NULL; // latch or lock timeout
823+
case lsError:
824+
fb_assert(false);
825+
break;
820826
}
821827

822828
adjust_scan_count(window, lockState == lsLocked);

src/jrd/cch.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class BCBHashTable;
6666

6767
// Page buffer cache size constraints.
6868

69-
const ULONG MIN_PAGE_BUFFERS = 50;
69+
inline constexpr ULONG MIN_PAGE_BUFFERS = 50;
7070
#if SIZEOF_VOID_P == 4
71-
const ULONG MAX_PAGE_BUFFERS = 131072;
71+
inline constexpr ULONG MAX_PAGE_BUFFERS = 131072;
7272
#else
73-
const ULONG MAX_PAGE_BUFFERS = MAX_SLONG - 1;
73+
inline constexpr ULONG MAX_PAGE_BUFFERS = MAX_SLONG - 1;
7474
#endif
7575

7676
// BufferControl -- Buffer control block -- one per system
@@ -174,16 +174,16 @@ class BufferControl : public pool_alloc<type_bcb>
174174
Firebird::Array<BDBBlock> bcb_bdbBlocks; // all allocated BufferDesc's
175175
};
176176

177-
const int BCB_keep_pages = 1; // set during btc_flush(), pages not removed from dirty binary tree
178-
const int BCB_cache_writer = 2; // cache writer thread has been started
179-
const int BCB_writer_start = 4; // cache writer thread is starting now
180-
const int BCB_writer_active = 8; // no need to post writer event count
177+
inline constexpr int BCB_keep_pages = 1; // set during btc_flush(), pages not removed from dirty binary tree
178+
inline constexpr int BCB_cache_writer = 2; // cache writer thread has been started
179+
inline constexpr int BCB_writer_start = 4; // cache writer thread is starting now
180+
inline constexpr int BCB_writer_active = 8; // no need to post writer event count
181181
#ifdef SUPERSERVER_V2
182-
const int BCB_cache_reader = 16; // cache reader thread has been started
183-
const int BCB_reader_active = 32; // cache reader not blocked on event
182+
inline constexpr int BCB_cache_reader = 16; // cache reader thread has been started
183+
inline constexpr int BCB_reader_active = 32; // cache reader not blocked on event
184184
#endif
185-
const int BCB_free_pending = 64; // request cache writer to free pages
186-
const int BCB_exclusive = 128; // there is only BCB in whole system
185+
inline constexpr int BCB_free_pending = 64; // request cache writer to free pages
186+
inline constexpr int BCB_exclusive = 128; // there is only BCB in whole system
187187

188188

189189
// BufferDesc -- Buffer descriptor block
@@ -273,28 +273,28 @@ class BufferDesc : public pool_alloc<type_bdb>
273273

274274
// to set/clear BDB_dirty use set_dirty_flag()/clear_dirty_flag()
275275
// These constants should really be of type USHORT.
276-
const int BDB_dirty = 0x0001; // page has been updated but not written yet
277-
const int BDB_garbage_collect = 0x0002; // left by scan for garbage collector
278-
const int BDB_writer = 0x0004; // someone is updating the page
279-
const int BDB_marked = 0x0008; // page has been updated
280-
const int BDB_must_write = 0x0010; // forces a write as soon as the page is released
281-
const int BDB_faked = 0x0020; // page was just allocated
282-
//const int BDB_merge = 0x0040;
283-
const int BDB_system_dirty = 0x0080; // system transaction has marked dirty
284-
const int BDB_io_error = 0x0100; // page i/o error
285-
const int BDB_read_pending = 0x0200; // read is pending
286-
const int BDB_free_pending = 0x0400; // buffer being freed for reuse
287-
const int BDB_not_valid = 0x0800; // i/o error invalidated buffer
288-
const int BDB_db_dirty = 0x1000; // page must be written to database
289-
//const int BDB_checkpoint = 0x2000; // page must be written by next checkpoint
290-
const int BDB_prefetch = 0x4000; // page has been prefetched but not yet referenced
291-
const int BDB_no_blocking_ast = 0x8000; // No blocking AST registered with page lock
292-
const int BDB_lru_chained = 0x10000; // buffer is in pending LRU chain
293-
const int BDB_nbak_state_lock = 0x20000; // nbak state lock should be released after buffer is written
276+
inline constexpr int BDB_dirty = 0x0001; // page has been updated but not written yet
277+
inline constexpr int BDB_garbage_collect = 0x0002; // left by scan for garbage collector
278+
inline constexpr int BDB_writer = 0x0004; // someone is updating the page
279+
inline constexpr int BDB_marked = 0x0008; // page has been updated
280+
inline constexpr int BDB_must_write = 0x0010; // forces a write as soon as the page is released
281+
inline constexpr int BDB_faked = 0x0020; // page was just allocated
282+
//inline constexpr int BDB_merge = 0x0040;
283+
inline constexpr int BDB_system_dirty = 0x0080; // system transaction has marked dirty
284+
inline constexpr int BDB_io_error = 0x0100; // page i/o error
285+
inline constexpr int BDB_read_pending = 0x0200; // read is pending
286+
inline constexpr int BDB_free_pending = 0x0400; // buffer being freed for reuse
287+
inline constexpr int BDB_not_valid = 0x0800; // i/o error invalidated buffer
288+
inline constexpr int BDB_db_dirty = 0x1000; // page must be written to database
289+
//inline constexpr int BDB_checkpoint = 0x2000; // page must be written by next checkpoint
290+
inline constexpr int BDB_prefetch = 0x4000; // page has been prefetched but not yet referenced
291+
inline constexpr int BDB_no_blocking_ast = 0x8000; // No blocking AST registered with page lock
292+
inline constexpr int BDB_lru_chained = 0x10000; // buffer is in pending LRU chain
293+
inline constexpr int BDB_nbak_state_lock = 0x20000; // nbak state lock should be released after buffer is written
294294

295295
// bdb_ast_flags
296296

297-
const int BDB_blocking = 0x01; // a blocking ast was sent while page locked
297+
inline constexpr int BDB_blocking = 0x01; // a blocking ast was sent while page locked
298298

299299

300300
// PRE -- Precedence block
@@ -309,7 +309,7 @@ class Precedence : public pool_alloc<type_pre>
309309
SSHORT pre_flags;
310310
};
311311

312-
const int PRE_cleared = 1;
312+
inline constexpr int PRE_cleared = 1;
313313

314314
/* Compatibility matrix for latch types.
315315
@@ -353,9 +353,9 @@ enum LATCH
353353

354354
// Constants used by prefetch mechanism
355355

356-
const int PREFETCH_MAX_TRANSFER = 16384; // maximum block I/O transfer (bytes)
356+
inline constexpr int PREFETCH_MAX_TRANSFER = 16384; // maximum block I/O transfer (bytes)
357357
// maximum pages allowed per prefetch request
358-
const int PREFETCH_MAX_PAGES = (2 * PREFETCH_MAX_TRANSFER / MIN_PAGE_SIZE);
358+
inline constexpr int PREFETCH_MAX_PAGES = (2 * PREFETCH_MAX_TRANSFER / MIN_PAGE_SIZE);
359359

360360
// Prefetch block
361361

@@ -374,7 +374,7 @@ class Prefetch : public pool_alloc<type_prf>
374374
SCHAR prf_unaligned_buffer[PREFETCH_MAX_TRANSFER + MIN_PAGE_SIZE];
375375
};
376376

377-
const int PRF_active = 1; // prefetch block currently in use
377+
inline constexpr int PRF_active = 1; // prefetch block currently in use
378378
#endif // SUPERSERVER_V2
379379

380380
typedef Firebird::SortedArray<SLONG, Firebird::InlineStorage<SLONG, 256>, SLONG> PagesArray;

src/jrd/cch_proto.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ inline void CCH_PREFETCH(Jrd::thread_db* tdbb, SLONG* pages, SSHORT count)
158158

159159
// Flush flags
160160

161-
const USHORT FLUSH_ALL = 1; // flush all dirty buffers in cache
162-
const USHORT FLUSH_RLSE = 2; // release page locks after flush
163-
const USHORT FLUSH_TRAN = 4; // flush transaction dirty buffers from dirty btree
164-
const USHORT FLUSH_SWEEP = 8; // flush dirty buffers from garbage collection
165-
const USHORT FLUSH_SYSTEM = 16; // flush system transaction only from dirty btree
166-
const USHORT FLUSH_FINI = (FLUSH_ALL | FLUSH_RLSE);
161+
inline constexpr USHORT FLUSH_ALL = 1; // flush all dirty buffers in cache
162+
inline constexpr USHORT FLUSH_RLSE = 2; // release page locks after flush
163+
inline constexpr USHORT FLUSH_TRAN = 4; // flush transaction dirty buffers from dirty btree
164+
inline constexpr USHORT FLUSH_SWEEP = 8; // flush dirty buffers from garbage collection
165+
inline constexpr USHORT FLUSH_SYSTEM = 16; // flush system transaction only from dirty btree
166+
inline constexpr USHORT FLUSH_FINI = (FLUSH_ALL | FLUSH_RLSE);
167167

168168
#endif // JRD_CCH_PROTO_H

0 commit comments

Comments
 (0)