Exemplo n.º 1
0
int get_pending_task(task *t)
{
   SDL_SemWait(pending_task_count);

   if (get_from_queue(&pending_meshes, t))
      return true;
   if (get_from_queue(&pending_gen, t))
      return true;
   assert(0);
   return false;
}
Exemplo n.º 2
0
static ssize_t
read_aux(struct file *file, char *buffer, size_t count, loff_t * ppos)
{
	DECLARE_WAITQUEUE(wait, current);
	ssize_t i = count;
	unsigned char c;

	if (queue_empty()) {
		if (file->f_flags & O_NONBLOCK)
			return -EAGAIN;
		add_wait_queue(&queue->proc_list, &wait);
	      repeat:
		set_current_state(TASK_INTERRUPTIBLE);
		if (queue_empty() && !signal_pending(current)) {
			schedule();
			goto repeat;
		}
		current->state = TASK_RUNNING;
		remove_wait_queue(&queue->proc_list, &wait);
	}
	while (i > 0 && !queue_empty()) {
		c = get_from_queue();
		put_user(c, buffer++);
		i--;
	}
	if (count - i) {
		file->f_dentry->d_inode->i_atime = CURRENT_TIME;
		return count - i;
	}
	if (signal_pending(current))
		return -ERESTARTSYS;
	return 0;
}
Exemplo n.º 3
0
static int read_aux(struct inode * inode, struct file * file, char * buffer, int count)
{
	struct wait_queue wait = { current, NULL };
	int i = count;
	unsigned char c;

	if (queue_empty()) {
		if (file->f_flags & O_NONBLOCK)
			return -EAGAIN;
		add_wait_queue(&queue->proc_list, &wait);
repeat:
		current->state = TASK_INTERRUPTIBLE;
		if (queue_empty() && !(current->signal & ~current->blocked)) {
			schedule();
			goto repeat;
		}
		current->state = TASK_RUNNING;
		remove_wait_queue(&queue->proc_list, &wait);
	}
	while (i > 0 && !queue_empty()) {
		c = get_from_queue();
		put_user(c, buffer++);
		i--;
	}
	aux_ready = !queue_empty();
	if (count-i) {
		inode->i_atime = CURRENT_TIME;
		return count-i;
	}
	if (current->signal & ~current->blocked)
		return -ERESTARTSYS;
	return 0;
}
Exemplo n.º 4
0
Arquivo: transport.c Projeto: gz/aos10
/* Called when we receive a packet */
static void
my_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
    struct ip_addr *addr, u16_t port)
{
    xid_t xid;
    struct rpc_queue *q_item;

    xid = extract_xid(p->payload);

    q_item = get_from_queue(xid);

    debug("Recieved a reply for xid: %u (%d) %p\n", 
	  xid, p->len, q_item);
    if (q_item == NULL)
        return;
    if (q_item->func != NULL) {
        p->arg[0] = p->payload;
	q_item->func(q_item->callback, q_item->arg, p);
    }
    
    /* Free our memory */
    pbuf_free(p);
    pbuf_free(q_item->pbuf);
    free(q_item);
}
Exemplo n.º 5
0
int decode_video(void *arg)
{
    VideoState *video = (VideoState *)arg;
    AVFrame *pFrame;
    int frameFinished;
    AVPacket packet;
    AVPacket *pkt = &packet;
	

    pFrame = avcodec_alloc_frame();
    while(true) {
	if(get_from_queue(&video->videoq, pkt) < 0) {
	    break;
	}
	avcodec_decode_video2(video->pCodecCtx, pFrame, &frameFinished, &packet);
	//did we get a video frame?
	if(frameFinished) {
	    if(video_frame_queue(video, pFrame) < 0)
		break;
	}
	av_free_packet(pkt);
    }
    av_free(pFrame);
    return 0;
}
Exemplo n.º 6
0
ssize_t read_qp(struct file * file, char * buffer, size_t count, loff_t *ppos)		
{
  struct wait_queue wait /* = { get_current() , ((void *)0)  } */;
  ssize_t i;
  unsigned char c;
  int temp_1, temp_2;
  
  i = count;
  temp_1 = queue_empty();

  if (temp_1) {
    if (file->f_flags & 04000 )
      return - 11 ;
    add_wait_queue(&queue->proc_list, &wait);
    //TRACER  repeat:
    //BLAST get_current() ->state = 1 ;
    temp_1 = queue_empty();
    temp_2 = signal_pending(get_current());

    if (temp_1 && ! temp_2) {
      schedule   ();
      //TRACER goto repeat;
    }
    //BLAST get_current() ->state = 0 ;
    remove_wait_queue(&queue->proc_list, &wait);
  }

  /*BLAST
    while (i > 0 && !queue_empty()) {
  */
  while(BLAST_NONDET) {
    c = get_from_queue();

/* TRACER ({ int __ret_pu; switch(sizeof (*( buffer++ ))) { case 1:
   __asm__ __volatile__("call __put_user_" "1" :"=a" ( __ret_pu ) :"0"
   ( buffer++ ),"d" ( (__typeof__(*( buffer++ )))( c ) ) :"cx") ;
   break; case 2: __asm__ __volatile__("call __put_user_" "2" :"=a" (
   __ret_pu ) :"0" ( buffer++ ),"d" ( (__typeof__(*( buffer++ )))( c )
   ) :"cx") ; break; case 4: __asm__ __volatile__("call __put_user_"
   "4" :"=a" ( __ret_pu ) :"0" ( buffer++ ),"d" ( (__typeof__(*(
   buffer++ )))( c ) ) :"cx") ; break; default: __asm__
   __volatile__("call __put_user_" "X" :"=a" ( __ret_pu ) :"0" (
   buffer++ ),"d" ( c ) :"cx") ; break; } __ret_pu; }) ; */

    i--;
  }

  if (count-i) {
    //file->f_dentry->d_inode->i_atime = xtime.tv_sec ;
    return count-i;
  }

  /*BLAST
    if (signal_pending(get_current() ))
    return - 512 ;
  */
  return 0;
}
Exemplo n.º 7
0
Arquivo: rpc.c Projeto: gapry/AOS
enum rpc_stat
rpc_call(struct pbuf *pbuf, int len, struct udp_pcb *pcb, 
     void (*func)(void *, uintptr_t, struct pbuf *), 
     void *callback, uintptr_t token)
{
    struct rpc_call_arg call_arg;
    struct rpc_queue *q_item;
    int time_out;
    enum rpc_stat stat;
    xid_t xid;

    /* If we give up early, we must ensure that the argument remains in memory
     * just in case the packet comes in later */
    assert(pcb);
    assert(pbuf);

    /* GeneratrSend the thing with the unlock frunction as a callback */
    call_arg.func = func;
    call_arg.callback = callback;
    call_arg.token = token;
    call_arg.complete = 0;

    /* Make the call */
    xid = extract_xid(pbuf);
    stat = rpc_send(pbuf, pbuf->tot_len, pcb, &rpc_call_cb, NULL, 
                   (uintptr_t)&call_arg);
    if(stat){
        return stat;
    }

    /* Wait for the response */
    time_out = RETRANSMIT_DELAY_MS * (CALL_RETRIES + 1);
    while(time_out >= 0){
        _usleep(CALL_TIMEOUT_MS * 1000);
        if(call_arg.complete) {
            /* Success */
            return 0;
        }
        rpc_timeout(CALL_TIMEOUT_MS);
        time_out -= CALL_TIMEOUT_MS;
    }

    /* If we get here, we have failed. Data is on the stack so make sure 
     * we remove references from the queue */
    q_item = get_from_queue(xid);
    assert(q_item);
    pbuf_free(q_item->pbuf);
    free(q_item);
    return RPCERR_COMM;
}
Exemplo n.º 8
0
int decode_audio(AudioState *audio, uint8_t *audio_buf, int buf_size, double *pts_ptr)
{
  int len1, data_size, n;
  AVPacket *pkt = &audio->audio_pkt;
  double pts;

  for(;;) {
    while(audio->audioPktSize > 0) {
      data_size = buf_size;
      len1 = avcodec_decode_audio3(audio->pCodecCtx, 
			 (int16_t *)audio_buf, &data_size, pkt);
      if(len1 < 0) {
	/* if error, skip frame */
	audio->audioPktSize = 0;
	break;
      }
      audio->audioPktData += len1;
      audio->audioPktSize -= len1;
      if(data_size <= 0) {
	/* No data yet, get more frames */
	continue;
      }
      pts = audio->audioClk;
      *pts_ptr = pts;
      n = 2;//* audio->pCodecCtx->channels;
      audio->audioClk += (double)data_size /
	(double)(n * audio->pCodecCtx->sample_rate);

      /* We have data, return it and come back for more later */
      return data_size;
    }
    if(pkt->data)
      av_free_packet(pkt);

    if(audio->quit) {
      return -1;
    }
    /* next packet */
    if(get_from_queue(&audio->audioq, pkt) < 0) {
      break;
    }
    audio->audioPktData = pkt->data;
    audio->audioPktSize = pkt->size;
    /* if update, update the audio clock w/pts */
    if(pkt->pts != AV_NOPTS_VALUE) {
      audio->audioClk = av_q2d(audio->pCodecCtx->time_base)*pkt->pts;
    }

  }
}
Exemplo n.º 9
0
/*
 * Put bytes from input queue to buffer.
 */
size_t read_aux(char * buffer, size_t count )
{
  size_t i = count;
  unsigned char c;

  if (queue_empty()) {
    return 0;
  }
  while (i > 0 && !queue_empty()) {
    c = get_from_queue();
    *buffer++ = c;
    i--;
  }
  return count-i;
}
Exemplo n.º 10
0
Z reader1(Z o, int n, ...)
{
	DWORD time;
	char ch;

	do {
		ch = (char)get_from_queue(&q, &time);
		if (ch == '\0')
			InterlockedIncrement(&counter);
		else
			printf("%010d:%c\n", time-start, ch);
		Sleep(rand() % 100);
	} while (counter < 1);
	return(NULL);
}
Exemplo n.º 11
0
Arquivo: rpc.c Projeto: gapry/AOS
static void
my_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
    struct ip_addr *addr, u16_t port)
{
    xid_t xid;
    struct rpc_queue *q_item;
    (void)port;

    xid = extract_xid(p);

    q_item = get_from_queue(xid);

    debug("Recieved a reply for xid: %u (%d) %p\n", xid, p->len, q_item);
    if (q_item != NULL){
        assert(q_item->func);
        q_item->func(q_item->callback, q_item->arg, p);
        /* Clean up the queue item */
        pbuf_free(q_item->pbuf);
        free(q_item);
    }
    /* Done with the incoming packet so free it */
    pbuf_free(p);
}
Exemplo n.º 12
0
int thread_main(server_decl_t * srv)
{
     ci_connection_t con;
     char clientname[CI_MAXHOSTNAMELEN + 1];
     int ret, request_status = CI_NO_STATUS;
     int keepalive_reqs;
//***********************
     thread_signals(0);
//*************************
     srv->srv_id = getpid();    //Setting my pid ...

     for (;;) {
          /*
             If we must shutdown IMEDIATELLY it is time to leave the server
             else if we are going to shutdown GRACEFULLY we are going to die 
             only if there are not any accepted connections
           */
          if (child_data->to_be_killed == IMMEDIATELY) {
               srv->running = 0;
               return 1;
          }

          if ((ret = get_from_queue(con_queue, &con)) == 0) {
               if (child_data->to_be_killed) {
                    srv->running = 0;
                    return 1;
               }
               ret = wait_for_queue(con_queue);
               continue;
          }

          if (ret < 0) {        //An error has occured
               ci_debug_printf(1,
                               "Fatal Error!!! Error getting a connection from connections queue!!!\n");
               break;
          }

          ci_thread_mutex_lock(&counters_mtx);  /*Update counters as soon as possible */
          (child_data->freeservers)--;
          (child_data->usedservers)++;
          ci_thread_mutex_unlock(&counters_mtx);

          ci_netio_init(con.fd);
          ret = 1;
          if (srv->current_req == NULL)
               srv->current_req = newrequest(&con);
          else
               ret = recycle_request(srv->current_req, &con);

          if (srv->current_req == NULL || ret == 0) {
               ci_sockaddr_t_to_host(&(con.claddr), clientname,
                                     CI_MAXHOSTNAMELEN);
               ci_debug_printf(1, "Request from %s denied...\n", clientname);
               hard_close_connection((&con));
               goto end_of_main_loop_thread;    /*The request rejected. Log an error and continue ... */
          }

          keepalive_reqs = 0;
          do {
               if (MAX_KEEPALIVE_REQUESTS > 0
                   && keepalive_reqs >= MAX_KEEPALIVE_REQUESTS)
                    srv->current_req->keepalive = 0;    /*do not keep alive connection */
               if (child_data->to_be_killed)    /*We are going to die do not keep-alive */
                    srv->current_req->keepalive = 0;

               if ((request_status = process_request(srv->current_req)) == CI_NO_STATUS) {
                    ci_debug_printf(5,
                                    "Process request timeout or interrupted....\n");
                    ci_request_reset(srv->current_req);
                    break;
               }
               srv->served_requests++;
               srv->served_requests_no_reallocation++;
               keepalive_reqs++;

               /*Increase served requests. I dont like this. The delay is small but I don't like... */
               ci_thread_mutex_lock(&counters_mtx);
               (child_data->requests)++;
               ci_thread_mutex_unlock(&counters_mtx);

               log_access(srv->current_req, request_status);
//             break; //No keep-alive ......

               if (child_data->to_be_killed  == IMMEDIATELY)
                    break;      //Just exiting the keep-alive loop

               /*if we are going to term gracefully we will try to keep our promice for
                 keepalived request....
                */
               if (child_data->to_be_killed  == GRACEFULLY && 
                   srv->current_req->keepalive == 0)
                    break;

               ci_debug_printf(8, "Keep-alive:%d\n",
                               srv->current_req->keepalive);
               if (srv->current_req->keepalive && keepalive_request(srv->current_req)) {
                   ci_debug_printf(8,
                                   "Server %d going to serve new request from client (keep-alive) \n",
                                   srv->srv_id);
               }
               else
                    break;
          } while (1);

          if (srv->current_req) {
               if (request_status != CI_OK || child_data->to_be_killed) {
                    hard_close_connection(srv->current_req->connection);
               }
               else {
                    close_connection(srv->current_req->connection);
               }
          }
          if (srv->served_requests_no_reallocation >
              MAX_REQUESTS_BEFORE_REALLOCATE_MEM) {
               ci_debug_printf(5,
                               "Max requests reached, reallocate memory and buffers .....\n");
               ci_request_destroy(srv->current_req);
               srv->current_req = NULL;
               srv->served_requests_no_reallocation = 0;
          }


        end_of_main_loop_thread:
          ci_thread_mutex_lock(&counters_mtx);
          (child_data->freeservers)++;
          (child_data->usedservers)--;
          ci_thread_mutex_unlock(&counters_mtx);
          ci_thread_cond_signal(&free_server_cond);

     }
     srv->running = 0;
     return 0;
}
Exemplo n.º 13
0
int thread_main(server_decl_t *srv){
     ci_connection_t con;
     ci_thread_mutex_t cont_mtx;
     char clientname[CI_MAXHOSTNAMELEN+1];
     int max,ret,request_status=0;
     request_t *tmp;
//***********************
     thread_signals();
//*************************
     srv->srv_id=getpid(); //Setting my pid ...
     srv->srv_pthread=pthread_self();

     for(;;){
	  if(child_data->to_be_killed)
	       return; //Exiting thread.....
	  
	  if((ret=get_from_queue(con_queue,&con))==0){
	       wait_for_queue(con_queue); //It is better that the wait_for_queue to be 
                                          //moved into the get_from_queue 
	       continue; 
	  }
	  ci_thread_mutex_lock(&counters_mtx);
	  (child_data->freeservers)--;
	  (child_data->usedservers)++;
	  ci_thread_mutex_unlock(&counters_mtx);


	  if(ret<0){ //An error has occured
	       debug_printf(1,"Error getting from connections queue\n");
	       break;
	  }

/*
	  icap_addrtohost(&(con.claddr.sin_addr),clientname, CI_MAXHOSTNAMELEN);
	  debug_printf(1,"Client name: %s server %d\n",clientname,srv->srv_id);
*/
	  icap_netio_init(con.fd);

	  if(srv->current_req==NULL)
	       srv->current_req=newrequest(&con);
	  else
	       recycle_request(srv->current_req,&con);

	  do{
	       if((request_status=process_request(srv->current_req))<0){
		    debug_printf(5,"Process request timeout or interupted....\n");
		    reset_request(srv->current_req);
		    break;//
	       }
	       srv->served_requests++;
	       srv->served_requests_no_reallocation++;

    /*Increase served requests. I dont like this. The delay is small but I don't like...*/
	       ci_thread_mutex_lock(&counters_mtx); 
	       (child_data->requests)++; 
	       ci_thread_mutex_unlock(&counters_mtx);



	       log_access(srv->current_req,request_status);
//	       break; //No keep-alive ......

	       if(child_data->to_be_killed)
		    return; //Exiting thread.....
	      
               debug_printf(8,"Keep-alive:%d\n",srv->current_req->keepalive); 
	       if(srv->current_req->keepalive && check_for_keepalive_data(srv->current_req->connection->fd)){
		    reset_request(srv->current_req);
		    debug_printf(8,"Server %d going to serve new request from client(keep-alive) \n",
				 srv->srv_id);
	       }
	       else
		    break;
	  }while(1);
	  
	  if(srv->current_req){
	       if(request_status<0)
		    hard_close_connection(srv->current_req->connection);
	       else
		    close_connection(srv->current_req->connection);
	  }
	  if(srv->served_requests_no_reallocation > MAX_REQUESTS_BEFORE_REALLOCATE_MEM){
	       debug_printf(5,"Max requests reached, reallocate memory and buffers .....\n");
	       destroy_request(srv->current_req);
	       srv->current_req=NULL;
	       srv->served_requests_no_reallocation=0;
	  }

	  ci_thread_mutex_lock(&counters_mtx);
	  (child_data->freeservers)++;
	  (child_data->usedservers)--;
	  ci_thread_mutex_unlock(&counters_mtx);
	  ci_thread_cond_signal(&free_server_cond);

     }
     return 0;
}
Exemplo n.º 14
0
static ssize_t
sun_mouse_read(struct file *file, char *buffer,
	       size_t count, loff_t *ppos)
{
	struct wait_queue wait = { current, NULL };

	if (queue_empty ()){
		if (file->f_flags & O_NONBLOCK)
			return -EWOULDBLOCK;
		add_wait_queue (&sunmouse.proc_list, &wait);
		while (queue_empty () && !signal_pending(current)) {
			current->state = TASK_INTERRUPTIBLE;
			schedule ();
		}
		current->state = TASK_RUNNING;
		remove_wait_queue (&sunmouse.proc_list, &wait);
	}
	if (gen_events){
		char *p = buffer, *end = buffer+count;
		
		while (p < end && !queue_empty ()){
#ifdef CONFIG_SPARC32_COMPAT
			if (current->tss.flags & SPARC_FLAG_32BIT) {
				Firm_event *q = get_from_queue();
				
				if ((end - p) <
				    ((sizeof(Firm_event) - sizeof(struct timeval) +
				      (sizeof(u32) * 2))))
					break;
				copy_to_user_ret((Firm_event *)p, q, 
						 sizeof(Firm_event)-sizeof(struct timeval),
						 -EFAULT);
				p += sizeof(Firm_event)-sizeof(struct timeval);
				__put_user_ret(q->time.tv_sec, (u32 *)p, -EFAULT);
				p += sizeof(u32);
				__put_user_ret(q->time.tv_usec, (u32 *)p, -EFAULT);
				p += sizeof(u32);
			} else
#endif	
			{	
				if ((end - p) < sizeof(Firm_event))
					break;
				copy_to_user_ret((Firm_event *)p, get_from_queue(),
				     		 sizeof(Firm_event), -EFAULT);
				p += sizeof (Firm_event);
			}
		}
		sunmouse.ready = !queue_empty ();
		file->f_dentry->d_inode->i_atime = CURRENT_TIME;
		return p-buffer;
	} else {
		int c, limit = 3;

		if (count < limit)
			limit = count;
		for (c = 0; c < limit; c++) {
			put_user(sunmouse.queue.stream[sunmouse.tail], buffer);
			buffer++;
			sunmouse.tail = (sunmouse.tail + 1) % STREAM_SIZE;
		}
		while (c < count) {
			if (c >= 5)
				break;
			put_user(0, buffer);
			buffer++;
			c++;
		}
		sunmouse.ready = !queue_empty();
		file->f_dentry->d_inode->i_atime = CURRENT_TIME;
		return c;
	}
	/* Only called if nothing was sent */
	if (signal_pending(current))
		return -ERESTARTSYS;
	return 0;
}
Exemplo n.º 15
0
static ssize_t
sun_mouse_read(struct file *file, char *buffer,
	       size_t count, loff_t *ppos)
{
	DECLARE_WAITQUEUE(wait, current);
	unsigned long flags;

	if (queue_empty ()) {
		if (file->f_flags & O_NONBLOCK)
			return -EWOULDBLOCK;
		add_wait_queue (&sunmouse.proc_list, &wait);
repeat:
		set_current_state(TASK_INTERRUPTIBLE);
		if (queue_empty() && !signal_pending(current)) {
			schedule();
			goto repeat;
		}
		current->state = TASK_RUNNING;
		remove_wait_queue (&sunmouse.proc_list, &wait);
	}
	if (gen_events) {
		char *p = buffer, *end = buffer+count;
		
		spin_lock_irqsave(&sunmouse.lock, flags);
		while (p < end && !queue_empty ()){
			Firm_event this_event;

			get_from_queue(&this_event);
			spin_unlock_irqrestore(&sunmouse.lock, flags);

#ifdef CONFIG_SPARC32_COMPAT
			if (current->thread.flags & SPARC_FLAG_32BIT) {
				if ((end - p) <
				    ((sizeof(Firm_event) - sizeof(struct timeval) +
				      (sizeof(u32) * 2))))
					break;
				if (copy_to_user((Firm_event *)p, &this_event,
						 sizeof(Firm_event)-sizeof(struct timeval)))
					return -EFAULT;
				p += sizeof(Firm_event)-sizeof(struct timeval);
				if (__put_user(this_event.time.tv_sec, (u32 *)p))
					return -EFAULT;
				p += sizeof(u32);
				if (__put_user(this_event.time.tv_usec, (u32 *)p))
					return -EFAULT;
				p += sizeof(u32);
			} else
#endif	
			{	
				if ((end - p) < sizeof(Firm_event))
					break;
				if (copy_to_user((Firm_event *)p, &this_event,
				     		 sizeof(Firm_event)))
					return -EFAULT;
				p += sizeof (Firm_event);
			}
			spin_lock_irqsave(&sunmouse.lock, flags);
		}
		spin_unlock_irqrestore(&sunmouse.lock, flags);
		file->f_dentry->d_inode->i_atime = CURRENT_TIME;
		return p-buffer;
	} else {
		int c, limit = 3;

		if (count < limit)
			limit = count;
		for (c = 0; c < limit; c++) {
			unsigned char val;
			int empty = 0;

			spin_lock_irqsave(&sunmouse.lock, flags);
			if (queue_empty()) {
				empty = 1;
				val = 0;
			} else {
				val = sunmouse.queue.stream[sunmouse.tail];
				sunmouse.tail = (sunmouse.tail + 1) % STREAM_SIZE;
			}
			spin_unlock_irqrestore(&sunmouse.lock, flags);

			if (empty)
				break;

			put_user(val, buffer);
			buffer++;
		}
		while (c < count) {
			if (c >= 5)
				break;
			put_user(0, buffer);
			buffer++;
			c++;
		}
		file->f_dentry->d_inode->i_atime = CURRENT_TIME;
		return c;
	}
	/* Only called if nothing was sent */
	if (signal_pending(current))
		return -ERESTARTSYS;
	return 0;
}