mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Log: Refine log context, use const
This commit is contained in:
parent
254529d946
commit
0a057a0427
4 changed files with 16 additions and 16 deletions
|
@ -93,10 +93,10 @@ public:
|
||||||
// @remark We do not set to current thread, user should do this.
|
// @remark We do not set to current thread, user should do this.
|
||||||
virtual SrsContextId generate_id() = 0;
|
virtual SrsContextId generate_id() = 0;
|
||||||
// Get the context id of current thread.
|
// 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.
|
// Set the context id of current thread.
|
||||||
// @return the previous context id.
|
// @return the current context id.
|
||||||
virtual SrsContextId set_id(SrsContextId v) = 0;
|
virtual const SrsContextId& set_id(const SrsContextId& v) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// @global User must provides a log object
|
// @global User must provides a log object
|
||||||
|
|
|
@ -49,22 +49,22 @@ SrsContextId SrsThreadContext::generate_id()
|
||||||
return cid;
|
return cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsContextId SrsThreadContext::get_id()
|
const SrsContextId& SrsThreadContext::get_id()
|
||||||
{
|
{
|
||||||
return cache[srs_thread_self()];
|
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();
|
srs_thread_t self = srs_thread_self();
|
||||||
|
|
||||||
SrsContextId ov;
|
if (cache.find(self) == cache.end()) {
|
||||||
if (cache.find(self) != cache.end()) {
|
cache[self] = v;
|
||||||
ov = cache[self];
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SrsContextId& ov = cache[self];
|
||||||
cache[self] = v;
|
cache[self] = v;
|
||||||
|
|
||||||
return ov;
|
return ov;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ public:
|
||||||
virtual ~SrsThreadContext();
|
virtual ~SrsThreadContext();
|
||||||
public:
|
public:
|
||||||
virtual SrsContextId generate_id();
|
virtual SrsContextId generate_id();
|
||||||
virtual SrsContextId get_id();
|
virtual const SrsContextId& get_id();
|
||||||
virtual SrsContextId set_id(SrsContextId v);
|
virtual const SrsContextId& set_id(const SrsContextId& v);
|
||||||
public:
|
public:
|
||||||
virtual void clear_cid();
|
virtual void clear_cid();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1382,12 +1382,12 @@ VOID TEST(TCPServerTest, ContextUtility)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsThreadContext ctx;
|
SrsThreadContext ctx;
|
||||||
|
|
||||||
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
|
EXPECT_TRUE(!ctx.set_id(SrsContextId("100")).compare(SrsContextId("100")));
|
||||||
EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("100")));
|
EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("1000")));
|
||||||
EXPECT_TRUE(!ctx.get_id().compare(SrsContextId("1000")));
|
EXPECT_TRUE(!ctx.get_id().compare(SrsContextId("1000")));
|
||||||
|
|
||||||
ctx.clear_cid();
|
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;
|
int base_size = 0;
|
||||||
|
|
Loading…
Reference in a new issue