Exemplo n.º 1
0
// thread relinquish use of the processor
// and wait in the ready queuee
void th_yield()
{
	entry_section();

	if (threads[curr]->state == RUNNING)
		rq_push(curr);
	else if (threads[curr]->state == WAITING)
		wq_push(curr);

	// transfer the control to the next thread
	if (rq_begin != rq_end) {
		int old = curr;
		
		curr = rq_front();
		rq_pop();

		threads[curr]->state = RUNNING;

		exit_section();
		th_swap(threads[old], threads[curr]);
		entry_section();

		recycle_dead();
	}
	exit_section();
}
Exemplo n.º 2
0
critical void getRepPacket(packet_t *thePacket) {
   uint8_t plen, i;
   uint8_t * packet_ptr = (uint8_t *) thePacket;
  
   plen = rq_front() + HEADER_SIZE;
   for (i = 0; i < plen; i++) {
      packet_ptr[i] = rq_pop();
   }
   newRepPacket--;


   // XXX DEBUGGING
   //newUARTPacket++;
}
Exemplo n.º 3
0
void libevent_token_thread( int fd, short ev,void *arg){
    uint64_t u;
    ssize_t s;

    s = read(token_efd, &u, sizeof(uint64_t));
    if (s != sizeof(uint64_t)){
        printf("s is error\n");
    }

    notify_token_thread = NT_WORKING;
    do{
        RQ *rq_item = rq_pop();
        if(rq_item == NULL){ 
            /* DEBUG("rq_item is null");*/
            break;
        }
        if(rq_item->isjob == JOB_HAS) {
            
            WTQ *work_child = wtq_queue_tail;
            
            FIND_WTQ(work_child, JOB_FREE);

            if(work_child->isjob == JOB_FREE){

                rq_item->isjob = JOB_WORKING;
                work_child->rq_item = rq_item;
                work_child->isjob = JOB_HAS;

                LIBEVENT_WORK_THREAD *thread;
                thread = work_threads + work_child->no; 

                if(thread == NULL){
                    DEBUG("thread null ");
                    rq_item->isjob = JOB_HAS;
                    work_child->isjob = JOB_FREE;
                    break;
                }
                if(write(thread->notify_write_fd, "", 1) != 1){
                    DEBUG("write thread error");
                }
            }
        }
        else{
            DEBUG("break");
            break;
        }
    }while(1);

    notify_token_thread = NT_FREE;
}