mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibC: Make gettid() cache the thread ID in thread-local-storage
This makes gettid() very cheap, compared to the cost of having to do a syscall every time.
This commit is contained in:
parent
ec5091fa7d
commit
161cb89e87
1 changed files with 5 additions and 2 deletions
|
@ -538,10 +538,13 @@ int ftruncate(int fd, off_t length)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__thread int t_cached_tid = -1;
|
||||||
|
|
||||||
int gettid()
|
int gettid()
|
||||||
{
|
{
|
||||||
int rc = syscall(SC_gettid);
|
if (t_cached_tid == -1)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
t_cached_tid = syscall(SC_gettid);
|
||||||
|
return t_cached_tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int donate(int tid)
|
int donate(int tid)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue