4 ms·
This is exactly how the list implementation in the Linux kernel works [1]. I've extracted this header file and used it in user-space before, too. The cool trick
by eatbitseveryday 8y ago
This is exactly how the list implementation in the Linux kernel works [1]. I've extracted this header file and used it in user-space before, too. The cool trick is in calculating an offset to the start of the struct containing the link.
But I do not think this trick or list implementation is newly introduced in Wayland. It existed at least as far back as kernel 2.6.11 [2].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h?h=v5.0-rc8 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
[2] https://elixir.bootlin.com/linux/v2.6.11/source/include/linux/list.h https://elixir.bootlin.com/linux/v2.6.11/source/include/linu...
- fmela 8y agoI've seen this same trick done with macros in BSD kernel code from the 80s!
- electrum 8y agoHere's the code from FreeBSD: https://github.com/freebsd/freebsd/blob/master/sys/sys/queue.h https://github.com/freebsd/freebsd/blob/master/sys/sys/queue...
- deleted 8y ago[deleted]
- eps 8y agoThis is an exceedingly common way of using containers in C, because how fast and predictable it is during the run-time. It also allows putting a single data item into multiple containers like that. It's used pretty much in every OS kernel, Windows included.
- buserror 8y agoI've been using queue.h from bsd for as long as I can remember. It's slightly different syntax, but it's available on linux, from userland, and is not GPL... Note that the one that ships in linux is pretty simple, the one that is in BSD is a lot more complete.