@@ -230,7 +230,8 @@ void DbClientLockFree::execSql(
230230}
231231
232232std::shared_ptr<Transaction> DbClientLockFree::newTransaction (
233- const std::function<void (bool )> &) noexcept (false )
233+ const std::function<void (bool )> &,
234+ TransactionType) noexcept (false )
234235{
235236 // Don't support transaction;
236237 LOG_ERROR
@@ -241,7 +242,8 @@ std::shared_ptr<Transaction> DbClientLockFree::newTransaction(
241242}
242243
243244void DbClientLockFree::newTransactionAsync (
244- const std::function<void (const std::shared_ptr<Transaction> &)> &callback)
245+ const std::function<void (const std::shared_ptr<Transaction> &)> &callback,
246+ TransactionType transType)
245247{
246248 loop_->assertInLoopThread ();
247249 for (auto &conn : connections_)
@@ -250,7 +252,8 @@ void DbClientLockFree::newTransactionAsync(
250252 {
251253 makeTrans (conn,
252254 std::function<void (const std::shared_ptr<Transaction> &)>(
253- callback));
255+ callback),
256+ transType);
254257 return ;
255258 }
256259 }
@@ -272,7 +275,7 @@ void DbClientLockFree::newTransactionAsync(
272275 iter != transCallbacks_.end ();
273276 ++iter)
274277 {
275- if (cbPtr == * iter)
278+ if (cbPtr == iter-> first )
276279 {
277280 transCallbacks_.erase (iter);
278281 break ;
@@ -292,16 +295,20 @@ void DbClientLockFree::newTransactionAsync(
292295 *newCallbackPtr = callbackPtr;
293296 timeoutFlagPtr->runTimer ();
294297 }
295- transCallbacks_.push_back (callbackPtr);
298+ transCallbacks_.push_back ({ callbackPtr, transType} );
296299}
297300
298301void DbClientLockFree::makeTrans (
299302 const DbConnectionPtr &conn,
300- std::function<void (const std::shared_ptr<Transaction> &)> &&callback)
303+ std::function<void (const std::shared_ptr<Transaction> &)> &&callback,
304+ TransactionType transType)
301305{
302306 std::weak_ptr<DbClientLockFree> weakThis = shared_from_this ();
303307 auto trans = std::make_shared<TransactionImpl>(
304- type_, conn, std::function<void (bool )>(), [weakThis, conn]() {
308+ type_,
309+ conn,
310+ std::function<void (bool )>(),
311+ [weakThis, conn]() {
305312 auto thisPtr = weakThis.lock ();
306313 if (!thisPtr)
307314 return ;
@@ -312,9 +319,11 @@ void DbClientLockFree::makeTrans(
312319 }
313320 if (!thisPtr->transCallbacks_ .empty ())
314321 {
315- auto callback = std::move (thisPtr->transCallbacks_ .front ());
322+ auto &entry = thisPtr->transCallbacks_ .front ();
323+ auto nextCallback = std::move (*entry.first );
324+ auto nextType = entry.second ;
316325 thisPtr->transCallbacks_ .pop_front ();
317- thisPtr->makeTrans (conn, std::move (*callback) );
326+ thisPtr->makeTrans (conn, std::move (nextCallback), nextType );
318327 return ;
319328 }
320329
@@ -342,7 +351,8 @@ void DbClientLockFree::makeTrans(
342351 break ;
343352 }
344353 }
345- });
354+ },
355+ transType);
346356 transSet_.insert (conn);
347357 trans->doBegin ();
348358 if (timeout_ > 0.0 )
@@ -360,9 +370,11 @@ void DbClientLockFree::handleNewTask(const DbConnectionPtr &conn)
360370
361371 if (!transCallbacks_.empty ())
362372 {
363- auto callback = std::move (transCallbacks_.front ());
373+ auto &entry = transCallbacks_.front ();
374+ auto callback = std::move (*entry.first );
375+ auto transType = entry.second ;
364376 transCallbacks_.pop_front ();
365- makeTrans (conn, std::move (* callback));
377+ makeTrans (conn, std::move (callback), transType );
366378 return ;
367379 }
368380
0 commit comments