void Thread::dequeue(Head* queue, bool flag) { if (queue->is_empty()) return; Thread* thread = (Thread*) queue->get_succ(); if (flag) { attach(thread); resume(thread); } else { get_succ()->attach(thread); } }
static void remove_block(void *bp, size_t size) { //printf ("remove block\n"); REQUIRES ( bp != NULL ); REQUIRES ( (size_t)(bp) % 8 == 0); int offset = get_offset(size); void *pred = get_pred(bp); void *succ = get_succ(bp); if ( pred == NULL && succ != NULL) //block to be removed is the first block in the list { SET_SUCC(bp) = 0; SET_PRED(succ) = 0; SET_ROOT(GET_BUCKET(root, offset)) = (long)succ; } else if (pred != NULL && succ == NULL) //block to be removed is the last block in the list { SET_SUCC(pred) = 0; SET_PRED(bp) = 0; } else if (pred != NULL && succ != NULL) //block to be removed is located somewhere within the list. { SET_SUCC(pred) = (int)( (long)succ - BASE); SET_PRED(succ) = (int)((long)pred - BASE); SET_PRED(bp) = 0; SET_SUCC(bp) = 0; } else if ( pred == NULL && succ == NULL) { //printf("resetting root\n"); SET_ROOT(GET_BUCKET(root, offset)) = 0; } print_list(); return; }
void Thread::run() { while (1) { if (!s_delayed.is_empty()) { uint32_t now = Watchdog::millis(); Thread* thread = (Thread*) s_delayed.get_succ(); while (thread != (Thread*) &s_delayed) { if (thread->m_expires > now) break; Thread* succ = (Thread*) thread->get_succ(); this->attach(thread); thread = succ; } } Thread* thread = (Thread*) get_succ(); if (thread != this) resume(thread); else Power::sleep(s_mode); } }
static void *first_best_fit (void *bp, size_t asize, size_t diff) { //printf ("in best fit"); for (size_t i = 0; i < 3;i++) { void *next_bp = get_succ(bp); if (next_bp == NULL) break; //printf ("next bp %p \n",next_bp); size_t size = GET_SIZE(HDRP((next_bp))); int alloc = GET_ALLOC( HDRP((next_bp) )); if ( (asize <= size) && !alloc && (size - asize) < diff) { ENSURES ( (size_t)(bp)%8 == 0); bp = next_bp; diff = size - asize; } } return bp; }