@@ 999-1012 (lines=14) @@ | ||
996 | * @param int $timeout |
|
997 | * @return bool |
|
998 | */ |
|
999 | public function lock( $lockName, $method, $timeout = 5 ) { |
|
1000 | $encName = $this->addQuotes( $this->makeLockName( $lockName ) ); |
|
1001 | $result = $this->query( "SELECT GET_LOCK($encName, $timeout) AS lockstatus", $method ); |
|
1002 | $row = $this->fetchObject( $result ); |
|
1003 | ||
1004 | if ( $row->lockstatus == 1 ) { |
|
1005 | parent::lock( $lockName, $method, $timeout ); // record |
|
1006 | return true; |
|
1007 | } |
|
1008 | ||
1009 | $this->queryLogger->warning( __METHOD__ . " failed to acquire lock '$lockName'\n" ); |
|
1010 | ||
1011 | return false; |
|
1012 | } |
|
1013 | ||
1014 | /** |
|
1015 | * FROM MYSQL DOCS: |
|
@@ 1021-1034 (lines=14) @@ | ||
1018 | * @param string $method |
|
1019 | * @return bool |
|
1020 | */ |
|
1021 | public function unlock( $lockName, $method ) { |
|
1022 | $encName = $this->addQuotes( $this->makeLockName( $lockName ) ); |
|
1023 | $result = $this->query( "SELECT RELEASE_LOCK($encName) as lockstatus", $method ); |
|
1024 | $row = $this->fetchObject( $result ); |
|
1025 | ||
1026 | if ( $row->lockstatus == 1 ) { |
|
1027 | parent::unlock( $lockName, $method ); // record |
|
1028 | return true; |
|
1029 | } |
|
1030 | ||
1031 | $this->queryLogger->warning( __METHOD__ . " failed to release lock '$lockName'\n" ); |
|
1032 | ||
1033 | return false; |
|
1034 | } |
|
1035 | ||
1036 | private function makeLockName( $lockName ) { |
|
1037 | // http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock |