Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NativeResource.php « CRT « AWS « src « aws-crt-php « aws - github.com/nextcloud/3rdparty.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 528df759ffece100c8cb14ead6593a821e96a04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
namespace AWS\CRT;

use AWS\CRT\CRT as CRT;

/**
 * Base class for all native resources, tracks all outstanding resources
 * and provides basic leak checking
 */
abstract class NativeResource {
    protected static $crt = null;
    protected static $resources = [];
    protected $native = null;

    protected function __construct() {
        if (is_null(self::$crt)) {
            self::$crt = new CRT();
        }

        self::$resources[spl_object_hash($this)] = 1;
    }

    protected function acquire($handle) {
        return $this->native = $handle;
    }

    protected function release() {
        $native = $this->native;
        $this->native = null;
        return $native;
    }

    function __destruct() {
        // Should have been destroyed and released by derived resource
        assert($this->native == null);
        unset(self::$resources[spl_object_hash($this)]);
    }
}