[feature/system-cron] Rename lock() to acquire and unlock() to release.

PHPBB3-9596
This commit is contained in:
Nils Adermann 2011-01-13 02:03:16 +01:00 committed by Oleg Pudeyev
parent 09b136272b
commit 2e47409e80
3 changed files with 20 additions and 20 deletions

View file

@ -48,7 +48,7 @@ function do_cron($cron_lock, $run_tasks)
} }
// Unloading cache and closing db after having done the dirty work. // Unloading cache and closing db after having done the dirty work.
$cron_lock->unlock(); $cron_lock->release();
garbage_collection(); garbage_collection();
} }
@ -74,7 +74,7 @@ else
} }
$cron_lock = new phpbb_lock_db('cron_lock', $config, $db); $cron_lock = new phpbb_lock_db('cron_lock', $config, $db);
if ($cron_lock->lock()) if ($cron_lock->acquire())
{ {
if ($config['use_system_cron']) if ($config['use_system_cron'])
{ {

View file

@ -80,11 +80,11 @@ class phpbb_lock_db
* @return bool true if lock was acquired * @return bool true if lock was acquired
* false otherwise * false otherwise
*/ */
public function lock() public function acquire()
{ {
if ($this->locked) if ($this->locked)
{ {
return true; return false;
} }
if (!isset($this->config[$this->config_name])) if (!isset($this->config[$this->config_name]))
@ -119,15 +119,15 @@ class phpbb_lock_db
/** /**
* Releases the lock. * 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. * was issued and returned true.
* *
* Note: Attempting to release a lock that is already released, * 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 * @return void
*/ */
public function unlock() public function release()
{ {
if ($this->locked) if ($this->locked)
{ {

View file

@ -32,52 +32,52 @@ class phpbb_lock_db_test extends phpbb_database_test_case
public function test_new_lock() 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'); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
$lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $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'); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
} }
public function test_expire_lock() public function test_expire_lock()
{ {
$lock = new phpbb_lock_db('foo_lock', $this->config, $this->db); $lock = new phpbb_lock_db('foo_lock', $this->config, $this->db);
$this->assertTrue($lock->lock()); $this->assertTrue($lock->acquire());
} }
public function test_double_lock() 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'); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
$value = $this->config['test_lock']; $value = $this->config['test_lock'];
$this->assertTrue($this->lock->lock()); $this->assertFalse($this->lock->acquire());
$this->assertEquals($value, $this->config['test_lock'], 'Second lock was ignored'); $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'); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
} }
public function test_double_unlock() 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->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'); $this->assertEquals('0', $this->config['test_lock'], 'First lock is released');
$lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $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->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'); $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'); $this->assertEquals('0', $this->config['test_lock'], 'Second lock is released');
} }
} }