From be54f4a0b6f160f8a2b0b9e9c988fb5251f70a97 Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Mon, 12 Mar 2018 00:56:41 -0400 Subject: [PATCH] Wrap thread local in function for Cygwin Fixes #1826. See #1352 for a previous instance of a similar change. --- src/libstore/download.hh | 2 +- src/libutil/logging.cc | 11 ++++++++++- src/libutil/logging.hh | 11 ++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libstore/download.hh b/src/libstore/download.hh index d9d525d4e..0b8d29b21 100644 --- a/src/libstore/download.hh +++ b/src/libstore/download.hh @@ -22,7 +22,7 @@ struct DownloadRequest std::string mimeType; DownloadRequest(const std::string & uri) - : uri(uri), parentAct(curActivity) { } + : uri(uri), parentAct(getCurActivity()) { } }; struct DownloadResult diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index c1cff5cf9..e860b27d3 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -6,7 +6,16 @@ namespace nix { -thread_local ActivityId curActivity = 0; +static thread_local ActivityId curActivity = 0; + +ActivityId getCurActivity() +{ + return curActivity; +} +void setCurActivity(const ActivityId activityId) +{ + curActivity = activityId; +} Logger * logger = makeDefaultLogger(); diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index ca768d555..678703102 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -77,7 +77,8 @@ public: virtual void result(ActivityId act, ResultType type, const Fields & fields) { }; }; -extern thread_local ActivityId curActivity; +ActivityId getCurActivity(); +void setCurActivity(const ActivityId activityId); struct Activity { @@ -86,10 +87,10 @@ struct Activity const ActivityId id; Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s = "", - const Logger::Fields & fields = {}, ActivityId parent = curActivity); + const Logger::Fields & fields = {}, ActivityId parent = getCurActivity()); Activity(Logger & logger, ActivityType type, - const Logger::Fields & fields = {}, ActivityId parent = curActivity) + const Logger::Fields & fields = {}, ActivityId parent = getCurActivity()) : Activity(logger, lvlError, type, "", fields, parent) { }; Activity(const Activity & act) = delete; @@ -121,8 +122,8 @@ struct Activity struct PushActivity { const ActivityId prevAct; - PushActivity(ActivityId act) : prevAct(curActivity) { curActivity = act; } - ~PushActivity() { curActivity = prevAct; } + PushActivity(ActivityId act) : prevAct(getCurActivity()) { setCurActivity(act); } + ~PushActivity() { setCurActivity(prevAct); } }; extern Logger * logger;