Coverage for src/bluetooth_sig/registry/base.py: 100%
16 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
1"""Base registry class for Bluetooth SIG registries."""
3from __future__ import annotations
5import threading
6from typing import Generic, TypeVar
8T = TypeVar("T")
11class BaseRegistry(Generic[T]):
12 """Base class for Bluetooth SIG registries with singleton pattern and thread safety."""
14 _instance: BaseRegistry[T] | None = None
15 _lock = threading.RLock()
17 def __init__(self) -> None:
18 """Initialize the registry."""
19 self._lock = threading.RLock()
21 @classmethod
22 def get_instance(cls) -> BaseRegistry[T]:
23 """Get the singleton instance of the registry."""
24 if cls._instance is None:
25 with cls._lock:
26 if cls._instance is None:
27 cls._instance = cls()
28 return cls._instance