Example #1
0
int queue_av_pkt(void *arg) {
    LOGI("created reading thread");
    AVPacket *pkt = av_mallocz(sizeof(AVPacket));
    State *state = (State *)arg;
    init_queue(&state->audio->raw_data_buf);
    init_queue(&state->video->raw_data_buf);
    while(true) {
	if(state->video->raw_data_buf.size > MAX_VIDEO_QUEUE_SIZE || state->audio->raw_data_buf.size > MAX_AUDIO_QUEUE_SIZE) {
	    SDL_Delay(10);
//	    LOGW("queue is full, waiting for decoding");
	    continue;
	}
	if(av_read_frame(state->content->format_ctx, pkt) < 0) {
	    if(url_ferror(state->content->format_ctx->pb) == 0) {
		SDL_Delay(100);
		continue;
	    }else {
		LOGW("read frame error, maybe come to end of content : queue_av_pkt");
		break;		// error or end of content
	    }
	}
	//put packet into AV queue
	if(pkt->stream_index == state->video->track) {
	    add_to_queue(&state->video->raw_data_buf, pkt);
	}else if(pkt->stream_index == state->audio->track) {
	    add_to_queue(&state->audio->raw_data_buf, pkt);
	}else {
	    LOGV("neither audio or video track : queue_av_pkt");
	    av_free_packet(pkt);
	}
    }
    return 0;
}
Example #2
0
void process_packets(struct ts *ts, uint8_t *ts_packet, ssize_t readen) {
	struct timeval now;
	struct packet *packet = ts->current_packet;

	if (packet->data_len + readen < PACKET_MAX_LENGTH) {
		// Add data to buffer
		memcpy(packet->data + packet->data_len, ts_packet, readen);
		packet->data_len += readen;
	} else {
		// Too much data, add to queue
		p_dbg1("*** Reached buffer end (%zd + %zd > %d)\n", packet->data_len + readen, readen, PACKET_MAX_LENGTH);
		packet = add_to_queue(ts);
	}

	if (!packet->ts.tv_sec)
		gettimeofday(&packet->ts, NULL);

	gettimeofday(&now, NULL);
	unsigned long long diff = timeval_diff_msec(&packet->ts, &now);
	if (diff > PACKET_MAX_TIME) {
		// Too much time have passed, add to queue
		p_dbg1("+++ Reached time limit (%llu > %d)\n", diff, PACKET_MAX_TIME);
		add_to_queue(ts);
	}
}
Example #3
0
void	hf_leave(t_env *env, char *str, int fd)
{
	t_chat_rooms	*rooms_tmp;
	t_usercont		*tmp;
	t_usercont		*before;

	str = str + 12;
	rooms_tmp = env->rooms_list;
	while (rooms_list != NULL)
	{
		if (ft_strcmp(str, rooms_list->name) == 0)
			break;
		rooms_list = rooms_list->next;
	}
	if (rooms_list ==  NULL)
		add_to_queue(env, "Server: There is no such room", fd);
	tmp = rooms_list->users;
	before = NULL;
	while (tmp != NULL)
	{
		if (tmp->user->fd == fd )
			break;
		before = tmp;
		tmp = tmp->next;
	}
	if (before == NULL)
		rooms_list->users = tmp->next;
	else (tmp == NULL)
		add_to_queue(env, "Server: You are not in that room", fd);
	else
Example #4
0
void		hf_msgch(t_env *env, char *str, int fd)
{//verifier que on est bien dans la salle ?
	char		*chanel
	rooms_list	*tmp;
	t_usercont	*utmp;

	str = str + 7;
	chanel = get_first_word(str);
	tmp = env->rooms_list;
	while (tmp != NULL)
	{
		if (ft_strcmp(tmp->name, chanel) == 0)
			break;
		tmp = tmp->next;
	}
	if (tmp == NULL)
	{
		add_to_queue(env, "There is no such room", fd);		
		return ;
	}
	str = str + ft_strlen(chanel) + 1;
	free(chanel);
	utmp = tmp->users;
	//rajouter le nom de l'utilisateur au debut du message
	while (utmp != NULL)
	{
		if (fd != utmp->user->fd)
		add_to_queue(env, str, utmp->user->fd);
		utmp = utmp->next;
	}
}
Example #5
0
int queue_av_pkt(void *arg) {
    AVPacket *pkt = av_mallocz(sizeof(AVPacket));
    State *state = (State *)arg;
    init_queue(&state->audio->audioq);
    init_queue(&state->video->videoq);
    while(true) {
	//if queue is full, wait for eat
	if(state->video->videoq.size > MAX_VIDEO_QUEUE_SIZE || state->audio->audioq.size > MAX_AUDIO_QUEUE_SIZE) {
	    SDL_Delay(5);
	    continue;
	}
	//if packet is valid
	if(av_read_frame(state->file->pFormatCtx, pkt) < 0) {
	    if(url_ferror(state->file->pFormatCtx->pb) == 0) {
		SDL_Delay(100);
		continue;
	    }else {
		break;		// error or end of file
	    }
	}
	//put packet into AV queue
	if(pkt->stream_index == state->video->videoTrack) {
	    add_to_queue(&state->video->videoq, pkt);
	}else if(pkt->stream_index == state->audio->audioTrack) {
	    add_to_queue(&state->audio->audioq, pkt);
	}else {
	    av_free_packet(pkt);
	}
    }
}
Example #6
0
int mesh_worker_handler(void *data)
{
   for(;;) {
      task t;
      if (get_pending_task(&t)) {
         switch (t.task_type) {
            case JOB_build_mesh: {
               stbvox_mesh_maker mm;
               mesh_chunk *mc = malloc(sizeof(*mc));
               built_mesh out_mesh;
               vec3i wc = { t.world_x, t.world_y, 0 };

               stbvox_init_mesh_maker(&mm);

               mc->chunk_x = t.world_x >> MESH_CHUNK_CACHE_X_LOG2;
               mc->chunk_y = t.world_y >> MESH_CHUNK_CACHE_Y_LOG2;

               generate_mesh_for_chunk_set(&mm, mc, wc, &t.cs, vertex_build_buffer, sizeof(vertex_build_buffer), face_buffer);

               out_mesh.vertex_build_buffer = malloc(mc->num_quads * 16);
               out_mesh.face_buffer  = malloc(mc->num_quads *  4);
               memcpy(out_mesh.vertex_build_buffer, vertex_build_buffer, mc->num_quads * 16);
               memcpy(out_mesh.face_buffer, face_buffer, mc->num_quads * 4);
               {
                  int i;
                  for (i=0; i < 16; ++i)
                     release_gen_chunk(t.cs.chunk[0][i]);
               }
               out_mesh.mc = mc;
               if (!add_to_queue(&built_meshes, &out_mesh)) {
                  free(out_mesh.vertex_build_buffer);
                  free(out_mesh.face_buffer);
               } else
                  waiter_wake(&manager_monitor);
               break;
            }
            case JOB_generate_terrain: {
               finished_gen_chunk fgc;
               fgc.world_x = t.world_x;
               fgc.world_y = t.world_y;
               fgc.gc = generate_chunk(t.world_x, t.world_y);
               if (!add_to_queue(&finished_gen, &fgc))
                  release_gen_chunk(fgc.gc);
               else {
                  ++fgc.gc->ref_count;
                  waiter_wake(&manager_monitor);
               }
               break;
            }
         }
      }
   }
}
  void
  Sink::send_owned(Part& owned) throw(ZmqErrorType)
  {
    switch (state_)
    {
    case NOTSENT:
      if (!cached_.valid())
      {
        cached_.move(owned);
        break;
      }
      if (try_send_first_cached(false))
      {
        cached_.move(owned);
      }
      else
      {
        if (state_ == QUEUEING)
        {
          add_to_queue(owned);
        }
      }

      break;
    case SENDING:
      if (cached_.valid())
      {
        do_send_one(cached_, false);
        cached_.move(owned);
      }
      else
      {
        ZMQMESSAGE_LOG_STREAM <<
          "Outgoing message in state SENDING, no messages cached yet - strange"
          << ZMQMESSAGE_LOG_TERM;
        cached_.move(owned);
      }

      break;
    case QUEUEING:
      assert(outgoing_queue_.get());
      add_to_queue(owned);

      break;
    case DROPPING:
      break;
    case FLUSHED:
      ZMQMESSAGE_LOG_STREAM << "trying to send a message in FLUSHED state"
        << ZMQMESSAGE_LOG_TERM;
      break;
    }
  }
Example #8
0
int main ()
{
    int sq, eq, q[50], Max = 50;
    initialise_queue(&sq, &eq);
    add_to_queue(q, &sq, &eq, Max, 1);
    add_to_queue(q, &sq, &eq, Max, 2);
    add_to_queue(q, &sq, &eq, Max, 3);
    add_to_queue(q, &sq, &eq, Max, 4);
    print(q, &sq, &eq);
    pop_queue(&sq, &eq, Max);
    print(q, &sq, &eq);
    printf("\n%d", queue_front(q, &sq));
}
Example #9
0
void schedule(){
	printf("Scheduling starts\n");
        int d;
        scanf("%d",&d);
	if(current_thread == NULL){
		current_thread=head->task;
		swapcontext(&Main,current_thread->thread);
	}
	else{
	printf("Checkling");
		if(head->next ==NULL){
			it.it_interval.tv_sec=0;
			it.it_interval.tv_usec=0;
			it.it_value.tv_sec=0;
			it.it_value.tv_usec=0;
			setitimer(ITIMER_PROF,&it,NULL);
			setcontext(&Main);
		}
		else{
			current_thread=head->next->task;
			add_to_queue(head->task);
                        previous_thread=head->task;
			head=head->next;
			swapcontext(previous_thread->thread,current_thread->thread);
		}
	}
	printf("Scheduling ends\n");
}
Example #10
0
void msgq_watch()
{
	key_t key;
	msg_t message;
	int shmid;
	shared_block *shm;

	while(1)
	{
		msgq_rcvr(&message);
		memcpy(&key, message.mtext,MSG_SIZE); 
	
		printf("key: %i\n", key);	
		shmid = shmget(key, sizeof(shared_block), S_IWUSR | S_IRUSR | 
                                                              S_IWGRP | S_IRGRP);
		if(shmid == -1)
		{
			printf("%s\n", strerror(errno));
		}

		shm = (shared_block *) shmat(shmid, NULL, 0);
		if(shm == (void *) -1)
		{
			printf("%s\n", strerror(errno));
		}

		pthread_mutex_lock(&lock);
		add_to_queue(shm, shm->pid);		
		pthread_mutex_unlock(&lock);
	}
}
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tprio,tarr_time,tburst_time,tpid;
  pptr tprocess;
  FILE *read;
  read=fopen("inputp","r");
  write=fopen("write","w");
  //trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    fscanf(read,"%d",&tprio);//toscan the priority
    tprocess=create_process(tpid,tarr_time,tburst_time);
    tprocess->over=tprio;//assigning prio
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  tprocess=head;
  i=0;
  while(tprocess!=NULL) {
    ++i;
    tprocess=tprocess->next;
  }
  priopre(&head,&tail,i);
  return 0;
}
Example #12
0
File: erq.c Project: amotzkau/ldmud
/*-------------------------------------------------------------------------*/
int
writen (int fd, char *mesg, int len, struct equeue_s **qpp)

/* Send or queue the message <mesg> (length <len> bytes) to <fd>.
 * If *<qpp> is non-NULL, the message is queued immediately.
 * Otherwise, the function tries to send as much of the message
 * as possible, and the queues whatever is left.
 */

{
    int l = 0;

    XPRINTF((stderr, "%s writen(%d, %p:%d, %p (-> %p) ))\n"
                   , time_stamp(), fd, mesg, len, qpp, *qpp));
    if (!(*qpp))
    {
        /* Send as much of the message as possible */
        do
            l = write(fd, mesg, len);
        while (l == -1 && errno == EINTR);
        XPRINTF((stderr, "%s   Wrote %d bytes.\n", time_stamp(), l));
        if (l < 0 || l == len)
            return l;
        mesg += l;
        len -= l;
    }

    if (!len)
        return 0;

    XPRINTF((stderr, "%s   Queuing data %p:%d\n", time_stamp(), mesg, len));
    add_to_queue(qpp, mesg, len, 0);
    return l;
} /* writen() */
  bool
  Sink::try_send_first_cached(bool last) throw(ZmqErrorType)
  {
    assert(state_ == NOTSENT);
    assert(cached_.valid());
    bool blocked = false;

    try
    {
      if (options_ & OutOptions::EMULATE_BLOCK_SENDS)
      {
        blocked = true;
        ZMQMESSAGE_LOG_STREAM
          << "Emulating blocking send!" << ZMQMESSAGE_LOG_TERM;
      }
      else
      {
        blocked = !do_send_one_non_strict(cached_, last);
      }
    }
    catch (const ZmqErrorType& e)
    {
      cached_.mark_invalid();
      ZMQMESSAGE_LOG_STREAM <<
        "Cannot send first outgoing message: error: " << e.what() <<
        ZMQMESSAGE_LOG_TERM;
      throw;
    }

    if (blocked)
    {
      if (options_ & OutOptions::CACHE_ON_BLOCK)
      {
        ZMQMESSAGE_LOG_STREAM
          << "Cannot send first outgoing message: would block: start caching"
          << ZMQMESSAGE_LOG_TERM;
        state_ = QUEUEING;
        outgoing_queue_.reset(new QueueContainer(init_queue_len));
        add_to_queue(cached_);
      }
      else if (options_ & OutOptions::DROP_ON_BLOCK)
      {
        ZMQMESSAGE_LOG_STREAM <<
          "Cannot send first outgoing message: would block: dropping" <<
          ZMQMESSAGE_LOG_TERM;
        state_ = DROPPING;
      }
      else
      {
        ZMQMESSAGE_LOG_STREAM <<
          "Cannot send first outgoing message: would block: throwing error" <<
          ZMQMESSAGE_LOG_TERM;
        throw_zmq_exception(zmq::error_t());
      }
      return false;
    }

    state_ = SENDING;
    return true;
  }
Example #14
0
int add_gen_task(task *t)
{
   int retval = add_to_queue(&pending_gen, t);
   if (retval)
      SDL_SemPost(pending_task_count);
   return retval;
}
Example #15
0
void ok_prermdeconfigure(int argc, void **argv) {
  struct pkginfo *deconf= (struct pkginfo*)argv[0];
  /* also has conflictor in argv[1] and infavour in argv[2] */
  
  if (cipaction->arg == act_install)
    add_to_queue(deconf);
}
Example #16
0
int iothread_perform_base(int (*handler)(void *), void (*completionCallback)(void *, int),
                          void *context) {
    ASSERT_IS_MAIN_THREAD();
    ASSERT_IS_NOT_FORKED_CHILD();
    iothread_init();

    // Create and initialize a request.
    struct SpawnRequest_t *req = new SpawnRequest_t();
    req->handler = handler;
    req->completionCallback = completionCallback;
    req->context = context;

    int local_thread_count = -1;
    bool spawn_new_thread = false;
    {
        // Lock around a local region. Note that we can only access s_active_thread_count under the
        // lock.
        scoped_lock lock(s_spawn_queue_lock);
        add_to_queue(req);
        if (s_active_thread_count < IO_MAX_THREADS) {
            s_active_thread_count++;
            spawn_new_thread = true;
        }
        local_thread_count = s_active_thread_count;
    }

    // Kick off the thread if we decided to do so.
    if (spawn_new_thread) {
        iothread_spawn();
    }

    // We return the active thread count for informational purposes only.
    return local_thread_count;
}
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tpid,tarr_time,tburst_time;
  pptr tprocess;
  FILE *read;
  read=fopen("input","r");
  write=fopen("write","w");
  trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    //fscanf(read,"%d",&tpid);
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    tprocess=create_process(tpid,tarr_time,tburst_time);
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  fcfs(head,tail);



  return 0;


}
Example #18
0
int set_net_timer(net_timer_event *e, unsigned int delay_ms, net_timer_callback callback, void *args, int flags)
{
    int err = NO_ERROR;

    mutex_lock(&net_q.lock);

    if(e->pending) {
        if(flags & NET_TIMER_PENDING_IGNORE) {
            err = ERR_GENERAL;
            goto out;
        }
        _cancel_net_timer(e);
    }

    // set up the timer
    e->func = callback;
    e->args = args;
    e->sched_time = system_time() + delay_ms * 1000;
    e->pending = true;

    add_to_queue(e);

out:
    mutex_unlock(&net_q.lock);

    return err;
}
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tpid,tarr_time,tburst_time;
  pptr tprocess;
  FILE *read;
  read=fopen("input","r");
  write=fopen("write","w");
  //trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    //fscanf(read,"%d",&tpid);
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    tprocess=create_process(tpid,tarr_time,tburst_time);
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  tprocess=head;
  i=0;
  while(tprocess!=NULL) {
    ++i;
    tprocess=tprocess->next;
  }
  roundrobin(&head,&tail,i);
  return 0;
}
Example #20
0
int rthread_create(struct rthread_t *newt, void (*fn)(), void *arg){
	printf("CREATING THREAD.........\n");
	rthread_init(newt);
	makecontext(newt->thread,fn,1,arg);
	int ret=add_to_queue(newt);
	printf("Created thread...........\n");
	return ret;
}
Example #21
0
void		hf_msg(t_env *env, char *str, int fd)
{
	char	*usr;
	int		fdr;

	str = str + 5;
	usr = get_first_word(str);
	str = str + ft_strlen(usr) + 1;
	fdr = get_client_fd(usr, env->users_list);
	if (fdr == -1)
		add_to_queue(env, "There is no such user", fd);
	else
	{
		add_to_queue(env, str, fdr);
	}
	free(usr);
}
Example #22
0
void player2Win(Room * r) {
    send(r->p2, "Win!", strlen("Win!"), 0);
    send(r->p1, "Lose", strlen("Lose"), 0);
    add_to_queue(r->p1);
    r->p1 = -1;
    r->playeramount--;
    r->clock = 0;
}
Example #23
0
int main(int argc, char *argv[]) {
    char ch = 'A';
    int i;
    struct entry *elem;

    TAILQ_INIT(&head);
    for (i=0; i<4; i++) {
        add_to_queue(ch);
        ch++;
        add_to_queue(ch);

        elem = head.tqh_first;
        TAILQ_REMOVE(&head, head.tqh_first, entries);
        printf("%c\n", elem->c);
        free(elem);
    }
    exit(0);
}
Example #24
0
                void run_in_thread() {
                    osmium::thread::set_thread_name("_osmium_read");

                    try {
                        while (!m_done) {
                            std::string data {m_decompressor.read()};
                            if (at_end_of_data(data)) {
                                break;
                            }
                            add_to_queue(m_queue, std::move(data));
                        }

                        m_decompressor.close();
                    } catch (...) {
                        add_to_queue(m_queue, std::current_exception());
                    }

                    add_end_of_data_to_queue(m_queue);
                }
void thread_local_buffer::write(procid_t target, char* c, size_t len, 
                                bool do_not_count_bytes_sent) {
  if (!do_not_count_bytes_sent) {
    bytes_sent[target] += len;
    inc_calls_sent(target);
  }
  // make sure that messsages sent before this write are sent before this write
  if (current_archive[target].off) {
    archive_locks[target].lock();

    if (current_archive[target].off) {
      add_to_queue(target, current_archive[target].buf, current_archive[target].off);
    }
    current_archive[target].buf = NULL; 
    current_archive[target].off = 0;
    archive_locks[target].unlock();
  }
  add_to_queue(target, c, len);
}
Example #26
0
void	read_token(t_env *env, char *str, int *i)
{
	while (str[*i] == ' ' || str[*i] == '\t')
		(*i)++;
    if (is_number(str[*i]))
        add_to_queue(env, read_number(str, i));
    else if (is_operator(str[*i]))
		add_operator(env, str, i);
	else
		add_paranthesis(env, str, i);
}
Example #27
0
                void parse() {
                    try {
                        run();
                    } catch (...) {
                        std::exception_ptr exception = std::current_exception();
                        set_header_exception(exception);
                        add_to_queue(m_output_queue, std::move(exception));
                    }

                    add_end_of_data_to_queue(m_output_queue);
                }
Example #28
0
File: rpc.c Project: gapry/AOS
enum rpc_stat
rpc_send(struct pbuf *pbuf, int len, struct udp_pcb *pcb, 
     void (*func)(void *, uintptr_t, struct pbuf *), 
     void *callback, uintptr_t token)
{
    assert(pcb);
    pbuf_realloc(pbuf, len);
    /* Add to a queue */
    add_to_queue(pbuf, pcb, func, callback, token);
    return my_udp_send(pcb, pbuf);
}
Example #29
0
/* Function: load_graph_file
 * Given a filename, the entire contents of the file will be read into memory
 * filename: name of the file 
*/
void load_graph_file(char *filename, int * numtasks){
    FILE * f = fopen(filename, "r");
    char * line = NULL;
    size_t len = 0;
    int read = 0;

    while((read = getline(&line, &len, f)) != -1){
        add_to_queue(line);
        *numtasks = *numtasks + 1;
    }
    fclose(f);
}
void thread_local_buffer::release(procid_t target, bool do_not_count_bytes_sent) {
  if (!do_not_count_bytes_sent) {
    bytes_sent[target] += current_archive[target].off - prev_acquire_archive_size - sizeof(packet_hdr);
    inc_calls_sent(target);
  }
  if (!using_secondary) {
    if (current_archive[target].off >= FULL_BUFFER_SIZE_LIMIT) {
      // shift the buffer into outbuf
      char* ptr = current_archive[target].buf;
      size_t len = current_archive[target].off;
      current_archive[target].buf = NULL; 
      current_archive[target].off = 0;
      archive_locks[target].unlock();

      add_to_queue(target, ptr, len);

    } else {
      archive_locks[target].unlock();
    }
  } else {
    // we were using the secondary archive
    // now we try to shift it to the primary
    archive_locks[target].lock();
    if (current_archive[target].off == 0) {
      // nothing in current archive, swap it in!
      std::swap(current_archive[target], secondary_archive);
      archive_locks[target].unlock();
    } else {
      // put current into the queue, put secondary into current.
      char* ptr = current_archive[target].buf;
      size_t len = current_archive[target].off;
      current_archive[target] = secondary_archive;
      archive_locks[target].unlock();
      // add both current to the queue and clear secondary
      add_to_queue(target, ptr, len);
      secondary_archive.buf = NULL;
      secondary_archive.off = 0;
    }
  }
}