Merge pull request #1965 from masaeedu/master

Wrap thread local in function for Cygwin
This commit is contained in:
Eelco Dolstra 2018-03-15 14:56:21 +01:00 committed by GitHub
commit 7b8914825a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -22,7 +22,7 @@ struct DownloadRequest
std::string mimeType; std::string mimeType;
DownloadRequest(const std::string & uri) DownloadRequest(const std::string & uri)
: uri(uri), parentAct(curActivity) { } : uri(uri), parentAct(getCurActivity()) { }
}; };
struct DownloadResult struct DownloadResult

View file

@ -6,7 +6,16 @@
namespace nix { 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(); Logger * logger = makeDefaultLogger();

View file

@ -77,7 +77,8 @@ public:
virtual void result(ActivityId act, ResultType type, const Fields & fields) { }; virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
}; };
extern thread_local ActivityId curActivity; ActivityId getCurActivity();
void setCurActivity(const ActivityId activityId);
struct Activity struct Activity
{ {
@ -86,10 +87,10 @@ struct Activity
const ActivityId id; const ActivityId id;
Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s = "", 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, 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(logger, lvlError, type, "", fields, parent) { };
Activity(const Activity & act) = delete; Activity(const Activity & act) = delete;
@ -121,8 +122,8 @@ struct Activity
struct PushActivity struct PushActivity
{ {
const ActivityId prevAct; const ActivityId prevAct;
PushActivity(ActivityId act) : prevAct(curActivity) { curActivity = act; } PushActivity(ActivityId act) : prevAct(getCurActivity()) { setCurActivity(act); }
~PushActivity() { curActivity = prevAct; } ~PushActivity() { setCurActivity(prevAct); }
}; };
extern Logger * logger; extern Logger * logger;