Kill NamespaceCompat. Nothing, anywhere (not even comments, since r70692) still refer...
[mediawiki.git] / includes / PoolCounter.php
blob2564fbc67f02a5287f321a9d1db6055650f75cb3
1 <?php
3 abstract class PoolCounter {
4 public static function factory( $type, $key ) {
5 global $wgPoolCounterConf;
6 if ( !isset( $wgPoolCounterConf[$type] ) ) {
7 return new PoolCounter_Stub;
9 $conf = $wgPoolCounterConf[$type];
10 $class = $conf['class'];
11 return new $class( $conf, $type, $key );
14 abstract public function acquire();
15 abstract public function release();
16 abstract public function wait();
18 public function executeProtected( $mainCallback, $dirtyCallback = false ) {
19 $status = $this->acquire();
20 if ( !$status->isOK() ) {
21 return $status;
23 if ( !empty( $status->value['overload'] ) ) {
24 # Overloaded. Try a dirty cache entry.
25 if ( $dirtyCallback ) {
26 if ( call_user_func( $dirtyCallback ) ) {
27 $this->release();
28 return Status::newGood();
32 # Wait for a thread
33 $status = $this->wait();
34 if ( !$status->isOK() ) {
35 $this->release();
36 return $status;
39 # Call the main callback
40 call_user_func( $mainCallback );
41 return $this->release();
45 class PoolCounter_Stub extends PoolCounter {
46 public function acquire() {
47 return Status::newGood();
50 public function release() {
51 return Status::newGood();
54 public function wait() {
55 return Status::newGood();
58 public function executeProtected( $mainCallback, $dirtyCallback = false ) {
59 call_user_func( $mainCallback );
60 return Status::newGood();