Packages

  • Nette
    • Application
      • Application\Diagnostics
      • Application\Responses
      • Application\Routers
      • Application\UI
    • Caching
      • Caching\Storages
    • ComponentModel
    • Config
    • Database
      • Database\Diagnostics
      • Database\Drivers
      • Database\Reflection
      • Database\Table
    • DI
    • Diagnostics
    • Forms
      • Forms\Controls
      • Forms\Rendering
    • Http
    • Iterators
    • Latte
      • Latte\Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • Arrays
  • CriticalSection
  • Finder
  • Html
  • Json
  • LimitedScope
  • MimeTypeDetector
  • Neon
  • Paginator
  • Strings

Exceptions

  • JsonException
  • NeonException
  • RegexpException
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  * @package Nette\Utils
11:  */
12: 
13: 
14: 
15: /**
16:  * Critical sections support.
17:  *
18:  * @author     David Grudl
19:  * @package Nette\Utils
20:  */
21: final class CriticalSection
22: {
23:     /** @var array */
24:     private static $criticalSections;
25: 
26: 
27: 
28:     /**
29:      * Static class - cannot be instantiated.
30:      */
31:     final public function __construct()
32:     {
33:         throw new StaticClassException;
34:     }
35: 
36: 
37: 
38:     /**
39:      * Enters the critical section, other threads are locked out.
40:      * @return void
41:      */
42:     public static function enter()
43:     {
44:         if (self::$criticalSections) {
45:             throw new InvalidStateException('Critical section has already been entered.');
46:         }
47:         // locking on Windows causes that a file seems to be empty
48:         $handle = substr(PHP_OS, 0, 3) === 'WIN'
49:             ? @fopen(NETTE_DIR . '/lockfile', 'w')
50:             : @fopen(__FILE__, 'r'); // @ - file may not already exist
51: 
52:         if (!$handle) {
53:             throw new InvalidStateException("Unable initialize critical section.");
54:         }
55:         flock(self::$criticalSections = $handle, LOCK_EX);
56:     }
57: 
58: 
59: 
60:     /**
61:      * Leaves the critical section, other threads can now enter it.
62:      * @return void
63:      */
64:     public static function leave()
65:     {
66:         if (!self::$criticalSections) {
67:             throw new InvalidStateException('Critical section has not been initialized.');
68:         }
69:         flock(self::$criticalSections, LOCK_UN);
70:         fclose(self::$criticalSections);
71:         self::$criticalSections = NULL;
72:     }
73: 
74: }
75: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0