Date: Mon, 23 Jul 2012 09:34:19 +0000 (UTC) From: David Xu <davidxu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r238715 - stable/8/lib/libthr/thread Message-ID: <201207230934.q6N9YJPv089012@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: davidxu Date: Mon Jul 23 09:34:19 2012 New Revision: 238715 URL: http://svn.freebsd.org/changeset/base/238715 Log: Merge r238637,r238640,r238641,r238642: ------------------------------------------------------------------------ r238637 | davidxu | 2012-07-20 09:56:14 +0800 (Fri, 20 Jul 2012) | 6 lines Don't forget to release a thread reference count, replace _thr_ref_add() with _thr_find_thread(), so reference count is no longer needed. ------------------------------------------------------------------------ r238640 | davidxu | 2012-07-20 11:00:41 +0800 (Fri, 20 Jul 2012) | 2 lines Eliminate duplicated code. ------------------------------------------------------------------------ r238641 | davidxu | 2012-07-20 11:16:52 +0800 (Fri, 20 Jul 2012) | 2 lines Eliminate duplicated code. ------------------------------------------------------------------------ r238642 | davidxu | 2012-07-20 11:22:17 +0800 (Fri, 20 Jul 2012) | 2 lines Don't assign same value. Modified: stable/8/lib/libthr/thread/thr_setprio.c (contents, props changed) stable/8/lib/libthr/thread/thr_setschedparam.c (contents, props changed) Modified: stable/8/lib/libthr/thread/thr_setprio.c ============================================================================== --- stable/8/lib/libthr/thread/thr_setprio.c Mon Jul 23 09:33:31 2012 (r238714) +++ stable/8/lib/libthr/thread/thr_setprio.c Mon Jul 23 09:34:19 2012 (r238715) @@ -45,38 +45,22 @@ _pthread_setprio(pthread_t pthread, int int ret; param.sched_priority = prio; - if (pthread == curthread) { + if (pthread == curthread) THR_LOCK(curthread); - if (curthread->attr.sched_policy == SCHED_OTHER || - curthread->attr.prio == prio) { - curthread->attr.prio = prio; - ret = 0; - } else { - ret = _thr_setscheduler(curthread->tid, - curthread->attr.sched_policy, ¶m); - if (ret == -1) - ret = errno; - else - curthread->attr.prio = prio; - } - THR_UNLOCK(curthread); - } else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) - == 0) { - THR_THREAD_LOCK(curthread, pthread); - if (pthread->attr.sched_policy == SCHED_OTHER || - pthread->attr.prio == prio) { + else if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0))) + return (ret); + if (pthread->attr.sched_policy == SCHED_OTHER || + pthread->attr.prio == prio) { + pthread->attr.prio = prio; + ret = 0; + } else { + ret = _thr_setscheduler(pthread->tid, + pthread->attr.sched_policy, ¶m); + if (ret == -1) + ret = errno; + else pthread->attr.prio = prio; - ret = 0; - } else { - ret = _thr_setscheduler(pthread->tid, - curthread->attr.sched_policy, ¶m); - if (ret == -1) - ret = errno; - else - pthread->attr.prio = prio; - } - THR_THREAD_UNLOCK(curthread, pthread); - _thr_ref_delete(curthread, pthread); } + THR_THREAD_UNLOCK(curthread, pthread); return (ret); } Modified: stable/8/lib/libthr/thread/thr_setschedparam.c ============================================================================== --- stable/8/lib/libthr/thread/thr_setschedparam.c Mon Jul 23 09:33:31 2012 (r238714) +++ stable/8/lib/libthr/thread/thr_setschedparam.c Mon Jul 23 09:34:19 2012 (r238715) @@ -53,42 +53,25 @@ _pthread_setschedparam(pthread_t pthread struct pthread *curthread = _get_curthread(); int ret; - if (pthread == curthread) { + if (pthread == curthread) THR_LOCK(curthread); - if (curthread->attr.sched_policy == policy && - (policy == SCHED_OTHER || - curthread->attr.prio == param->sched_priority)) { - pthread->attr.prio = param->sched_priority; - THR_UNLOCK(curthread); - return (0); - } - ret = _thr_setscheduler(curthread->tid, policy, param); - if (ret == -1) - ret = errno; - else { - curthread->attr.sched_policy = policy; - curthread->attr.prio = param->sched_priority; - } - THR_UNLOCK(curthread); - } else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) - == 0) { - THR_THREAD_LOCK(curthread, pthread); - if (pthread->attr.sched_policy == policy && - (policy == SCHED_OTHER || - pthread->attr.prio == param->sched_priority)) { - pthread->attr.prio = param->sched_priority; - THR_THREAD_UNLOCK(curthread, pthread); - return (0); - } - ret = _thr_setscheduler(pthread->tid, policy, param); - if (ret == -1) - ret = errno; - else { - pthread->attr.sched_policy = policy; - pthread->attr.prio = param->sched_priority; - } + else if ((ret = _thr_find_thread(curthread, pthread, + /*include dead*/0)) != 0) + return (ret); + if (pthread->attr.sched_policy == policy && + (policy == SCHED_OTHER || + pthread->attr.prio == param->sched_priority)) { + pthread->attr.prio = param->sched_priority; THR_THREAD_UNLOCK(curthread, pthread); - _thr_ref_delete(curthread, pthread); + return (0); } + ret = _thr_setscheduler(pthread->tid, policy, param); + if (ret == -1) + ret = errno; + else { + pthread->attr.sched_policy = policy; + pthread->attr.prio = param->sched_priority; + } + THR_THREAD_UNLOCK(curthread, pthread); return (ret); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207230934.q6N9YJPv089012>