for_each_process_thread() is better, from 6.6, than
the older do_each|while_each_thread() macros
This commit is contained in:
@@ -80,7 +80,13 @@ static int showthrds_rcu(void)
|
||||
* the _rcu list-mutation primitives such as list_add_rcu() as long as it's
|
||||
* guarded by rcu_read_lock(). ...'
|
||||
*/
|
||||
|
||||
/* Commit # 5ffd2c37cb7a53d520 ... */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
do_each_thread(g, t) { /* 'g' : process ptr; 't': thread ptr */
|
||||
#else
|
||||
for_each_process_thread(g, t) { /* 'g' : process ptr; 't': thread ptr */
|
||||
#endif
|
||||
g_rcu = rcu_dereference(g);
|
||||
t_rcu = rcu_dereference(t);
|
||||
|
||||
@@ -121,7 +127,11 @@ static int showthrds_rcu(void)
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
put_task_struct(t_rcu); /* release reference to the task struct */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
} while_each_thread(g, t);
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
rcu_read_unlock(); /* This ends the RCU read-side critical section */
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,12 @@ static int showthrds_buggy(void)
|
||||
rcu_read_lock(); /* This triggers off an RCU read-side critical section; ensure
|
||||
* you are non-blocking within it! */
|
||||
#endif
|
||||
/* Commit # 5ffd2c37cb7a53d520 ... */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
do_each_thread(g, t) { /* 'g' : process ptr; 't': thread ptr */
|
||||
#else
|
||||
for_each_process_thread(g, t) { /* 'g' : process ptr; 't': thread ptr */
|
||||
#endif
|
||||
get_task_struct(t); /* take a reference to the task struct */
|
||||
task_lock(t);
|
||||
|
||||
@@ -107,7 +112,11 @@ static int showthrds_buggy(void)
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
task_unlock(t);
|
||||
put_task_struct(t); /* release reference to the task struct */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
} while_each_thread(g, t);
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
/* <same as above, reg the RCU synchronization for the task list> */
|
||||
rcu_read_unlock();
|
||||
|
||||
@@ -88,7 +88,18 @@ static int showthrds(void)
|
||||
* Worry not, you'll learn several approaches to kernel synchronization in
|
||||
* the book's last two chapters.
|
||||
*/
|
||||
do_each_thread(p, t) { /* 'p' : process ptr; 't': thread ptr */
|
||||
|
||||
/*
|
||||
* FYI, from 6.6, the do_ach_thread()/while_each_thread() style macros have been
|
||||
* removed in favor of the simpler and more readable for_each_process_thread()
|
||||
* macro.
|
||||
* Commit # 5ffd2c37cb7a53d520...
|
||||
*/
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
do_each_thread(p, t) { /* 'p' : process ptr; 't': thread ptr */
|
||||
#else
|
||||
for_each_process_thread(p, t) { /* 'p' : process ptr; 't': thread ptr */
|
||||
#endif
|
||||
get_task_struct(t); /* take a reference to the task struct */
|
||||
task_lock(t);
|
||||
|
||||
@@ -129,7 +140,11 @@ static int showthrds(void)
|
||||
|
||||
task_unlock(t);
|
||||
put_task_struct(t); /* release reference to the task struct */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
|
||||
} while_each_thread(p, t);
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user