From 124ee0df8f8ce0801c2e56ba978c6593da738b2d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Jan 2026 13:59:52 +1300 Subject: [PATCH] Remove redundant type locking --- src/Appwrite/GraphQL/Types.php | 54 +++++++--------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/src/Appwrite/GraphQL/Types.php b/src/Appwrite/GraphQL/Types.php index 89ff464dd8..27dda68ba2 100644 --- a/src/Appwrite/GraphQL/Types.php +++ b/src/Appwrite/GraphQL/Types.php @@ -6,79 +6,47 @@ use Appwrite\GraphQL\Types\Assoc; use Appwrite\GraphQL\Types\InputFile; use Appwrite\GraphQL\Types\Json; use GraphQL\Type\Definition\Type; -use Swoole\Lock; class Types { private static ?Json $json = null; private static ?Assoc $assoc = null; private static ?InputFile $inputFile = null; - private static ?Lock $lock = null; /** - * Get or create the shared lock for thread-safe initialization. - */ - private static function getLock(): Lock - { - if (self::$lock === null) { - self::$lock = new Lock(SWOOLE_MUTEX); - } - return self::$lock; - } - - /** - * Get the JSON type (thread-safe). + * Get the JSON type. + * + * Thread-safety note: In Swoole, each worker is a separate process with its own + * static variables. Within a worker, coroutines are cooperative and only yield + * at I/O points. Since these constructors have no I/O, the null check and + * assignment execute atomically without needing locks. */ public static function json(): Type { if (self::$json === null) { - self::getLock()->lock(); - try { - // Double-check after acquiring lock - if (self::$json === null) { - self::$json = new Json(); - } - } finally { - self::getLock()->unlock(); - } + self::$json = new Json(); } return self::$json; } /** - * Get the Assoc type (thread-safe). + * Get the Assoc type. */ public static function assoc(): Type { if (self::$assoc === null) { - self::getLock()->lock(); - try { - // Double-check after acquiring lock - if (self::$assoc === null) { - self::$assoc = new Assoc(); - } - } finally { - self::getLock()->unlock(); - } + self::$assoc = new Assoc(); } return self::$assoc; } /** - * Get the InputFile type (thread-safe). + * Get the InputFile type. */ public static function inputFile(): Type { if (self::$inputFile === null) { - self::getLock()->lock(); - try { - // Double-check after acquiring lock - if (self::$inputFile === null) { - self::$inputFile = new InputFile(); - } - } finally { - self::getLock()->unlock(); - } + self::$inputFile = new InputFile(); } return self::$inputFile; }