Skip to content

Commit 10f5323

Browse files
committed
Make expire time atomic
It is checked in WebController::expireSessions(), possibly concurrently with it being updated in WebSession::setState(). Made Time ctor noexcept and made copy and move trivial to meet std::atomic requirements. While I don't expect this to have caused any real issues (expireSessions() would likely just read the old or the new version), thread sanitizer doesn't like it, and it's more correct to make it atomic.
1 parent ce14bd6 commit 10f5323

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/web/TimeUtil.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@
44

55
namespace Wt {
66

7-
Time::Time()
7+
Time::Time() noexcept
88
{
99
tp_ = std::chrono::steady_clock::now();
1010
}
1111

12+
#ifdef WT_TARGET_JAVA
1213
Time::Time(const Time &other)
1314
{
1415
tp_ = other.tp_;
1516
}
17+
#endif // WT_TARGET_JAVA
1618

1719
Time& Time::operator+= (int msec)
1820
{
1921
tp_ += std::chrono::milliseconds(msec);
2022
return *this;
2123
}
2224

25+
#ifdef WT_TARGET_JAVA
2326
Time& Time::operator= (const Time &other)
2427
{
2528
tp_ = other.tp_;
2629
return *this;
2730
}
31+
#endif
2832

2933
Time Time::operator+ (int msec) const
3034
{

src/web/TimeUtil.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ namespace Wt {
1919
class WT_API Time
2020
{
2121
public:
22-
Time(); // now
22+
Time() noexcept; // now
23+
#ifdef WT_TARGET_JAVA
2324
Time(const Time &other);
25+
#endif // WT_TARGET_JAVA
2426

2527
Time operator+ (int msec) const;
2628
Time& operator+= (int msec);
29+
30+
#ifdef WT_TARGET_JAVA
2731
Time& operator= (const Time &other);
32+
#endif
2833

2934
int operator- (const Time& other) const; // milliseconds
3035

3136
private:
3237
std::chrono::steady_clock::time_point tp_;
3338
};
3439

40+
3541
}
3642

3743
#endif // TIMEUTIL_H_

src/web/WebSession.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include "Wt/WEnvironment.h"
3535
#include "Wt/WLogger.h"
3636

37+
#ifdef WT_THREADED
38+
#include <atomic>
39+
#endif // WT_THREADED
40+
3741
namespace Wt {
3842

3943
class WebController;
@@ -118,7 +122,7 @@ class WT_API WebSession
118122
WObject *emitStackTop();
119123

120124
#ifndef WT_TARGET_JAVA
121-
const Time& expireTime() const { return expire_; }
125+
Time expireTime() const { return expire_; }
122126
#endif // WT_TARGET_JAVA
123127

124128
bool dead() { return state_ == State::Dead; }
@@ -315,8 +319,12 @@ class WT_API WebSession
315319
int deferCount_;
316320

317321
#ifndef WT_TARGET_JAVA
322+
#ifdef WT_THREADED
323+
std::atomic<Time> expire_;
324+
#else
318325
Time expire_;
319326
#endif
327+
#endif
320328

321329
#ifdef WT_BOOST_THREADS
322330
std::condition_variable recursiveEvent_, recursiveEventDone_;

0 commit comments

Comments
 (0)