Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions std/experimental/logger/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ private @property Logger defaultSharedLoggerImpl() @trusted
import std.conv : emplace;
import std.stdio : stderr;

static __gshared ubyte[__traits(classInstanceSize, FileLogger)] _buffer;
static __gshared align(FileLogger.alignof) void[__traits(classInstanceSize, FileLogger)] _buffer;
Copy link
Member

@PetarKirov PetarKirov May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andralex druntime & phobos are full of such ad hoc implementations of the singleton pattern (the last being 5355) we should really try to get singleton!T merged and fix this once and for all. Do you want me to take over the singleton implementation from dlang/druntime#1710?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZombineDev that'd be great, thanks. There seem to be three kinds - thread-local, shared, and gshared.

Copy link
Member

@PetarKirov PetarKirov May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine they would work like so:

// at module level
Singleton!T instance; // thread-local
shared Singleton!T shared_instance; // shared
__gshared Singleton!T gshared_instance; // __gshared

pragma (msg, typeof(instance.get()); // T
pragma (msg, typeof(shared_instance.get()); // shared(T)
pragma (msg, typeof(gshared_instance.get()); // T

// at function/aggregate scope
/* static is implicit in the implementation*/ Singleton!T instance; // thread-local
/* static is implicit in the implementation */ shared Singleton!T shared_instance; // shared
__gshared Singleton!T gshared_instance; // __gshared

pragma (msg, typeof(instance.get()); // T
pragma (msg, typeof(shared_instance.get()); // shared(T)
pragma (msg, typeof(gshared_instance.get()); // T

I.e. overload Singleton(T)'s methods on shared-ness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZombineDev the singleton wouldn't appear at module level - that's a global. It needs to be a function returning a reference.


synchronized (stdSharedLoggerMutex)
{
Expand Down Expand Up @@ -1763,7 +1763,7 @@ private @property Logger stdThreadLocalLogImpl() @trusted
{
import std.conv : emplace;

static ubyte[__traits(classInstanceSize, StdForwardLogger)] _buffer;
static void*[(__traits(classInstanceSize, StdForwardLogger) - 1) / (void*).sizeof + 1] _buffer;

auto buffer = cast(ubyte[]) _buffer;

Expand Down