aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include/linux/sched.h
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2017-03-17 15:40:24 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2017-03-17 15:40:24 +0000
commita0699ebf77fd50aec9504a4f93e303b90af6d1d7 (patch)
tree5d79e099c578ce58c8438c027bd909d433275e31 /sys/compat/linuxkpi/common/include/linux/sched.h
parent08a49957b3f06926744987207d542efa2631394d (diff)
downloadsrc-a0699ebf77fd50aec9504a4f93e303b90af6d1d7.tar.gz
src-a0699ebf77fd50aec9504a4f93e303b90af6d1d7.zip
Implement get_pid_task(), pid_task() and some other PID helper
functions in the LinuxKPI. Add a usage atomic to the task_struct structure to facilitate refcounting the task structure when returned from get_pid_task(). The get_task_struct() and put_task_struct() function is used to manage atomic refcounting. After this change the task_struct should only be freed through put_task_struct(). Obtained from: kmacy @ MFC after: 1 week Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=315457
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/sched.h')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sched.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h
index 3ea479d2b85d..4439fc00c092 100644
--- a/sys/compat/linuxkpi/common/include/linux/sched.h
+++ b/sys/compat/linuxkpi/common/include/linux/sched.h
@@ -38,7 +38,9 @@
#include <sys/sleepqueue.h>
#include <linux/types.h>
+#include <linux/compat.h>
#include <linux/completion.h>
+#include <linux/pid.h>
#include <linux/slab.h>
#include <linux/mm_types.h>
@@ -59,9 +61,10 @@ struct task_struct {
linux_task_fn_t *task_fn;
void *task_data;
int task_ret;
+ atomic_t usage;
int state;
atomic_t kthread_flags;
- pid_t pid;
+ pid_t pid; /* BSD thread ID */
const char *comm;
void *bsd_ioctl_data;
unsigned bsd_ioctl_len;
@@ -71,16 +74,30 @@ struct task_struct {
#define current ((struct task_struct *)curthread->td_lkpi_task)
-#define task_pid(task) ((task)->task_thread->td_proc->p_pid)
-#define task_pid_nr(task) ((task)->task_thread->td_tid)
-#define get_pid(x) (x)
-#define put_pid(x)
+#define task_pid_group_leader(task) \
+ FIRST_THREAD_IN_PROC((task)->task_thread->td_proc)->td_tid
+#define task_pid(task) ((task)->pid)
+#define task_pid_nr(task) ((task)->pid)
+#define get_pid(x) (x)
+#define put_pid(x) do { } while (0)
#define current_euid() (curthread->td_ucred->cr_uid)
#define set_current_state(x) \
atomic_store_rel_int((volatile int *)&current->state, (x))
#define __set_current_state(x) current->state = (x)
+static inline void
+get_task_struct(struct task_struct *task)
+{
+ atomic_inc(&task->usage);
+}
+
+static inline void
+put_task_struct(struct task_struct *task)
+{
+ if (atomic_dec_and_test(&task->usage))
+ linux_free_current(task);
+}
#define schedule() \
do { \