<commit_before><?php
/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/12
 * Time: 20:52
 */

namespace Jenner\SimpleFork\IPC;


class Semaphore
{
    /**
     * @param $key
     * @return Semaphore
     */
    public static function create($key)
    {
        return new Semaphore($key);
    }

    /**
     * @var
     */
    private $lock_id;
    /**
     * @var bool
     */
    private $locked = false;

    /**
     * @param $key
     * @throws \Exception
     */
    private function __construct($key)
    {
        if ( ($this->lock_id = sem_get($this->_stringToSemKey($key))) === false)
        {
            throw new \RuntimeException('Cannot create semaphore for key: ' . $key);
        }
    }

    /**
     * @throws \Exception
     */
    public function __destruct()
    {
        $this->release();
    }


    /**
     * @throws \Exception
     */
    public function acquire()
    {
        if (!sem_acquire($this->lock_id))
        {
            throw new \RuntimeException('Cannot acquire semaphore: ' . $this->lock_id);
        }
        $this->lock_id = true;
    }

    /**
     * @throws \Exception
     */
    public function release()
    {
        if ($this->locked)
        {
            if (!sem_release($this->lock_id))
            {<commit_msg>add shared memory test<commit_after><?php
/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/12
 * Time: 20:52
 */

namespace Jenner\SimpleFork\IPC;


class Semaphore
{
    /**
     * @param $key
     * @return Semaphore
     */
    public static function create($key)
    {
        return new Semaphore($key);
    }

    /**
     * @var
     */
    private $lock_id;
    /**
     * @var bool
     */
    private $locked = false;

    /**
     * @param $key
     * @throws \RuntimeException
     */
    private function __construct($key)
    {
        if ( ($this->lock_id = sem_get($this->_stringToSemKey($key))) === false)
        {
            throw new \RuntimeException('Cannot create semaphore for key: ' . $key);
        }
    }

    /**
     * @throws \RuntimeException
     */
    public function __destruct()
    {
        $this->release();
    }


    /**
     * @throws \Exception
     */
    public function acquire()
    {
        if (!sem_acquire($this->lock_id))
        {
            throw new \RuntimeException('Cannot acquire semaphore: ' . $this->lock_id);
        }
        $this->locked = true;
    }

    /**
     * @throws \RuntimeException
     */
    public function release()
    {
        if ($this->locked)
        {
            if (!sem_release($this->lock_id))
            {
{'fraction_non_alphanumeric': 0.14697960754136205, 'fraction_numerical': 0.008464794151596768, 'mean_word_length': 1.6209677419354838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5134910', 'n_tokens_mistral': 841, 'n_tokens_neox': 810, 'n_words': 167}