/****************************************************************************** * ddekit_lock_init_locked * *****************************************************************************/ PUBLIC void ddekit_lock_init_locked(ddekit_lock_t *mtx) { (*mtx) = (struct ddekit_lock *) ddekit_simple_malloc(sizeof(struct ddekit_lock)); (*mtx)->wait_queue = NULL; (*mtx)->owner = ddekit_thread_myself(); }
/****************************************************************************** * ddekit_lock_try_lock * *****************************************************************************/ PUBLIC int ddekit_lock_try_lock(ddekit_lock_t *mtx) { if ((*mtx)->owner == NULL) { (*mtx)->owner = ddekit_thread_myself(); return 0; } else { return -1; } }
/****************************************************************************** * ddekit_lock_lock * *****************************************************************************/ PUBLIC void ddekit_lock_lock (ddekit_lock_t *mtx) { if ((*mtx)->owner == NULL) { (*mtx)->owner = ddekit_thread_myself(); } else { if ((*mtx)->wait_queue == NULL) { (*mtx)->wait_queue = ddekit_thread_myself(); } else { ddekit_thread_t *pos = (*mtx)->wait_queue; while(pos->next != NULL) { pos = pos->next; } pos->next = ddekit_thread_myself(); } _ddekit_thread_schedule(); if ((*mtx)->owner != NULL) { _ddekit_print_backtrace((*mtx)->owner); _ddekit_print_backtrace(ddekit_thread_myself()); ddekit_panic("owner!=NULL: %s (I am %s)\n", (*mtx)->owner->name, ddekit_thread_myself()->name); } (*mtx)->owner = ddekit_thread_myself(); } }
/* Process setup for worker threads */ int l4dde26_process_add_worker(void) { dde26_thread_data *cur = init_dde26_thread(); /* If this function is called for a kernel_thread, the thread already has * been set up and we just need to store a reference to the ddekit struct. * However, this function may also be called directly to turn an L4 thread * into a DDE thread. Then, we need to initialize here. */ cur->_ddekit_thread = ddekit_thread_myself(); if (cur->_ddekit_thread == NULL) cur->_ddekit_thread = ddekit_thread_setup_myself(".dde26_thread"); Assert(cur->_ddekit_thread); ddekit_thread_set_my_data(cur); attach_pid(LX_TASK(cur), 0, &cur->_vpid); /* Linux' default is to have this set to 1 initially and let the * scheduler set this to 0 later on. */ current_thread_info()->preempt_count = 0; return 0; }