Skip to content

Commit

Permalink
Add an implementation note about concurrent loggers. Fixes #176.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jul 27, 2024
1 parent b0cf34a commit 5842c3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions source/vibe/core/connectionpool.d
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,12 @@ struct LockedConnection(Connection) {

~this()
{
import core.memory : GC;

debug assert(m_magic == 0xB1345AC2, "LockedConnection value corrupted.");
if (!!m_conn) {
if (GC.inFinalizer) onInvalidMemoryOperationError();

auto plc = m_conn in m_pool.m_lockCount;
assert(plc !is null);
assert(*plc != 0);
Expand All @@ -291,6 +295,8 @@ struct LockedConnection(Connection) {
alias __conn this;
}

private extern(C) void onInvalidMemoryOperationError() @safe nothrow;

///
unittest {
int id = 0;
Expand Down
19 changes: 18 additions & 1 deletion source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,24 @@ struct LogLine {
string text; /// Legacy field used in `Logger.log`
}

/// Abstract base class for all loggers
/** Abstract base class for all loggers
Concurrency_requirements:
Classes derived from `Logger` must be implemented in a thread-safe way.
Although the methods of `Logger` are not annotated with `shared` due to
historic reasons, they should be treated as if they were.
Also, none of the methods must, explicitly or implicitly, yield
execution (e.g. by calling `vibe.core.yield` or performing vibe.d based
I/O or wait operations). In cases where a logger needs to perform
blocking I/O that may degrade performance of the calling thread, for
example by sending over the network, a separate writer thread should be
used in conjunction with a queue. The synchronization of this queue must
use classical synchronization primitives, such as `core.sync.Mutex`,
instead of the ones in `vibe.core.sync`. See `SyslogLogger` for an
example of such an implementation.
*/
class Logger {
LogLevel minLevel = LogLevel.min;

Expand Down

0 comments on commit 5842c3d

Please sign in to comment.