svn commit: r192421 - in user/kmacy/releng_7_2_fcs/sys: kern sys
Kip Macy
kmacy at FreeBSD.org
Wed May 20 05:39:41 UTC 2009
Author: kmacy
Date: Wed May 20 05:39:41 2009
New Revision: 192421
URL: http://svn.freebsd.org/changeset/base/192421
Log:
Add new kthread_create_pri function which allows users to pass a priority when
creating a thread
Modified:
user/kmacy/releng_7_2_fcs/sys/kern/kern_kthread.c
user/kmacy/releng_7_2_fcs/sys/sys/kthread.h
Modified: user/kmacy/releng_7_2_fcs/sys/kern/kern_kthread.c
==============================================================================
--- user/kmacy/releng_7_2_fcs/sys/kern/kern_kthread.c Wed May 20 04:26:19 2009 (r192420)
+++ user/kmacy/releng_7_2_fcs/sys/kern/kern_kthread.c Wed May 20 05:39:41 2009 (r192421)
@@ -72,12 +72,11 @@ kproc_start(udata)
* flags are flags to fork1 (in unistd.h)
* fmt and following will be *printf'd into (*newpp)->p_comm (for ps, etc.).
*/
-int
-kthread_create(void (*func)(void *), void *arg,
- struct proc **newpp, int flags, int pages, const char *fmt, ...)
+static int
+kthread_create_pri_v(void (*func)(void *), void *arg,
+ struct proc **newpp, int flags, int pages, int prio, const char *comm)
{
int error;
- va_list ap;
struct thread *td;
struct proc *p2;
@@ -101,19 +100,18 @@ kthread_create(void (*func)(void *), voi
mtx_unlock(&p2->p_sigacts->ps_mtx);
PROC_UNLOCK(p2);
- /* set up arg0 for 'ps', et al */
- va_start(ap, fmt);
- vsnprintf(p2->p_comm, sizeof(p2->p_comm), fmt, ap);
- va_end(ap);
+ memcpy(p2->p_comm, comm, sizeof(p2->p_comm));
+ td = FIRST_THREAD_IN_PROC(p2);
+ memcpy(td->td_name, comm, sizeof(td->td_name));
/* call the processes' main()... */
- td = FIRST_THREAD_IN_PROC(p2);
cpu_set_fork_handler(td, func, arg);
TD_SET_CAN_RUN(td);
/* Delay putting it on the run queue until now. */
if (!(flags & RFSTOPPED)) {
thread_lock(td);
+ sched_prio(td, prio);
sched_add(td, SRQ_BORING);
thread_unlock(td);
}
@@ -121,6 +119,35 @@ kthread_create(void (*func)(void *), voi
return 0;
}
+int
+kthread_create_pri(void (*func)(void *), void *arg,
+ struct proc **newpp, int flags, int pages, int prio, const char *fmt, ...)
+{
+ va_list ap;
+ char p_comm[MAXCOMLEN + 1]; /* (b) Process name. XXX */
+
+ /* set up arg0 for 'ps', et al */
+ va_start(ap, fmt);
+ vsnprintf(p_comm, sizeof(p_comm), fmt, ap);
+ va_end(ap);
+
+ return (kthread_create_pri_v(func, arg, newpp, flags, pages, prio, p_comm));
+}
+
+int
+kthread_create(void (*func)(void *), void *arg,
+ struct proc **newpp, int flags, int pages, const char *fmt, ...)
+{
+ va_list ap;
+ char p_comm[MAXCOMLEN + 1]; /* (b) Process name. XXX */
+
+ /* set up arg0 for 'ps', et al */
+ va_start(ap, fmt);
+ vsnprintf(p_comm, sizeof(p_comm), fmt, ap);
+ va_end(ap);
+ return (kthread_create_pri_v(func, arg, newpp, flags, pages, 0, p_comm));
+}
+
void
kthread_exit(int ecode)
{
Modified: user/kmacy/releng_7_2_fcs/sys/sys/kthread.h
==============================================================================
--- user/kmacy/releng_7_2_fcs/sys/sys/kthread.h Wed May 20 04:26:19 2009 (r192420)
+++ user/kmacy/releng_7_2_fcs/sys/sys/kthread.h Wed May 20 05:39:41 2009 (r192421)
@@ -46,6 +46,8 @@ void kproc_shutdown(void *, int);
void kproc_start(const void *);
int kthread_create(void (*)(void *), void *, struct proc **,
int flags, int pages, const char *, ...) __printflike(6, 7);
+int kthread_create_pri(void (*)(void *), void *, struct proc **,
+ int flags, int pages, int prio, const char *, ...) __printflike(7, 8);
void kthread_exit(int) __dead2;
int kthread_resume(struct proc *); /* XXXKSE */
int kthread_suspend(struct proc *, int); /* XXXKSE */
More information about the svn-src-user
mailing list