
25 Dec
2008
25 Dec
'08
1:56 a.m.
Remy Bohmer wrote:
Create a default fallback routine that can be used if there is no strong implementation:
__attribute__((weak)) unsigned long long printk_clock(void) { return sched_clock(); }
and here is an example of the strong implementation (from the ARM architecture):
unsigned long long printk_clock(void) { return (unsigned long long)(jiffies - INITIAL_JIFFIES) * (1000000000 / HZ); }
If the strong implementation is available, the weak is simply discarded during linking, if the strong is omitted, the weak is used as fallback. This is a clean, lean and mean example without complex/superfluous aliases or checks for NULL pointers. It should not get any harder than this...
+1. I like this one, and U-Boot/MIPS _machine_restart() is implemented in the same manner.
--
Shinya Kuribayashi
NEC Electronics