/** Our implementation of Linux' kernel_thread() function. Setup a new * thread running our __kthread_helper() function. */ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) { ddekit_thread_t *t; char name[20]; struct __kthread_data *kt = vmalloc(sizeof(struct __kthread_data)); ddekit_lock_t lock; /* Initialize (and grab) handshake lock */ ddekit_lock_init(&lock); ddekit_lock_lock(&lock); int threadnum = atomic_inc_return(&kthread_count); kt->fn = fn; kt->arg = arg; kt->lock = lock; // Copy lock ptr, note that kt is freed by the // new thread, so we MUST NOT use kt->lock after // this point! snprintf(name, 20, ".kthread%x", threadnum); t = ddekit_thread_create(__kthread_helper, (void *)kt, name, 0); Assert(t); ddekit_lock_lock(&lock); ddekit_lock_deinit(&lock); return pid_nr(VPID_P(kt->kthread)); }
/***************************************************************************** * ddekit_init_timers * ****************************************************************************/ void ddekit_init_timers(void) { static int first_time=0; if (!first_time) { ddekit_lock_init(&lock); jiffies = get_current_clock(); HZ = sys_hz(); pending_timer_ints = ddekit_sem_init(0); th = ddekit_thread_create(ddekit_timer_thread, 0, "timer"); first_time=1; DDEBUG_MSG_INFO("DDEkit timer subsustem initialized"); } }
static void initlock(void *arg) { ddekit_lock_init(&ann_buf_lock); }