mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-06 14:35:56 +02:00
[feature/system-cron] Rename lock() to acquire and unlock() to release.
PHPBB3-9596
This commit is contained in:
parent
09b136272b
commit
2e47409e80
@ -48,7 +48,7 @@ function do_cron($cron_lock, $run_tasks)
|
||||
}
|
||||
|
||||
// Unloading cache and closing db after having done the dirty work.
|
||||
$cron_lock->unlock();
|
||||
$cron_lock->release();
|
||||
garbage_collection();
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ else
|
||||
}
|
||||
|
||||
$cron_lock = new phpbb_lock_db('cron_lock', $config, $db);
|
||||
if ($cron_lock->lock())
|
||||
if ($cron_lock->acquire())
|
||||
{
|
||||
if ($config['use_system_cron'])
|
||||
{
|
||||
|
@ -80,11 +80,11 @@ class phpbb_lock_db
|
||||
* @return bool true if lock was acquired
|
||||
* false otherwise
|
||||
*/
|
||||
public function lock()
|
||||
public function acquire()
|
||||
{
|
||||
if ($this->locked)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->config[$this->config_name]))
|
||||
@ -119,15 +119,15 @@ class phpbb_lock_db
|
||||
/**
|
||||
* Releases the lock.
|
||||
*
|
||||
* The lock must have been previously obtained, that is, lock() call
|
||||
* The lock must have been previously obtained, that is, acquire() call
|
||||
* was issued and returned true.
|
||||
*
|
||||
* Note: Attempting to release a lock that is already released,
|
||||
* that is, calling unlock() multiple times, is harmless.
|
||||
* that is, calling release() multiple times, is harmless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unlock()
|
||||
public function release()
|
||||
{
|
||||
if ($this->locked)
|
||||
{
|
||||
|
@ -32,52 +32,52 @@ class phpbb_lock_db_test extends phpbb_database_test_case
|
||||
|
||||
public function test_new_lock()
|
||||
{
|
||||
$this->assertTrue($this->lock->lock());
|
||||
$this->assertTrue($this->lock->acquire());
|
||||
$this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
|
||||
|
||||
$lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db);
|
||||
$this->assertFalse($lock2->lock());
|
||||
$this->assertFalse($lock2->acquire());
|
||||
|
||||
$this->lock->unlock();
|
||||
$this->lock->release();
|
||||
$this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
|
||||
}
|
||||
|
||||
public function test_expire_lock()
|
||||
{
|
||||
$lock = new phpbb_lock_db('foo_lock', $this->config, $this->db);
|
||||
$this->assertTrue($lock->lock());
|
||||
$this->assertTrue($lock->acquire());
|
||||
}
|
||||
|
||||
public function test_double_lock()
|
||||
{
|
||||
$this->assertTrue($this->lock->lock());
|
||||
$this->assertTrue($this->lock->acquire());
|
||||
$this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
|
||||
|
||||
$value = $this->config['test_lock'];
|
||||
|
||||
$this->assertTrue($this->lock->lock());
|
||||
$this->assertEquals($value, $this->config['test_lock'], 'Second lock was ignored');
|
||||
$this->assertFalse($this->lock->acquire());
|
||||
$this->assertEquals($value, $this->config['test_lock'], 'Second lock failed');
|
||||
|
||||
$this->lock->unlock();
|
||||
$this->lock->release();
|
||||
$this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
|
||||
}
|
||||
|
||||
public function test_double_unlock()
|
||||
{
|
||||
$this->assertTrue($this->lock->lock());
|
||||
$this->assertTrue($this->lock->acquire());
|
||||
$this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired');
|
||||
|
||||
$this->lock->unlock();
|
||||
$this->lock->release();
|
||||
$this->assertEquals('0', $this->config['test_lock'], 'First lock is released');
|
||||
|
||||
$lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db);
|
||||
$this->assertTrue($lock2->lock());
|
||||
$this->assertTrue($lock2->acquire());
|
||||
$this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired');
|
||||
|
||||
$this->lock->unlock();
|
||||
$this->lock->release();
|
||||
$this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored');
|
||||
|
||||
$lock2->unlock();
|
||||
$lock2->release();
|
||||
$this->assertEquals('0', $this->config['test_lock'], 'Second lock is released');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user