Skip to content

Commit

Permalink
Better handle the record lock enumerations
Browse files Browse the repository at this point in the history
  • Loading branch information
paladine committed Oct 7, 2024
1 parent dc0471b commit 00d8e94
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 127 deletions.
137 changes: 79 additions & 58 deletions btrieve/OperationCode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
#include <cstdio>

namespace btrieve {

#define CASE_WITH_RECORD_LOCK(a) \
case a: \
case a##_SingleWaitRecordLock: \
case a##_SingleNoWaitRecordLock: \
case a##_MultipleWaitRecordLock: \
case a##_MultipleNoWaitRecordLock

// clang-format off
bool requiresKey(OperationCode operationCode) {
switch (operationCode) {
case OperationCode::AcquireEqual:
case OperationCode::AcquireGreater:
case OperationCode::AcquireGreaterOrEqual:
case OperationCode::AcquireLess:
case OperationCode::AcquireLessOrEqual:
case OperationCode::QueryEqual:
case OperationCode::QueryGreater:
case OperationCode::QueryGreaterOrEqual:
case OperationCode::QueryLess:
case OperationCode::QueryLessOrEqual:
CASE_WITH_RECORD_LOCK(OperationCode::AcquireEqual):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireGreater):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireGreaterOrEqual):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireLess):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireLessOrEqual):
CASE_WITH_RECORD_LOCK(OperationCode::QueryEqual):
CASE_WITH_RECORD_LOCK(OperationCode::QueryGreater):
CASE_WITH_RECORD_LOCK(OperationCode::QueryGreaterOrEqual):
CASE_WITH_RECORD_LOCK(OperationCode::QueryLess):
CASE_WITH_RECORD_LOCK(OperationCode::QueryLessOrEqual):
return true;
default:
return false;
Expand All @@ -23,21 +32,21 @@ bool requiresKey(OperationCode operationCode) {

bool acquiresData(OperationCode operationCode) {
switch (operationCode) {
case OperationCode::AcquireEqual:
case OperationCode::AcquireNext:
case OperationCode::AcquirePrevious:
case OperationCode::AcquireGreater:
case OperationCode::AcquireGreaterOrEqual:
case OperationCode::AcquireLess:
case OperationCode::AcquireLessOrEqual:
case OperationCode::AcquireFirst:
case OperationCode::AcquireLast:
case OperationCode::StepFirst:
case OperationCode::StepLast:
case OperationCode::StepNext:
case OperationCode::StepNextExtended:
case OperationCode::StepPrevious:
case OperationCode::StepPreviousExtended:
CASE_WITH_RECORD_LOCK(OperationCode::AcquireEqual):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireNext):
CASE_WITH_RECORD_LOCK(OperationCode::AcquirePrevious):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireGreater):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireGreaterOrEqual):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireLess):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireLessOrEqual):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireFirst):
CASE_WITH_RECORD_LOCK(OperationCode::AcquireLast):
CASE_WITH_RECORD_LOCK(OperationCode::StepFirst):
CASE_WITH_RECORD_LOCK(OperationCode::StepLast):
CASE_WITH_RECORD_LOCK(OperationCode::StepNext):
CASE_WITH_RECORD_LOCK(OperationCode::StepNextExtended):
CASE_WITH_RECORD_LOCK(OperationCode::StepPrevious):
CASE_WITH_RECORD_LOCK(OperationCode::StepPreviousExtended):
return true;
default:
return false;
Expand All @@ -46,14 +55,14 @@ bool acquiresData(OperationCode operationCode) {

bool usesPreviousQuery(OperationCode operationCode) {
switch (operationCode) {
case OperationCode::AcquireNext:
case OperationCode::AcquirePrevious:
case OperationCode::StepNext:
case OperationCode::StepNextExtended:
case OperationCode::StepPrevious:
case OperationCode::StepPreviousExtended:
case OperationCode::QueryNext:
case OperationCode::QueryPrevious:
CASE_WITH_RECORD_LOCK(OperationCode::AcquireNext):
CASE_WITH_RECORD_LOCK(OperationCode::AcquirePrevious):
CASE_WITH_RECORD_LOCK(OperationCode::StepNext):
CASE_WITH_RECORD_LOCK(OperationCode::StepNextExtended):
CASE_WITH_RECORD_LOCK(OperationCode::StepPrevious):
CASE_WITH_RECORD_LOCK(OperationCode::StepPreviousExtended):
CASE_WITH_RECORD_LOCK(OperationCode::QueryNext):
CASE_WITH_RECORD_LOCK(OperationCode::QueryPrevious):
return true;
default:
return false;
Expand All @@ -64,43 +73,55 @@ bool usesPreviousQuery(OperationCode operationCode) {
case a: \
return #a

#define HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(a) \
case a: \
return #a; \
case a##_SingleWaitRecordLock: \
return #a "_SingleWaitRecordLock"; \
case a##_SingleNoWaitRecordLock: \
return #a "_SingleNoWaitRecordLock"; \
case a##_MultipleWaitRecordLock: \
return #a "_MultipleWaitRecordLock"; \
case a##_MultipleNoWaitRecordLock: \
return #a "_MultipleNoWaitRecordLock"

const char* toString(OperationCode operationCode) {
switch (operationCode) {
HANDLE_OPERATION_CODE(Open);
HANDLE_OPERATION_CODE(Close);
HANDLE_OPERATION_CODE(Insert);
HANDLE_OPERATION_CODE(Update);
HANDLE_OPERATION_CODE(Delete);
HANDLE_OPERATION_CODE(AcquireEqual);
HANDLE_OPERATION_CODE(AcquireNext);
HANDLE_OPERATION_CODE(AcquirePrevious);
HANDLE_OPERATION_CODE(AcquireGreater);
HANDLE_OPERATION_CODE(AcquireGreaterOrEqual);
HANDLE_OPERATION_CODE(AcquireLess);
HANDLE_OPERATION_CODE(AcquireLessOrEqual);
HANDLE_OPERATION_CODE(AcquireFirst);
HANDLE_OPERATION_CODE(AcquireLast);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireNext);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquirePrevious);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireGreater);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireGreaterOrEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireLess);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireLessOrEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireFirst);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(AcquireLast);
HANDLE_OPERATION_CODE(Create);
HANDLE_OPERATION_CODE(Stat);
HANDLE_OPERATION_CODE(Extend);
HANDLE_OPERATION_CODE(GetPosition);
HANDLE_OPERATION_CODE(GetDirectChunkOrRecord);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(GetDirectChunkOrRecord);
HANDLE_OPERATION_CODE(SetOwner);
HANDLE_OPERATION_CODE(StepFirst);
HANDLE_OPERATION_CODE(StepLast);
HANDLE_OPERATION_CODE(StepNext);
HANDLE_OPERATION_CODE(StepNextExtended);
HANDLE_OPERATION_CODE(StepPrevious);
HANDLE_OPERATION_CODE(StepPreviousExtended);
HANDLE_OPERATION_CODE(QueryEqual);
HANDLE_OPERATION_CODE(QueryNext);
HANDLE_OPERATION_CODE(QueryPrevious);
HANDLE_OPERATION_CODE(QueryGreater);
HANDLE_OPERATION_CODE(QueryGreaterOrEqual);
HANDLE_OPERATION_CODE(QueryLess);
HANDLE_OPERATION_CODE(QueryLessOrEqual);
HANDLE_OPERATION_CODE(QueryFirst);
HANDLE_OPERATION_CODE(QueryLast);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepFirst);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepLast);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepNext);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepNextExtended);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepPrevious);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(StepPreviousExtended);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryNext);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryPrevious);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryGreater);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryGreaterOrEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryLess);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryLessOrEqual);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryFirst);
HANDLE_OPERATION_CODE_WITH_RECORD_LOCK(QueryLast);
HANDLE_OPERATION_CODE(Stop);
HANDLE_OPERATION_CODE(None);
default:
Expand Down
57 changes: 32 additions & 25 deletions btrieve/OperationCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#define __OPERATION_CODES_H_

namespace btrieve {

#define WITH_RECORD_LOCK(a, value) \
a = value, a##_SingleWaitRecordLock = value + 100, \
a##_SingleNoWaitRecordLock = value + 200, \
a##_MultipleWaitRecordLock = value + 300, \
a##_MultipleNoWaitRecordLock = value + 400

enum OperationCode {
// Utility
Open = 0x0,
Expand All @@ -13,103 +20,103 @@ enum OperationCode {
// Acquire Operations
//[AcquiresData]
//[RequiresKey]
AcquireEqual = 0x5,
WITH_RECORD_LOCK(AcquireEqual, 0x5),

//[AcquiresData]
//[UsesPreviousQuery]
AcquireNext = 0x6,
WITH_RECORD_LOCK(AcquireNext, 0x6),

//[AcquiresData]
//[UsesPreviousQuery]
AcquirePrevious = 0x7,
WITH_RECORD_LOCK(AcquirePrevious, 0x7),

//[AcquiresData]
//[RequiresKey]
AcquireGreater = 0x8,
WITH_RECORD_LOCK(AcquireGreater, 0x8),

//[AcquiresData]
//[RequiresKey]
AcquireGreaterOrEqual = 0x9,
WITH_RECORD_LOCK(AcquireGreaterOrEqual, 0x9),

//[AcquiresData]
//[RequiresKey]
AcquireLess = 0xA,
WITH_RECORD_LOCK(AcquireLess, 0xA),

//[AcquiresData]
//[RequiresKey]
AcquireLessOrEqual = 0xB,
WITH_RECORD_LOCK(AcquireLessOrEqual, 0xB),

//[AcquiresData]
AcquireFirst = 0xC,
WITH_RECORD_LOCK(AcquireFirst, 0xC),

//[AcquiresData]
AcquireLast = 0xD,
WITH_RECORD_LOCK(AcquireLast, 0xD),

Create = 0xE,
// Information Operations
Stat = 0xF,
Extend = 0x10,
GetPosition = 0x16,
GetDirectChunkOrRecord = 0x17,
WITH_RECORD_LOCK(GetDirectChunkOrRecord, 0x17),
SetOwner = 0x1D,

// Step Operations, operates on physical offset not keys
//[AcquiresData]
StepFirst = 0x21,
WITH_RECORD_LOCK(StepFirst, 0x21),

//[AcquiresData]
StepLast = 0x22,
WITH_RECORD_LOCK(StepLast, 0x22),

//[AcquiresData]
//[UsesPreviousQuery]
StepNext = 0x18,
WITH_RECORD_LOCK(StepNext, 0x18),

//[AcquiresData]
//[UsesPreviousQuery]
StepNextExtended = 0x26,
WITH_RECORD_LOCK(StepNextExtended, 0x26),

//[AcquiresData]
//[UsesPreviousQuery]
StepPrevious = 0x23,
WITH_RECORD_LOCK(StepPrevious, 0x23),

//[AcquiresData]
//[UsesPreviousQuery]
StepPreviousExtended = 0x27,
WITH_RECORD_LOCK(StepPreviousExtended, 0x27),

// Query Operations
//[QueryOnly]
//[RequiresKey]
QueryEqual = 0x37,
WITH_RECORD_LOCK(QueryEqual, 0x37),

//[QueryOnly]
//[UsesPreviousQuery]
QueryNext = 0x38,
WITH_RECORD_LOCK(QueryNext, 0x38),

//[QueryOnly]
//[UsesPreviousQuery]
QueryPrevious = 0x39,
WITH_RECORD_LOCK(QueryPrevious, 0x39),

//[QueryOnly]
//[RequiresKey]
QueryGreater = 0x3A,
WITH_RECORD_LOCK(QueryGreater, 0x3A),

//[QueryOnly]
//[RequiresKey]
QueryGreaterOrEqual = 0x3B,
WITH_RECORD_LOCK(QueryGreaterOrEqual, 0x3B),

//[QueryOnly]
//[RequiresKey]
QueryLess = 0x3C,
WITH_RECORD_LOCK(QueryLess, 0x3C),

//[QueryOnly]
//[RequiresKey]
QueryLessOrEqual = 0x3D,
WITH_RECORD_LOCK(QueryLessOrEqual, 0x3D),

//[QueryOnly]
QueryFirst = 0x3E,
WITH_RECORD_LOCK(QueryFirst, 0x3E),

//[QueryOnly]
QueryLast = 0x3F,
WITH_RECORD_LOCK(QueryLast, 0x3F),

Stop = 0x19,

Expand Down
Loading

0 comments on commit 00d8e94

Please sign in to comment.