1 #include "common.h" 2 3 #include <ddekit/initcall.h> 4 5 6 #ifdef DDEKIT_DEBUG_INITCALL 7 #undef DDEBUG 8 #define DDEBUG DDEKIT_DEBUG_INITCALL 9 #endif 10 11 #include "debug.h" 12 13 static struct __ddekit_initcall_s head = {0,0,0}; 14 15 /****************************************************************************/ 16 /* __ddekit_add_initcall */ 17 /****************************************************************************/ 18 void __attribute__((used)) 19 __ddekit_add_initcall(struct __ddekit_initcall_s * ic) { 20 21 /* This function is required for the DDEKIT_INITCALL makro */ 22 23 struct __ddekit_initcall_s *i = 0; 24 25 DDEBUG_MSG_VERBOSE("adding initcall (%p) to %p with prio %d head at %p", 26 ic, ic->func, ic->prio, &head); 27 28 for (i = &head; i; i=i->next) 29 { 30 if (!i->next) { 31 i->next = ic; 32 return; 33 } 34 if (i->next->prio > ic->prio) { 35 ic->next = i->next; 36 i->next = ic; 37 return; 38 } 39 } 40 } 41 42 /****************************************************************************/ 43 /* ddekit_do_initcalls */ 44 /****************************************************************************/ 45 void ddekit_do_initcalls() 46 { 47 struct __ddekit_initcall_s *i = 0; 48 49 DDEBUG_MSG_VERBOSE("exectuing initcalls (head at %p, head->next = %p)", 50 &head, head.next); 51 52 for (i = head.next; i; i=i->next) { 53 DDEBUG_MSG_VERBOSE("executing initcall: %p with prio %d", 54 i->func, i->prio); 55 i->func(); 56 } 57 } 58