Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • 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
  • Namespace
  • 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:  */
11: 
12: namespace Nette\Utils;
13: 
14: use Nette;
15: 
16: 
17: 
18: /**
19:  * Critical sections support.
20:  *
21:  * @author     David Grudl
22:  */
23: final class CriticalSection
24: {
25:     /** @var array */
26:     private static $criticalSections;
27: 
28: 
29: 
30:     /**
31:      * Static class - cannot be instantiated.
32:      */
33:     final public function __construct()
34:     {
35:         throw new Nette\StaticClassException;
36:     }
37: 
38: 
39: 
40:     /**
41:      * Enters the critical section, other threads are locked out.
42:      * @return void
43:      */
44:     public static function enter()
45:     {
46:         if (self::$criticalSections) {
47:             throw new Nette\InvalidStateException('Critical section has already been entered.');
48:         }
49:         // locking on Windows causes that a file seems to be empty
50:         $handle = substr(PHP_OS, 0, 3) === 'WIN'
51:             ? @fopen(NETTE_DIR . '/lockfile', 'w')
52:             : @fopen(__FILE__, 'r'); // @ - file may not already exist
53: 
54:         if (!$handle) {
55:             throw new Nette\InvalidStateException("Unable initialize critical section.");
56:         }
57:         flock(self::$criticalSections = $handle, LOCK_EX);
58:     }
59: 
60: 
61: 
62:     /**
63:      * Leaves the critical section, other threads can now enter it.
64:      * @return void
65:      */
66:     public static function leave()
67:     {
68:         if (!self::$criticalSections) {
69:             throw new Nette\InvalidStateException('Critical section has not been initialized.');
70:         }
71:         flock(self::$criticalSections, LOCK_UN);
72:         fclose(self::$criticalSections);
73:         self::$criticalSections = NULL;
74:     }
75: 
76: }
77: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0