Page MenuHomeFreeBSD

D48899.id150717.diff
No OneTemporary

D48899.id150717.diff

diff --git a/share/man/man3/queue.3 b/share/man/man3/queue.3
--- a/share/man/man3/queue.3
+++ b/share/man/man3/queue.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 8, 2024
+.Dd February 8, 2025
.Dt QUEUE 3
.Os
.Sh NAME
@@ -53,6 +53,7 @@
.Nm STAILQ_CLASS_HEAD ,
.Nm STAILQ_CONCAT ,
.Nm STAILQ_EMPTY ,
+.Nm STAILQ_EMPTY_ATOMIC ,
.Nm STAILQ_ENTRY ,
.Nm STAILQ_FIRST ,
.Nm STAILQ_FOREACH ,
@@ -633,6 +634,10 @@
The macro
.Nm STAILQ_EMPTY
evaluates to true if there are no items on the tail queue.
+The
+.Nm STAILQ_EMPTY_ATOMIC
+variant has the same behavior, but can be safely used in contexts where it is
+possible that a different thread is concurrently updating the queue.
.Pp
The macro
.Nm STAILQ_ENTRY
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -396,7 +396,7 @@
STAILQ_INIT(&local_queue);
- if (!STAILQ_EMPTY(&td->td_proc->p_ktr)) {
+ if (!STAILQ_EMPTY_ATOMIC(&td->td_proc->p_ktr)) {
mtx_lock(&ktrace_mtx);
STAILQ_CONCAT(&local_queue, &td->td_proc->p_ktr);
mtx_unlock(&ktrace_mtx);
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
--- a/sys/sys/queue.h
+++ b/sys/sys/queue.h
@@ -387,6 +387,9 @@
STAILQ_FIRST(head) == NULL; \
})
+#define STAILQ_EMPTY_ATOMIC(head) \
+ (atomic_load_ptr(&(head)->stqh_first) == NULL)
+
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_FOREACH(var, head, field) \

File Metadata

Mime Type
text/plain
Expires
Fri, Jul 17, 2:18 AM (13 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35155176
Default Alt Text
D48899.id150717.diff (1 KB)

Event Timeline