Skip to content

Commit 786a733

Browse files
committed
constexpr/noexcept/final in Monitoring
1 parent 34b9cd0 commit 786a733

File tree

2 files changed

+47
-48
lines changed

2 files changed

+47
-48
lines changed

src/jrd/Monitoring.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
#define getpid _getpid
5555
#endif
5656

57-
const char* const SCRATCH = "fb_monitor_";
57+
constexpr const char* SCRATCH = "fb_monitor_";
5858

5959
using namespace Firebird;
6060
using namespace Jrd;
6161

6262

6363
namespace
6464
{
65-
class DumpWriter : public SnapshotData::DumpRecord::Writer
65+
class DumpWriter final : public SnapshotData::DumpRecord::Writer
6666
{
6767
public:
6868
DumpWriter(MonitoringData* data, AttNumber att_id, const char* user_name, ULONG generation)
@@ -71,7 +71,7 @@ namespace
7171
fb_assert(offset);
7272
}
7373

74-
void write(const SnapshotData::DumpRecord& record)
74+
void write(const SnapshotData::DumpRecord& record) override
7575
{
7676
const ULONG length = record.getLength();
7777
dump->write(offset, sizeof(ULONG), &length);
@@ -83,14 +83,14 @@ namespace
8383
const ULONG offset;
8484
};
8585

86-
class TempWriter : public SnapshotData::DumpRecord::Writer
86+
class TempWriter final : public SnapshotData::DumpRecord::Writer
8787
{
8888
public:
89-
TempWriter(TempSpace& temp)
89+
TempWriter(TempSpace& temp) noexcept
9090
: tempSpace(temp)
9191
{}
9292

93-
void write(const SnapshotData::DumpRecord& record)
93+
void write(const SnapshotData::DumpRecord& record) override
9494
{
9595
const offset_t offset = tempSpace.getSize();
9696
const ULONG length = record.getLength();
@@ -102,22 +102,22 @@ namespace
102102
TempSpace& tempSpace;
103103
};
104104

105-
const ULONG HEADER_SIZE = (ULONG) FB_ALIGN(sizeof(MonitoringHeader), FB_ALIGNMENT);
105+
constexpr ULONG HEADER_SIZE = (ULONG) FB_ALIGN(sizeof(MonitoringHeader), FB_ALIGNMENT);
106106

107107
} // namespace
108108

109109

110110
const Format* MonitoringTableScan::getFormat(thread_db* tdbb, jrd_rel* relation) const
111111
{
112-
MonitoringSnapshot* const snapshot = MonitoringSnapshot::create(tdbb);
112+
const auto* const snapshot = MonitoringSnapshot::create(tdbb);
113113
return snapshot->getData(relation)->getFormat();
114114
}
115115

116116

117117
bool MonitoringTableScan::retrieveRecord(thread_db* tdbb, jrd_rel* relation,
118118
FB_UINT64 position, Record* record) const
119119
{
120-
MonitoringSnapshot* const snapshot = MonitoringSnapshot::create(tdbb);
120+
const auto* const snapshot = MonitoringSnapshot::create(tdbb);
121121
if (!snapshot->getData(relation)->fetch(position, record))
122122
return false;
123123

@@ -149,7 +149,7 @@ bool MonitoringTableScan::retrieveRecord(thread_db* tdbb, jrd_rel* relation,
149149

150150
// hvlad: this will assign local system (server) time zone that was actual
151151
// when current attachment created.
152-
Attachment* att = tdbb->getAttachment();
152+
const Attachment* att = tdbb->getAttachment();
153153
ts->time_zone = att->att_timestamp.time_zone;
154154
}
155155
}
@@ -260,8 +260,8 @@ void MonitoringData::enumerate(const char* userName, ULONG generation, SessionLi
260260

261261
for (ULONG offset = HEADER_SIZE; offset < m_sharedMemory->getHeader()->used;)
262262
{
263-
const auto ptr = (UCHAR*) m_sharedMemory->getHeader() + offset;
264-
const auto element = (Element*) ptr;
263+
const auto* ptr = (UCHAR*) m_sharedMemory->getHeader() + offset;
264+
const auto* element = (Element*) ptr;
265265
const ULONG length = element->getBlockLength();
266266

267267
if (!userName || !strcmp(element->userName, userName)) // permitted
@@ -288,8 +288,8 @@ void MonitoringData::read(const char* userName, TempSpace& temp)
288288

289289
for (ULONG offset = HEADER_SIZE; offset < m_sharedMemory->getHeader()->used;)
290290
{
291-
const auto ptr = (UCHAR*) m_sharedMemory->getHeader() + offset;
292-
const auto element = (Element*) ptr;
291+
const auto* ptr = (UCHAR*) m_sharedMemory->getHeader() + offset;
292+
const auto* element = (Element*) ptr;
293293
const ULONG length = element->getBlockLength();
294294

295295
if (!userName || !strcmp(element->userName, userName)) // permitted
@@ -344,7 +344,7 @@ void MonitoringData::cleanup(AttNumber att_id)
344344
for (ULONG offset = HEADER_SIZE; offset < m_sharedMemory->getHeader()->used;)
345345
{
346346
const auto ptr = (UCHAR*) m_sharedMemory->getHeader() + offset;
347-
const auto element = (Element*) ptr;
347+
const auto* element = (Element*) ptr;
348348
const ULONG length = element->getBlockLength();
349349

350350
if (element->attId == att_id)
@@ -369,7 +369,7 @@ void MonitoringData::cleanup(AttNumber att_id)
369369

370370
void MonitoringData::ensureSpace(ULONG length)
371371
{
372-
FB_UINT64 newSize = m_sharedMemory->getHeader()->used + length;
372+
const FB_UINT64 newSize = m_sharedMemory->getHeader()->used + length;
373373

374374
if (newSize > m_sharedMemory->getHeader()->allocated)
375375
{
@@ -693,7 +693,7 @@ MonitoringSnapshot::MonitoringSnapshot(thread_db* tdbb, MemoryPool& pool)
693693
}
694694

695695

696-
void SnapshotData::clearSnapshot()
696+
void SnapshotData::clearSnapshot() noexcept
697697
{
698698
for (FB_SIZE_T i = 0; i < m_snapshot.getCount(); i++)
699699
delete m_snapshot[i].data;
@@ -702,15 +702,15 @@ void SnapshotData::clearSnapshot()
702702
}
703703

704704

705-
RecordBuffer* SnapshotData::getData(const jrd_rel* relation) const
705+
RecordBuffer* SnapshotData::getData(const jrd_rel* relation) const noexcept
706706
{
707707
fb_assert(relation);
708708

709709
return getData(relation->rel_id);
710710
}
711711

712712

713-
RecordBuffer* SnapshotData::getData(int id) const
713+
RecordBuffer* SnapshotData::getData(int id) const noexcept
714714
{
715715
for (FB_SIZE_T i = 0; i < m_snapshot.getCount(); i++)
716716
{
@@ -897,7 +897,7 @@ void SnapshotData::putField(thread_db* tdbb, Record* record, const DumpField& fi
897897
// Monitoring class
898898

899899

900-
SINT64 Monitoring::getGlobalId(int value)
900+
SINT64 Monitoring::getGlobalId(int value) noexcept
901901
{
902902
return ((SINT64) getpid() << BITS_PER_LONG) + value;
903903
}
@@ -912,7 +912,7 @@ void Monitoring::putDatabase(thread_db* tdbb, SnapshotData::DumpRecord& record)
912912
// Determine the backup state
913913
int backupState = backup_state_unknown;
914914

915-
const auto bm = dbb->dbb_backup_manager;
915+
const auto* bm = dbb->dbb_backup_manager;
916916

917917
if (bm && !bm->isShutDown())
918918
{
@@ -1042,7 +1042,7 @@ void Monitoring::putAttachment(SnapshotData::DumpRecord& record, const Jrd::Atta
10421042
if (!attachment->att_user)
10431043
return;
10441044

1045-
const auto dbb = attachment->att_database;
1045+
const auto* dbb = attachment->att_database;
10461046

10471047
record.reset(rel_mon_attachments);
10481048

@@ -1281,7 +1281,7 @@ void Monitoring::putRequest(SnapshotData::DumpRecord& record, const Request* req
12811281
{
12821282
fb_assert(request);
12831283

1284-
const auto dbb = request->req_attachment->att_database;
1284+
const auto* dbb = request->req_attachment->att_database;
12851285

12861286
record.reset(rel_mon_statements);
12871287

@@ -1344,7 +1344,7 @@ void Monitoring::putCall(SnapshotData::DumpRecord& record, const Request* reques
13441344
{
13451345
fb_assert(request);
13461346

1347-
const auto dbb = request->req_attachment->att_database;
1347+
const auto* dbb = request->req_attachment->att_database;
13481348
auto initialRequest = request->req_caller;
13491349

13501350
while (initialRequest->req_caller)
@@ -1527,7 +1527,7 @@ void Monitoring::putMemoryUsage(SnapshotData::DumpRecord& record, const MemorySt
15271527

15281528
void Monitoring::checkState(thread_db* tdbb)
15291529
{
1530-
const auto dbb = tdbb->getDatabase();
1530+
const auto* dbb = tdbb->getDatabase();
15311531
const auto attachment = tdbb->getAttachment();
15321532

15331533
if (!(attachment && (attachment->att_flags & ATT_monitor_init)))
@@ -1621,7 +1621,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
16211621

16221622
for (const auto request : attachment->att_requests)
16231623
{
1624-
const auto statement = request->getStatement();
1624+
const auto* statement = request->getStatement();
16251625

16261626
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
16271627
{

src/jrd/Monitoring.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class SnapshotData
6565

6666
struct DumpField
6767
{
68-
DumpField(USHORT p_id, ValueType p_type, ULONG p_length, const void* p_data)
68+
DumpField(USHORT p_id, ValueType p_type, ULONG p_length, const void* p_data) noexcept
6969
: id(p_id), type(p_type), length(p_length), data(p_data)
7070
{}
7171

72-
DumpField()
72+
DumpField() noexcept
7373
: id(0), type(VALUE_UNKNOWN), length(0), data(NULL)
7474
{}
7575

@@ -109,12 +109,12 @@ class SnapshotData
109109
buffer.assign(ptr, length);
110110
}
111111

112-
ULONG getLength() const
112+
ULONG getLength() const noexcept
113113
{
114114
return offset;
115115
}
116116

117-
const UCHAR* getData() const
117+
const UCHAR* getData() const noexcept
118118
{
119119
return buffer.begin();
120120
}
@@ -168,13 +168,13 @@ class SnapshotData
168168
storeField(field_id, VALUE_BOOLEAN, sizeof(UCHAR), &boolean);
169169
}
170170

171-
int getRelationId()
171+
int getRelationId() noexcept
172172
{
173173
fb_assert(!offset);
174174
return (ULONG) buffer[offset++];
175175
}
176176

177-
bool getField(DumpField& field)
177+
bool getField(DumpField& field) noexcept
178178
{
179179
fb_assert(offset);
180180

@@ -233,9 +233,9 @@ class SnapshotData
233233
void putField(thread_db*, Record*, const DumpField&);
234234

235235
RecordBuffer* allocBuffer(thread_db*, MemoryPool&, int);
236-
RecordBuffer* getData(const jrd_rel*) const;
237-
RecordBuffer* getData(int) const;
238-
void clearSnapshot();
236+
RecordBuffer* getData(const jrd_rel*) const noexcept;
237+
RecordBuffer* getData(int) const noexcept;
238+
void clearSnapshot() noexcept;
239239

240240
private:
241241
Firebird::Array<RelationData> m_snapshot;
@@ -253,8 +253,8 @@ struct MonitoringHeader : public Firebird::MemoryHeader
253253

254254
class MonitoringData final : public Firebird::PermanentStorage, public Firebird::IpcObject
255255
{
256-
static const USHORT MONITOR_VERSION = 6;
257-
static const ULONG DEFAULT_SIZE = 1048576;
256+
static constexpr USHORT MONITOR_VERSION = 6;
257+
static constexpr ULONG DEFAULT_SIZE = 1048576;
258258

259259
typedef MonitoringHeader Header;
260260

@@ -286,10 +286,10 @@ class MonitoringData final : public Firebird::PermanentStorage, public Firebird:
286286
data->release();
287287
}
288288

289-
private:
290-
Guard(const Guard&);
291-
Guard& operator=(const Guard&);
289+
Guard(const Guard&) = delete;
290+
Guard& operator=(const Guard&) = delete;
292291

292+
private:
293293
MonitoringData* const data;
294294
};
295295

@@ -330,6 +330,10 @@ class MonitoringData final : public Firebird::PermanentStorage, public Firebird:
330330
explicit MonitoringData(Database*);
331331
~MonitoringData();
332332

333+
// copying is prohibited
334+
MonitoringData(const MonitoringData&) = delete;
335+
MonitoringData& operator =(const MonitoringData&) = delete;
336+
333337
bool initialize(Firebird::SharedMemoryBase*, bool) override;
334338
void mutexBug(int osErrorCode, const char* text) override;
335339

@@ -350,10 +354,6 @@ class MonitoringData final : public Firebird::PermanentStorage, public Firebird:
350354
void cleanup(AttNumber);
351355

352356
private:
353-
// copying is prohibited
354-
MonitoringData(const MonitoringData&);
355-
MonitoringData& operator =(const MonitoringData&);
356-
357357
void ensureSpace(ULONG);
358358

359359
const Firebird::string& m_dbId;
@@ -362,7 +362,7 @@ class MonitoringData final : public Firebird::PermanentStorage, public Firebird:
362362
};
363363

364364

365-
class MonitoringTableScan: public VirtualTableScan
365+
class MonitoringTableScan final : public VirtualTableScan
366366
{
367367
public:
368368
MonitoringTableScan(CompilerScratch* csb, const Firebird::string& alias,
@@ -377,7 +377,7 @@ class MonitoringTableScan: public VirtualTableScan
377377
};
378378

379379

380-
class MonitoringSnapshot : public SnapshotData
380+
class MonitoringSnapshot final : public SnapshotData
381381
{
382382
public:
383383
static MonitoringSnapshot* create(thread_db* tdbb);
@@ -403,7 +403,6 @@ class Monitoring
403403
}
404404

405405
static void checkState(thread_db* tdbb);
406-
static SnapshotData* getSnapshot(thread_db* tdbb);
407406

408407
static void dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG generation);
409408

@@ -412,7 +411,7 @@ class Monitoring
412411

413412
static void putDatabase(thread_db* tdbb, SnapshotData::DumpRecord&);
414413
private:
415-
static SINT64 getGlobalId(int);
414+
static SINT64 getGlobalId(int) noexcept;
416415

417416
static void putAttachment(SnapshotData::DumpRecord&, const Attachment*);
418417
static void putTransaction(SnapshotData::DumpRecord&, const jrd_tra*);

0 commit comments

Comments
 (0)