From 370d75876864ab78085070c8d4110d7f8b6462bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 9 Aug 2021 11:36:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Pool/Connection.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index d3b54266..8c397293 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -47,7 +47,7 @@ class Connection extends Component if (!Context::hasContext('begin_' . $coroutineName)) { Context::setContext('begin_' . $coroutineName, 0); } - Context::increment('begin_' . $coroutineName, 1); + Context::increment('begin_' . $coroutineName); $connection = Context::getContext($coroutineName); if ($connection instanceof PDO && !$connection->inTransaction()) { @@ -62,12 +62,11 @@ class Connection extends Component public function commit($coroutineName) { $coroutineName = $this->name('Mysql:' . $coroutineName, true); - if (Context::decrement('begin_' . $coroutineName) > 0) { - return; - } - $connection = Context::getContext($coroutineName); - if ($connection instanceof PDO && $connection->inTransaction()) { - $connection->commit(); + if (Context::decrement('begin_' . $coroutineName) == 1) { + $connection = Context::getContext($coroutineName); + if ($connection instanceof PDO && $connection->inTransaction()) { + $connection->commit(); + } } } @@ -79,12 +78,11 @@ class Connection extends Component public function rollback($coroutineName) { $coroutineName = $this->name('Mysql:' . $coroutineName, true); - if (Context::decrement('begin_' . $coroutineName) > 0) { - return; - } - if (($connection = Context::getContext($coroutineName)) instanceof PDO) { - if ($connection->inTransaction()) { - $connection->rollBack(); + if (Context::decrement('begin_' . $coroutineName) == 1) { + if (($connection = Context::getContext($coroutineName)) instanceof PDO) { + if ($connection->inTransaction()) { + $connection->rollBack(); + } } } }