| @@ 977-990 (lines=14) @@ | ||
| 974 | * @param int $timeout |
|
| 975 | * @return bool |
|
| 976 | */ |
|
| 977 | public function lock( $lockName, $method, $timeout = 5 ) { |
|
| 978 | $lockName = $this->addQuotes( $this->makeLockName( $lockName ) ); |
|
| 979 | $result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method ); |
|
| 980 | $row = $this->fetchObject( $result ); |
|
| 981 | ||
| 982 | if ( $row->lockstatus == 1 ) { |
|
| 983 | parent::lock( $lockName, $method, $timeout ); // record |
|
| 984 | return true; |
|
| 985 | } |
|
| 986 | ||
| 987 | wfDebug( __METHOD__ . " failed to acquire lock\n" ); |
|
| 988 | ||
| 989 | return false; |
|
| 990 | } |
|
| 991 | ||
| 992 | /** |
|
| 993 | * FROM MYSQL DOCS: |
|
| @@ 999-1012 (lines=14) @@ | ||
| 996 | * @param string $method |
|
| 997 | * @return bool |
|
| 998 | */ |
|
| 999 | public function unlock( $lockName, $method ) { |
|
| 1000 | $lockName = $this->addQuotes( $this->makeLockName( $lockName ) ); |
|
| 1001 | $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method ); |
|
| 1002 | $row = $this->fetchObject( $result ); |
|
| 1003 | ||
| 1004 | if ( $row->lockstatus == 1 ) { |
|
| 1005 | parent::unlock( $lockName, $method ); // record |
|
| 1006 | return true; |
|
| 1007 | } |
|
| 1008 | ||
| 1009 | wfDebug( __METHOD__ . " failed to release lock\n" ); |
|
| 1010 | ||
| 1011 | return false; |
|
| 1012 | } |
|
| 1013 | ||
| 1014 | private function makeLockName( $lockName ) { |
|
| 1015 | // http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock |
|
| @@ 1616-1629 (lines=14) @@ | ||
| 1613 | * @param string $method |
|
| 1614 | * @return bool |
|
| 1615 | */ |
|
| 1616 | public function unlock( $lockName, $method ) { |
|
| 1617 | $key = $this->addQuotes( $this->bigintFromLockName( $lockName ) ); |
|
| 1618 | $result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method ); |
|
| 1619 | $row = $this->fetchObject( $result ); |
|
| 1620 | ||
| 1621 | if ( $row->lockstatus === 't' ) { |
|
| 1622 | parent::unlock( $lockName, $method ); // record |
|
| 1623 | return true; |
|
| 1624 | } |
|
| 1625 | ||
| 1626 | wfDebug( __METHOD__ . " failed to release lock\n" ); |
|
| 1627 | ||
| 1628 | return false; |
|
| 1629 | } |
|
| 1630 | ||
| 1631 | /** |
|
| 1632 | * @param string $lockName |
|