Clarify shared logging state and owning handle types
This commit is contained in:
1 parent
761bd66793
commit
851caef706
2 files changed
+94
-95
No files matched your search
@@ -266,7 +266,7 @@ usability in multithreaded environments. The design centers on two key types:
|
||||
#### LogService (Value Type)
|
||||
```nim
|
||||
type LogService* = object
|
||||
global: GlobalLogService
|
||||
shared: ptr SharedLogServiceState
|
||||
```
|
||||
|
||||
The *LogService* object is intended to support uses cases such as:
|
||||
@@ -288,7 +288,7 @@ The *LogService* object is intended to support uses cases such as:
|
||||
#### ThreadLocalLogService (Reference Type)
|
||||
```nim
|
||||
type ThreadLocalLogService* = ref object
|
||||
shared: LogService
|
||||
serviceHandle: LogService
|
||||
configVersion: int
|
||||
appenders: seq[LogAppender]
|
||||
thresholds: TableRef[string, Level]
|
||||
@@ -321,7 +321,7 @@ during regular operation and support both the configuration functions of
|
||||
> *ThreadLocalLogService* objects should **never** be shared outside the
|
||||
> context of the thread in which they were initialized.
|
||||
|
||||
#### GlobalLogService (Internal)
|
||||
#### SharedLogServiceState (Internal)
|
||||
|
||||
Under the hood *LogService* holds a pointer to a manually allocated shared
|
||||
control block that serves as the single source of truth for logging
|
||||
@@ -376,12 +376,12 @@ changes:
|
||||
```nim
|
||||
proc ensureFreshness*(ls: ThreadLocalLogService) =
|
||||
# Cheap atomic check first
|
||||
if ls.configVersion == ls.global.configVersion.load():
|
||||
if ls.configVersion == ls.shared.configVersion.load():
|
||||
return # No changes, return immediately
|
||||
|
||||
# Only acquire lock and copy if versions differ
|
||||
withLock ls.global.lock:
|
||||
ls.configVersion = ls.global.configVersion.load
|
||||
withLock ls.shared.lock:
|
||||
ls.configVersion = ls.shared.configVersion.load
|
||||
# Sync state...
|
||||
```
|
||||
|
||||
|
||||
Reference in new issue
Block a user