PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
SleeperNotifier.php
1<?php
2
3/*
4 * This file is part of Snooze <https://github.com/pmmp/Snooze>
5 * Copyright (c) 2018-2023 PMMP Team
6 *
7 * Snooze is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\snooze;
16
17use pmmp\thread\ThreadSafeArray;
18
23final class SleeperNotifier{
24
31 public function __construct(
32 private readonly ThreadSafeArray $sharedObject,
33 private readonly int $notifierId
34 ){}
35
39 final public function wakeupSleeper() : void{
40 $shared = $this->sharedObject;
41 $sleeperId = $this->notifierId;
42 $shared->synchronized(function() use ($shared, $sleeperId) : void{
43 if(!isset($shared[$sleeperId])){
44 $shared[$sleeperId] = $sleeperId;
45 $shared->notify();
46 }
47 });
48 }
49}