SystemFiveLocker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2008 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00017     final class SystemFiveLocker extends BaseLocker
00018     {
00019         public function get($key)
00020         {
00021             try {
00022                 if (!isset($this->pool[$key]))
00023                     $this->pool[$key] = sem_get($key, 1, ONPHP_IPC_PERMS, false);
00024                 
00025                 return sem_acquire($this->pool[$key]);
00026             } catch (BaseException $e) {
00027                 return null;
00028             }
00029             
00030             Assert::isUnreachable();
00031         }
00032         
00033         public function free($key)
00034         {
00035             if (isset($this->pool[$key])) {
00036                 try {
00037                     return sem_release($this->pool[$key]);
00038                 } catch (BaseException $e) {
00039                     // acquired by another process
00040                     return false;
00041                 }
00042             }
00043             
00044             return null;
00045         }
00046         
00047         public function drop($key)
00048         {
00049             if (isset($this->pool[$key])) {
00050                 try {
00051                     return sem_remove($this->pool[$key]);
00052                 } catch (BaseException $e) {
00053                     unset($this->pool[$key]); // already race-removed
00054                     return false;
00055                 }
00056             }
00057             
00058             return null;
00059         }
00060     }
00061 ?>