On Thu, Jun 30, 2016 at 12:22 PM, Justin Cinkelj <[email protected]> wrote:
> There is no need to reject non-zero pid/tid if it is equal to current tid. > The pid 0 means current tid anyway. > > Signed-off-by: Justin Cinkelj <[email protected]> > --- > libc/pthread.cc | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/libc/pthread.cc b/libc/pthread.cc > index d59fa37..ad094fc 100644 > --- a/libc/pthread.cc > +++ b/libc/pthread.cc > @@ -971,7 +971,10 @@ int pthread_setaffinity_np(pthread_t thread, size_t > cpusetsize, > int sched_setaffinity(pid_t pid, size_t cpusetsize, > cpu_set_t *cpuset) > { > - if (pid != 0) { > + int self_tid; > + sched::thread &t = pthread::from_libc(pthread_self())->_thread; > + self_tid = t.id(); > Looks good to me, but one nitpick: would be shorter to just have: sched::thread::current()->id(); (it's so short, you don't even need to save it in a variable) We even have gettid() doing this in linux.cc but it's not exposed in any header file (probably should...). Other versions of Unix (but not Linux) have a function called pthread_getthreadid_np return this id. But sched::thread::current()->id() is also pretty short :-) > + if (pid != 0 && pid != self_tid) { > WARN_STUBBED(); > return EINVAL; > } > @@ -1029,7 +1032,10 @@ int pthread_attr_getaffinity_np(const > pthread_attr_t *attr, size_t cpusetsize, > int sched_getaffinity(pid_t pid, size_t cpusetsize, > cpu_set_t *cpuset) > { > - if (pid != 0) { > + int self_tid; > + sched::thread &t = pthread::from_libc(pthread_self())->_thread; > + self_tid = t.id(); > + if (pid != 0 && pid != self_tid) { > WARN_STUBBED(); > return EINVAL; > } > -- > 2.5.0 > > -- > You received this message because you are subscribed to the Google Groups > "OSv Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
