Skip to content

Commit b05aeb8

Browse files
committed
Internal documentation for connection reference and pointer
1 parent 0ea634b commit b05aeb8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

dev/connection_holder.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ namespace sqlite_orm {
118118
return _control.db;
119119
}
120120

121-
// optional fast path: if connection is already open, just increment counter;
121+
// required fast path: if connection is already open, just increment counter;
122+
// it is required otherwise 'retain if open' would be useless;
123+
// with respect to performance,
122124
// this can make a difference while a transaction is active where all things happen in memory only;
123125
// it makes a difference if the `_didOpenDb` callback has a lot of work to do.
124126
if (int currentCount = _control.retainCount.load(std::memory_order_acquire)) {
@@ -134,7 +136,7 @@ namespace sqlite_orm {
134136
} while (currentCount > 0);
135137
}
136138
// test for recursion from the same thread
137-
else {
139+
else /*currentCount==0*/ {
138140
const std::thread::id threadId = _control.initializingThreadId.load(std::memory_order_acquire);
139141
if (threadId != std::thread::id{} && std::this_thread::get_id() == threadId)
140142
SQLITE_ORM_CPP_UNLIKELY {
@@ -146,6 +148,7 @@ namespace sqlite_orm {
146148
}
147149

148150
sqlite3* retain() {
151+
// optional fast path: if connection is already open, just increment counter;
149152
if (sqlite3* db = retain_if_open()) {
150153
return db;
151154
}
@@ -223,6 +226,9 @@ namespace sqlite_orm {
223226
const std::function<void(sqlite3* db)> _didOpenDb;
224227
};
225228

229+
/*
230+
Acquires a database connection upon construction and releases it upon destruction.
231+
*/
226232
struct connection_ref {
227233
connection_ref(connection_holder& holder) : holder{&holder}, db{holder.retain()} {}
228234

@@ -251,6 +257,9 @@ namespace sqlite_orm {
251257
sqlite3* db;
252258
};
253259

260+
/*
261+
Increases the reference count of an existing open connection upon construction and releases it upon destruction.
262+
*/
254263
struct connection_ptr {
255264
connection_ptr(connection_holder& holder) : holder{&holder}, db{holder.retain_if_open()} {}
256265

include/sqlite_orm/sqlite_orm.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14745,7 +14745,9 @@ namespace sqlite_orm {
1474514745
return _control.db;
1474614746
}
1474714747

14748-
// optional fast path: if connection is already open, just increment counter;
14748+
// required fast path: if connection is already open, just increment counter;
14749+
// it is required otherwise 'retain if open' would be useless;
14750+
// with respect to performance,
1474914751
// this can make a difference while a transaction is active where all things happen in memory only;
1475014752
// it makes a difference if the `_didOpenDb` callback has a lot of work to do.
1475114753
if (int currentCount = _control.retainCount.load(std::memory_order_acquire)) {
@@ -14761,7 +14763,7 @@ namespace sqlite_orm {
1476114763
} while (currentCount > 0);
1476214764
}
1476314765
// test for recursion from the same thread
14764-
else {
14766+
else /*currentCount==0*/ {
1476514767
const std::thread::id threadId = _control.initializingThreadId.load(std::memory_order_acquire);
1476614768
if (threadId != std::thread::id{} && std::this_thread::get_id() == threadId)
1476714769
SQLITE_ORM_CPP_UNLIKELY {
@@ -14773,6 +14775,7 @@ namespace sqlite_orm {
1477314775
}
1477414776

1477514777
sqlite3* retain() {
14778+
// optional fast path: if connection is already open, just increment counter;
1477614779
if (sqlite3* db = retain_if_open()) {
1477714780
return db;
1477814781
}
@@ -14850,6 +14853,9 @@ namespace sqlite_orm {
1485014853
const std::function<void(sqlite3* db)> _didOpenDb;
1485114854
};
1485214855

14856+
/*
14857+
Acquires a database connection upon construction and releases it upon destruction.
14858+
*/
1485314859
struct connection_ref {
1485414860
connection_ref(connection_holder& holder) : holder{&holder}, db{holder.retain()} {}
1485514861

@@ -14878,6 +14884,9 @@ namespace sqlite_orm {
1487814884
sqlite3* db;
1487914885
};
1488014886

14887+
/*
14888+
Increases the reference count of an existing open connection upon construction and releases it upon destruction.
14889+
*/
1488114890
struct connection_ptr {
1488214891
connection_ptr(connection_holder& holder) : holder{&holder}, db{holder.retain_if_open()} {}
1488314892

0 commit comments

Comments
 (0)