Object-oriented design patterns in the kernel, part 1
Posted Jun 3, 2011 9:07 UTC (Fri) by jengelh (subscriber, #33263)
[Link]
container_of is e.g. used for linked lists, where it merely gives the surrounding actual object to the linked list head, in other words, it is used like (Java)"class mydevice implements list_head" rather than "extends list_head", so it would not be quite like "super" :-)
Object-oriented design patterns in the kernel, part 1
Posted Jun 3, 2011 13:25 UTC (Fri) by linusw (subscriber, #40300)
[Link]
Yeah, extends or super or whatever. The point is that it is in the object orient.
Object-oriented design patterns in the kernel, part 1
Posted Jun 6, 2011 3:56 UTC (Mon) by jmm82 (guest, #59425)
[Link]
It is also used in many kernel subsystems when the base struct will have a pointer to a private struct where the driver can hold variables Specific to that driver. The base struct is like a super in this case and if all you have is a pointer to the private struct you can use container_of() to get the base struct.
Also, container_of is used with the kref code when deleting the struct which has embedded a kref for refence counting.