SystemFiveLocker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 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 /* $Id: SystemFiveLocker.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     final class SystemFiveLocker extends BaseLocker
00019     {
00020         public function get($key)
00021         {
00022             try {
00023                 if (!isset($this->pool[$key]))
00024                     $this->pool[$key] = sem_get($key, 1, ONPHP_IPC_PERMS, false);
00025                 
00026                 sem_acquire($this->pool[$key]);
00027                 
00028                 return $this->pool[$key];
00029             } catch (BaseException $e) {
00030                 return null;
00031             }
00032             
00033             Assert::isUnreachable();
00034         }
00035         
00036         public function free($key)
00037         {
00038             if (isset($this->pool[$key])) {
00039                 try {
00040                     return sem_release($this->pool[$key]);
00041                 } catch (BaseException $e) {
00042                     // acquired by another process
00043                     return false;
00044                 }
00045             }
00046             
00047             return null;
00048         }
00049         
00050         public function drop($key)
00051         {
00052             if (isset($this->pool[$key])) {
00053                 try {
00054                     return sem_remove($this->pool[$key]);
00055                 } catch (BaseException $e) {
00056                     unset($this->pool[$key]); // already race-removed
00057                     return false;
00058                 }
00059             }
00060             
00061             return null;
00062         }
00063     }
00064 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4