Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. namespace TYPO3\Flow\Utility\Lock;
  3.  
  4. /*
  5. * This file is part of the Neos.Flow.Lock package.
  6. *
  7. * (c) Contributors of the Neos Project - www.neos.io
  8. *
  9. * This package is Open Source Software. For the full copyright and license
  10. * information, please view the LICENSE file which was distributed with this
  11. * source code.
  12. */
  13.  
  14. /**
  15. * A Semaphore (IPC) based lock strategy.
  16. *
  17. * This lock strategy is based on Semaphore (IPC), only available on System V.
  18. *
  19. */
  20. class SemaphoreLockStrategy implements LockStrategyInterface
  21. {
  22. /**
  23. * Semaphore ID
  24. *
  25. * @var resource
  26. */
  27. protected $semaphoreId;
  28.  
  29. /**
  30. * File pointer if using flock method
  31. *
  32. * @var resource
  33. */
  34. protected $filePointer;
  35.  
  36. /**
  37. * @param string $subject
  38. * @param boolean $exclusiveLock TRUE to, acquire an exclusive (write) lock, FALSE for a shared (read) lock.
  39. * @return void
  40. * @throws LockNotAcquiredException
  41. */
  42. public function acquire($subject, $exclusiveLock)
  43. {
  44. $key = crc32(FLOW_PATH_ROOT . (string)$subject);
  45. $this->semaphoreId = sem_get($key);
  46. sem_acquire($this->semaphoreId);
  47. }
  48.  
  49. /**
  50. * Releases the lock
  51. *
  52. * @return boolean
  53. */
  54. public function release()
  55. {
  56. return @sem_release($this->semaphoreId);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement