Log: Refine log context, use const

pull/1908/head
winlin 5 years ago
parent 254529d946
commit 0a057a0427

@ -93,10 +93,10 @@ public:
// @remark We do not set to current thread, user should do this.
virtual SrsContextId generate_id() = 0;
// Get the context id of current thread.
virtual SrsContextId get_id() = 0;
virtual const SrsContextId& get_id() = 0;
// Set the context id of current thread.
// @return the previous context id.
virtual SrsContextId set_id(SrsContextId v) = 0;
// @return the current context id.
virtual const SrsContextId& set_id(const SrsContextId& v) = 0;
};
// @global User must provides a log object

@ -49,22 +49,22 @@ SrsContextId SrsThreadContext::generate_id()
return cid;
}
SrsContextId SrsThreadContext::get_id()
const SrsContextId& SrsThreadContext::get_id()
{
return cache[srs_thread_self()];
}
SrsContextId SrsThreadContext::set_id(SrsContextId v)
const SrsContextId& SrsThreadContext::set_id(const SrsContextId& v)
{
srs_thread_t self = srs_thread_self();
SrsContextId ov;
if (cache.find(self) != cache.end()) {
ov = cache[self];
if (cache.find(self) == cache.end()) {
cache[self] = v;
return v;
}
const SrsContextId& ov = cache[self];
cache[self] = v;
return ov;
}

@ -43,8 +43,8 @@ public:
virtual ~SrsThreadContext();
public:
virtual SrsContextId generate_id();
virtual SrsContextId get_id();
virtual SrsContextId set_id(SrsContextId v);
virtual const SrsContextId& get_id();
virtual const SrsContextId& set_id(const SrsContextId& v);
public:
virtual void clear_cid();
};

@ -1382,12 +1382,12 @@ VOID TEST(TCPServerTest, ContextUtility)
if (true) {
SrsThreadContext ctx;
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("100")));
EXPECT_TRUE(!ctx.set_id(SrsContextId("100")).compare(SrsContextId("100")));
EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("1000")));
EXPECT_TRUE(!ctx.get_id().compare(SrsContextId("1000")));
ctx.clear_cid();
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
EXPECT_TRUE(!ctx.set_id(SrsContextId("100")).compare(SrsContextId("100")));
}
int base_size = 0;

Loading…
Cancel
Save