int main()
{
  FIFO_DATA_TYPE out_val;

  fifo_init(&data_in_f, data_in, FIFO_SIZE);
  fifo_init(&data_out_f, data_out, FIFO_SIZE);

  fifo_push(&data_in_f, 1);
  fifo_push(&data_in_f, 2);
  fifo_push(&data_in_f, 3);
  fifo_push(&data_in_f, 4);
  fifo_push(&data_in_f, 5);

  if (fifo_pop(&data_in_f, &out_val))
    printf("Valore: %d\n", out_val);
  if (fifo_pop(&data_in_f, &out_val))
    printf("Valore: %d\n", out_val);
  if (fifo_pop(&data_in_f, &out_val))
    printf("Valore: %d\n", out_val);
  if (fifo_pop(&data_in_f, &out_val))
    printf("Valore: %d\n", out_val);
  if (fifo_pop(&data_in_f, &out_val))
    printf("Valore: %d\n", out_val);

  //ft_init();

  //ft_step();

  return 0;
}
Example #2
0
int main()
{
    struct fifo * list = fifo_create_thread_safe_fifo();
    int i = 0;

    /*pop empty queue*/
    fifo_pop(list);

    printf("length: %d\n",fifo_length(list));
    
    for(;i<10;i++)
    {
        fifo_push(list,(void*)i);
    }

    printf("length: %d\n",fifo_length(list));

    for(i=0;i<5;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }

    printf("length: %d\n",fifo_length(list));

    for(i=0;i<2;i++)
    {
        fifo_push(list,(void*)(i+10));
    }

    printf("length: %d\n",fifo_length(list));
        
    for(i=0;i<7;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }
    
    printf("length: %d\n",fifo_length(list));

    for(i=0;i<2;i++)
    {
        fifo_push(list,(void*)(i+10));
    }

    printf("length: %d\n",fifo_length(list));
    
    for(i=0;i<2;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }

    printf("length: %d\n",fifo_length(list));
    fifo_delete(list,NULL);
}
Example #3
0
File: alloc.c Project: 7799/linux
static int bch_allocator_push(struct cache *ca, long bucket)
{
	unsigned i;

	/* Prios/gens are actually the most important reserve */
	if (fifo_push(&ca->free[RESERVE_PRIO], bucket))
		return true;

	for (i = 0; i < RESERVE_NR; i++)
		if (fifo_push(&ca->free[i], bucket))
			return true;

	return false;
}
Example #4
0
void connect_grabbanners(ip_report_t *r) {
	union {
		void *ptr;
		connection_status_t *c;
	} c_u;
	uint64_t state_key=0;
	uint8_t *c_ptr=NULL;
	output_data_t *e_out=NULL;
	char pchars[256];
	size_t p_off=0, j=0;

	state_key=get_connectionkey(r);

	if (rbfind(state_tbl, state_key, &c_u.ptr) > 0) {

		memset(pchars, 0, sizeof(pchars));

		for (j=0, p_off=0, c_ptr=c_u.c->recv_buf; j < c_u.c->recv_len; j++, c_ptr++) {
			if (isgraph(*c_ptr) || *c_ptr == ' ') {
				pchars[p_off++]=(char )*c_ptr;
			}
			if (p_off > (sizeof(pchars) -2)) break;
		}

		if (p_off > 0) {
			e_out=(output_data_t *)xmalloc(sizeof(output_data_t));
			e_out->type=OD_TYPE_BANNER;
			e_out->t_u.banner=xstrdup(pchars);

			fifo_push(r->od_q, (void *)e_out);
		}
	}

	return;
}
uint32_t event_handler_push(async_event_t* p_evt)
{
    if (p_evt == NULL)
    {
        return NRF_ERROR_NULL;
    }
    fifo_t* p_fifo = NULL;
    switch (p_evt->type)
    {
    case EVENT_TYPE_GENERIC:
    case EVENT_TYPE_PACKET:
    case EVENT_TYPE_SET_FLAG:
    case EVENT_TYPE_TIMER_SCH:
        p_fifo = &g_async_evt_fifo;
        break;
    case EVENT_TYPE_TIMER:
        p_fifo = &g_async_evt_fifo_ts;
        break;
    default:
        return NRF_ERROR_INVALID_PARAM;
    }
    uint32_t result = fifo_push(p_fifo, p_evt);
    if (result != NRF_SUCCESS)
    {
        return result;
    }

    /* trigger IRQ */
    NVIC_SetPendingIRQ(EVENT_HANDLER_IRQ);

    return NRF_SUCCESS;
}
Example #6
0
void signal_thread(struct thread* thread, int signum, intptr_t sigval) {
  struct thread* delivered = 0; // thread to awaken.
  uint64_t sigbit = 1ull << (signum%SIGNAL_LIMIT);
  {
    SPIN_GUARD_RAW(thread->signal.lock);
    ++signal.seq;
    // can we do 'instant delivery'?
    if (thread->signal.wait_mask & sigbit) {
      // deliver the signal to this thread.
      thread->signal.wait_mask = 0;
      thread->signal.wait_signum = signum;
      thread->signal.wait_sigval = sigval;
      delivered = thread;
      // remove it from waiting list.
      list_remove(&thread->signal.waiting_item);
    }

    // queue the signal if it was not instantly delivered.
    if (!delivered) {
      struct thread_signal_info* sig = thread->signal.sig + signum;
      struct signal_pending *pending = HEAP_NEW(struct signal_pending);
      pending->sigval = sigval;
      fifo_push(&sig->pending, &pending->item);
      thread->signal.pending_mask |= sigbit;
    }
  }
  
  // wake up the thread if it received the signal:
  if (delivered) {
    scheduler_wakeup(delivered);
  }
}
Example #7
0
void room_generateDoor (Room *room, Fifo *fifo)
{
    Room *nextRoom;
    Direction dir, opDir;
    for (dir = RIGHT; dir <= UP; dir++) {
        nextRoom = room_next(room, dir);
        if (nextRoom == NULL) {
            _room_attach(room, NULL, dir);
        } else {
            room->door[dir*2] = rand() % 3 == 0;/* chance porte1 */
            room->door[(dir*2)+1] = rand() % 5 == 0;   /* porte2 */
            if (nextRoom->type == RT_EMPTY) {
                if (room_doorCount(room, dir)) {
                    fifo_push(fifo, nextRoom);
                    nextRoom->type = RT_SIMPLE;
                }
            } else {
                opDir = opDir(dir);        /* chances de boucler */
                if (room_doorCount(nextRoom, opDir) || rand() % 4 == 0) {
                    _room_attach(room, nextRoom, dir);
                } else {
                    _room_attach(nextRoom, room, opDir);
                }
            }
        }
    }
}
bool serial_handler_event_send(serial_evt_t* evt)
{
    if (fifo_is_full(&tx_fifo))
    {
        return false;
    }

    enable_pin_listener(false);
    NVIC_DisableIRQ(SPI1_TWI1_IRQn); /* critical section */

    serial_data_t raw_data;
    raw_data.status_byte = 0;
    memcpy(raw_data.buffer, evt, evt->length + 1);
    fifo_push(&tx_fifo, &raw_data);

    if (fifo_is_full(&rx_fifo))
    {
        enable_pin_listener(true);
        serial_state = SERIAL_STATE_WAIT_FOR_QUEUE;
    }
    else if (serial_state == SERIAL_STATE_IDLE)
    {
        do_transmit();
    }

    NVIC_EnableIRQ(SPI1_TWI1_IRQn); /* critical section complete */
    return true;
}
void write_ai_regs(void* opaque, uint32_t address, uint32_t value, uint32_t mask)
{
    struct ai_controller* ai = (struct ai_controller*)opaque;
    uint32_t reg = ai_reg(address);

    switch (reg)
    {
    case AI_LEN_REG:
        masked_write(&ai->regs[AI_LEN_REG], value, mask);
        if (ai->regs[AI_LEN_REG] != 0) {
            fifo_push(ai);
        }
        else {
            /* stop sound */
        }
        return;

    case AI_STATUS_REG:
        clear_rcp_interrupt(ai->mi, MI_INTR_AI);
        return;

    case AI_BITRATE_REG:
    case AI_DACRATE_REG:
        /* lazy audio format setting */
        if ((ai->regs[reg]) != (value & mask))
            ai->samples_format_changed = 1;

        masked_write(&ai->regs[reg], value, mask);
        return;
    }

    masked_write(&ai->regs[reg], value, mask);
}
Example #10
0
/***
* The thread pool has the property that all the threads will keep running until signalled to quit.
* Each thread will call pthread_exit() once it has completed execution of it's current 'task_t'.
*/
void thread_pool_join_all( thread_pool_t *pool ) {
  dna_log(DEBUG, "Joining thread pool:");
  while ( !fifo_is_empty(pool->thread_queue) ) {
    dna_mutex_lock( pool->mutex );
    int threadsAreStillRunning = 0;
    while ( (threadsAreStillRunning = fifo_any( pool->thread_queue, &thread_context_is_running)) ) {
      dna_log(DEBUG, "Some threads are still running...%i", threadsAreStillRunning);
      dna_cond_wait( pool->wait, pool->mutex );
    }
    dna_thread_context_t *context = (dna_thread_context_t*) fifo_pop( pool->thread_queue );
    if (context->runstate == RUNNING) {
      dna_log(WARN, "context is still running, placing back in the queue.");
      fifo_push( pool->thread_queue, context );
    }
    else {
      // if the context is != RUNNING, it's either SHOULD_QUIT or HAS_QUIT
      // so we have to rely on the null work we pushed earlier to clear
      // any blocks
      dna_thread_context_join( context );
      dna_thread_context_destroy(context);
    }
    dna_mutex_unlock( pool->mutex );
  }
  dna_log(DEBUG, "Thread pool joined.");
}
Example #11
0
// in: linda_ud, key, ...
// out: true|false
int keepercall_send( lua_State* L)
{
	keeper_fifo* fifo;
	int n = lua_gettop( L) - 2;
	push_table( L, 1);                           // ud key ... fifos
	// get the fifo associated to this key in this linda, create it if it doesn't exist
	lua_pushvalue( L, 2);                        // ud key ... fifos key
	lua_rawget( L, -2);                          // ud key ... fifos fifo
	if( lua_isnil( L, -1))
	{
		lua_pop( L, 1);                            // ud key ... fifos
		fifo_new( L);                              // ud key ... fifos fifo
		lua_pushvalue( L, 2);                      // ud key ... fifos fifo key
		lua_pushvalue( L, -2);                     // ud key ... fifos fifo key fifo
		lua_rawset( L, -4);                        // ud key ... fifos fifo
	}
	lua_remove( L, -2);                          // ud key ... fifo
	fifo = (keeper_fifo*) lua_touserdata( L, -1);
	if( fifo->limit >= 0 && fifo->count + n > fifo->limit)
	{
		lua_settop( L, 0);                         //
		lua_pushboolean( L, 0);                    // false
	}
	else
	{
		fifo = prepare_fifo_access( L, -1);
		lua_replace( L, 2);                        // ud fifo ...
		fifo_push( L, fifo, n);                    // ud fifo
		lua_settop( L, 0);                         //
		lua_pushboolean( L, 1);                    // true
	}
	return 1;
}
Example #12
0
void serial_handle_interrupt(void)
{
  if (!PIR1bits.RCIF)
    return ;

  if (RCSTAbits.OERR)
    {
      unsigned char c;

      c = RCREG;

      gfifo.error = 1;
    }
  else if (RCSTAbits.FERR)
    {
      RCSTAbits.CREN = 0;
      RCSTAbits.CREN = 1;

      gfifo.error = 1;
    }
  else
    {
      if (gfifo.size < sizeof(gfifo.buffer))
	fifo_push(&gfifo, RCREG);
      else
	gfifo.overflow = 1;
    }

  PIR1bits.RCIF = 0;
}
Example #13
0
static int mystify_timer(TWidget *wid)
{
    if(paused){
        return 0;
    }
    
    if(polygons.nb_items > nb_polygons){
        /* We have too many polygons, we must drop some of them */
        fifo_pop(&polygons);
    }
    if(nb_polygons == polygons.nb_items){
        /* We have the good number of polygons, we can safely drop 
        the last one to add the new one later */
        fifo_pop(&polygons);
    }
    fifo_push(&polygons, &leading_polygon);
    
    /*
    * Then we update the leading polygon for the next round acording to
    * current move (the move may be altered in case of sreen border 
    * collision)
    */
    polygon_update(&leading_polygon, &move);
    change_color();
    
    wid->dirty++;
    
    return 0;
}
Example #14
0
// -----[ _post ]----------------------------------------------------
static int _post(sched_t * self, const sim_event_ops_t * ops,
		 void * ctx, double time, sim_time_t time_type)
{
  sched_static_t * sched= (sched_static_t *) self;
  _event_t * event= _event_create(ops, ctx);
  return fifo_push(sched->events, event);
}
Example #15
0
static void invalidate_one_bucket(struct cache *ca, struct bucket *b)
{
	bch_inc_gen(ca, b);
	b->prio = INITIAL_PRIO;
	atomic_inc(&b->pin);
	fifo_push(&ca->free_inc, b - ca->buckets);
}
Example #16
0
int create_report(const void *r) {
	union {
		const ip_report_t *ir;
		const arp_report_t *ar;
		const void *ptr;
		const uint8_t *cr;
		const uint32_t *r_magic;
		const uint16_t *len;
		struct myiphdr *i;
	} r_u;
	size_t dlen=0;
	output_data_t *e_out=NULL;
	char *res=NULL;
	struct in_addr ia;

	r_u.ptr=r;

	if (_disabled == 1 || *r_u.r_magic != IP_REPORT_MAGIC) {
		return 1;
	}

	if (r_u.ir->proto != IPPROTO_TCP) {
		return 1;
	}

	if (r_u.ir->doff > 0) {
		dlen=(size_t)r_u.ir->doff;
		r_u.cr += sizeof(ip_report_t);

		if (*r_u.len != dlen) {
			ERR("Mis-Match length of packet data");
			return 1;
		}

		r_u.len++;

		if (dlen < sizeof(struct myiphdr)) {
			return 1;
		}

		ia.s_addr=r_u.i->saddr;

		res=do_osdetect(r_u.cr, dlen);

		if (GET_IMMEDIATE() && res != NULL && strlen(res)) {
			OUT("System at %s matches OS %s", inet_ntoa(ia), res);
		}

		if (res != NULL) {
			e_out=(output_data_t *)xmalloc(sizeof(output_data_t));
			e_out->type=OD_TYPE_OS;
			e_out->t_u.os=(char *)xstrdup(res);
			r_u.ptr=r; /* reset */
			assert(r_u.ir->od_q != NULL);
			fifo_push(r_u.ir->od_q, (void *)e_out);
		}
	}

	return 1;
}
Example #17
0
void ui_printf(const char *msg, ...) {
  char     *buf;
  size_t    len;
  va_list   args;
  ui_msg_t *m;
  
  /* Compute buffer length. */
  va_start(args, msg);
  len = vsnprintf(NULL, 0, msg, args) + 1;
  va_end(args);
  
  /* Allocate data. */
  buf = malloc(len);
  if(buf == NULL)
    return;
  
  m = malloc(sizeof *m);
  if(m == NULL) {
    free(buf);
    return;
  }
  
  /* Print into string. */
  va_start(args, msg);
  vsprintf(buf, msg, args);
  va_end(args);
  
  /* Push message to UI queue. */
  m->type = UI_MSG_PRINT;
  m->data = buf;
  fifo_push(event_queue, m);
}
Example #18
0
/* Add an operation to the queue for tile @index
 * Note: if an operation affects more than one tile, it must be added once per tile.
 *
 * Concurrency: This function is not thread-safe on the same @self instance. */
void
operation_queue_add(OperationQueue *self, TileIndex index, OperationDataDrawDab *op)
{
    while (!tile_map_contains(self->tile_map, index)) {
#ifdef HEAVY_DEBUG
        operation_queue_resize(self, self->tile_map->size+1);
#else
        operation_queue_resize(self, self->tile_map->size*2);
#endif
    }

    Fifo **queue_pointer = (Fifo **)tile_map_get(self->tile_map, index);
    Fifo *op_queue = *queue_pointer;

    if (op_queue == NULL) {
        // Lazy initialization
        op_queue = fifo_new();
        *queue_pointer = op_queue;
    }

    if (fifo_peek_first(op_queue) == NULL) {
        // Critical section, not thread-safe
       if (!(self->dirty_tiles_n < self->tile_map->size*2*self->tile_map->size*2)) {
           // Prune duplicate tiles that cause us to almost exceed max
           self->dirty_tiles_n = remove_duplicate_tiles(self->dirty_tiles, self->dirty_tiles_n);
       }
       assert(self->dirty_tiles_n < self->tile_map->size*2*self->tile_map->size*2);
       self->dirty_tiles[self->dirty_tiles_n++] = index;
    }
    fifo_push(op_queue, (void *)op);
}
Example #19
0
void progressive_display_add_rect(struct xrdp_screen * self)
{
  int i, j;
  struct list* update_rects = self->update_rects;
  struct update_rect* urect;
  struct update_rect* fu_rect;
  struct update_rect* ur;
  struct xrdp_rect intersection;
  struct update_rect* tmp;
  struct list* l_tmp = list_create();
  l_tmp->auto_free = 1;

  bool no_inter = true;
  while (!fifo_is_empty(self->candidate_update_rects))
  {
    fu_rect = (struct update_rect*) fifo_pop(self->candidate_update_rects);
    if (update_rects->count > 0)
    {
      no_inter = true;
      for (i = update_rects->count - 1; i >= 0; i--)
      {
        urect = (struct update_rect*) list_get_item(update_rects, i);
        if (!rect_equal(&urect->rect, &fu_rect->rect))
        {
          if (rect_intersect(&urect->rect, &fu_rect->rect, &intersection))
          {
            no_inter = false;
            progressive_display_rect_union(fu_rect, urect, l_tmp);
            list_remove_item(update_rects, i);
            for (j = 0; j < l_tmp->count; j++)
            {
              ur = (struct update_rect*) list_get_item(l_tmp, j);
              tmp = (struct update_rect*) g_malloc(sizeof(struct update_rect), 0);
              g_memcpy(tmp, ur, sizeof(struct update_rect));
              fifo_push(self->candidate_update_rects, tmp);
            }
            list_clear(l_tmp);
            break;
          }
        }
        else
        {
          no_inter = false;
          urect->quality = fu_rect->quality;
          urect->quality_already_send = fu_rect->quality_already_send;
          break;
        }
      }
      if (no_inter)
      {
        list_add_progressive_display_rect(update_rects, fu_rect->rect.left, fu_rect->rect.top, fu_rect->rect.right, fu_rect->rect.bottom, fu_rect->quality, fu_rect->quality_already_send);
      }
    }
    else
    {
      list_add_progressive_display_rect(update_rects, fu_rect->rect.left, fu_rect->rect.top, fu_rect->rect.right, fu_rect->rect.bottom, fu_rect->quality, fu_rect->quality_already_send);
    }
  }
  list_delete(l_tmp);
}
Example #20
0
static int kill_connection(uint64_t key, void *cptr, void *pri_work) {
	union {
		void *ptr;
		connection_status_t *c;
	} c_u;
	union {
		uint64_t state_key;
		struct {
			uint32_t dhost;
			uint16_t sport;
			uint16_t dport;
		} s;
	} k_u;
	union {
		void *ptr;
		send_pri_workunit_t *w;
		uint8_t *inc;
	} w_u;
	struct in_addr ia;
	char shost_s[32];

	if (cptr == NULL) {
		PANIC("state table has NULL entry");
	}
	if (pri_work == NULL) {
		PANIC("pri_work is NULL");
	}

	c_u.ptr=cptr;
	k_u.state_key=key;

	ia.s_addr=c_u.c->send_ip;
	snprintf(shost_s, sizeof(shost_s) -1, "%s", inet_ntoa(ia));
	ia.s_addr=k_u.s.dhost;

	if (c_u.c->status != U_TCP_CLOSE) {
		DBG(M_CON, "%s:%u -> %s:%u hanging in %s", shost_s, k_u.s.dport, inet_ntoa(ia), k_u.s.sport, strconnstatus(c_u.c->status));

		w_u.ptr=xmalloc(sizeof(send_pri_workunit_t));
		w_u.w->magic=PRI_4SEND_MAGIC;
		w_u.w->dhost=k_u.s.dhost;
		w_u.w->dport=k_u.s.dport;
		w_u.w->sport=k_u.s.sport;
		w_u.w->shost=c_u.c->send_ip;
		w_u.w->tseq=c_u.c->tseq + (c_u.c->window / 2);
		w_u.w->mseq=c_u.c->mseq;
		w_u.w->window_size=0;
		w_u.w->flags=TH_RST;
		w_u.w->doff=0;
		w_u.w->t_tstamp=c_u.c->t_tstamp;
		w_u.w->m_tstamp=c_u.c->m_tstamp + 1;

		fifo_push(pri_work, w_u.ptr);
		s->stats.stream_segments_sent++;
		w_u.ptr=NULL;
	}

	return 1;
}
/**
* @brief SPI event handler, from SPI driver
*/
void spi_event_handler(spi_slave_evt_t evt)
{
    switch (evt.evt_type)
    {
        case SPI_SLAVE_BUFFERS_SET_DONE:
            if (has_pending_tx)
            {
                NRF_GPIO->OUTCLR = (1 << PIN_RDYN);
            }
            has_pending_tx = false;
            break;

        case SPI_SLAVE_XFER_DONE:
            NRF_GPIO->OUTSET = (1 << PIN_RDYN);
            nrf_gpio_pin_set(1);
            nrf_gpio_pin_clear(1);
            /* handle incoming */
            if (rx_buffer.buffer[SERIAL_LENGTH_POS] > 0)
            {
                if (fifo_push(&rx_fifo, &rx_buffer) == NRF_SUCCESS)
                {

                    /* notify ACI handler */
                    async_event_t async_evt;
                    async_evt.callback.generic = mesh_aci_command_check;
                    async_evt.type = EVENT_TYPE_GENERIC;
                    event_handler_push(&async_evt);
                }
                else
                {
                    APP_ERROR_CHECK(NRF_ERROR_NO_MEM);
                }
            }

            if (fifo_is_empty(&tx_fifo))
            {
                serial_state = SERIAL_STATE_IDLE;
                prepare_rx();
                enable_pin_listener(true);
            }
            else if (fifo_is_full(&rx_fifo))
            {
                prepare_rx();
                serial_state = SERIAL_STATE_WAIT_FOR_QUEUE;
            }
            else
            {
                do_transmit();
            }

            break;

        default:
            /* no implementation necessary */
            break;
    }
}
Example #22
0
void signal_process(struct process* process, int signum, intptr_t sigval) {
  struct thread* delivered = 0; // thread to awaken.
  {
    SPIN_GUARD_RAW(process->signal.lock);
    ++signal.seq;
    uint64_t sigbit = 1ull << (signum%SIGNAL_LIMIT);
  
    // can we do 'instant delivery' to the signal specific waiting thread?
    struct process_signal_info* sig = process->signal.sig + signum;
    struct thread* thread = sig->waiting;
    if (thread) {
      SPIN_GUARD_RAW(thread->signal.lock);
      if (thread->signal.wait_mask & sigbit) {
        // deliver the signal to this thread.
        thread->signal.wait_mask = 0;
        thread->signal.wait_signum = signum;
        thread->signal.wait_sigval = sigval;
        delivered = thread;
        // remove it from waiting list.
        sig->waiting = 0;
        list_remove(&thread->signal.waiting_item);
      }
    }

    // can we do 'instant delivery' to any waiting thread?
    if (!delivered) {
      for (list_item_t *li = list_first(&process->signal.waiting_list); 
           li; li = list_next(li)) {
        struct thread* thread = list_container(li, struct thread, signal.waiting_item);
        SPIN_GUARD_RAW(thread->signal.lock);
        if (thread->signal.wait_mask & sigbit) {
          // deliver the signal to this thread.
          thread->signal.wait_mask = 0;
          thread->signal.wait_signum = signum;
          thread->signal.wait_sigval = sigval;
          delivered = thread;
          // remove it from waiting list.
          list_remove(li);
          break;
        }        
      }
    }

    // queue the signal if it was not instantly delivered.
    if (!delivered) {
      struct signal_pending *pending = HEAP_NEW(struct signal_pending);
      pending->sigval = sigval;
      fifo_push(&sig->pending, &pending->item);
      process->signal.pending_mask |= sigbit;
    }
  }
  
  // wake up the thread that received the signal:
  if (delivered) {
    scheduler_wakeup(delivered);
  }
}
Example #23
0
//in: linda_ud key [val]
int keepercall_set( lua_State* L)
{
	STACK_GROW( L, 6);
	// make sure we have a value on the stack
	if( lua_gettop( L) == 2)                          // ud key val?
	{
		lua_pushnil( L);                                // ud key nil
	}

	// retrieve fifos associated with the linda
	push_table( L, 1);                                // ud key val fifos
	lua_replace( L, 1);                               // fifos key val

	if( !lua_isnil( L, 3)) // set/replace contents stored at the specified key?
	{
		keeper_fifo* fifo;
		lua_pushvalue( L, -2);                          // fifos key val key
		lua_rawget( L, 1);                              // fifos key val fifo|nil
		fifo = (keeper_fifo*) lua_touserdata( L, -1);
		if( fifo == NULL) // might be NULL if we set a nonexistent key to nil
		{
			lua_pop( L, 1);                               // fifos key val
			fifo_new( L);                                 // fifos key val fifo
			lua_pushvalue( L, 2);                         // fifos key val fifo key
			lua_pushvalue( L, -2);                        // fifos key val fifo key fifo
			lua_rawset( L, 1);                            // fifos key val fifo
		}
		else // the fifo exists, we just want to clear its contents
		{
			// empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
			lua_newtable( L);                             // fifos key val fifo {}
			lua_setuservalue( L, -2);                     // fifos key val fifo
			fifo->first = 1;
			fifo->count = 0;
		}
		fifo = prepare_fifo_access( L, -1);
		lua_insert( L, -2);                             // fifos key fifo val
		fifo_push( L, fifo, 1);                         // fifos key fifo
	}
	else // val == nil                                // fifos key nil
	{
		keeper_fifo* fifo;
		lua_pop( L, 1);                                 // fifos key
		lua_rawget( L, 1);                              // fifos fifo|nil
		// empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
		fifo = (keeper_fifo*) lua_touserdata( L, -1);
		if( fifo != NULL) // might be NULL if we set a nonexistent key to nil
		{
			lua_newtable( L);                             // fifos fifo {}
			lua_setuservalue( L, -2);                     // fifos fifo
			fifo->first = 1;
			fifo->count = 0;
		}
	}
	return 0;
}
Example #24
0
void Serial_WriteByte(uint8_t writtenByte)
{
  unsigned int i;
  
  if (fifo_push(&Serial.fifo_output, writtenByte)) {
    for (i = 0; i < Serial.OBOH_Amount; i++)
      Serial.OutBufOverHandlers[i]();
  }
  RunTransmission();
}
Example #25
0
void *fifo_fill( void *nothing ) {
  int i = 0;
  for (i = 0; i < ELEMS; i++) {
    fifo_push( fifo, NULL );
#ifdef VALUE_LOG
    dna_log(DEBUG, "<< added %i to value fifo", i);
#endif

  }
  return NULL;
}
Example #26
0
bool switch_unicast(Port* port, Packet* packet) {
    if(!port->out)
        return false;

#ifdef NET_CONTROL
    if(!fifo_push(port->out->queue, packet))
        return false;
#else
    port->out->send(port->out, packet);
#endif

    return true;
}
Example #27
0
void Serial_WriteFloat(float number)
{
  int i, j;
  
  Serial._32Converter.RealNum = number;
  for (i = 3; i >= 0; i--) {
    if (fifo_push(&Serial.fifo_output, Serial._32Converter.Bytes[i])) {
      for (j = 0; j < Serial.OBOH_Amount; j++)
        Serial.OutBufOverHandlers[j]();
    }
  }

  RunTransmission();
}
Example #28
0
int neighbour_list_scan_neighbour(void * data, void * user_data)
{
    struct neighbour * n = (struct neighbour *)data;
    struct fifo * delete_list = (struct fifo *)user_data;
    if(n->ttl <= 0)
    {
        fifo_push(delete_list,n);
    }
    else
    {
        n->ttl -= 1;
    }
    return 0;
}
Example #29
0
void Serial_WriteInt16(uint16_t number)
{
  int i, j;
  
  Serial.WordConverter.Word = number;
  
  for (i = 1; i >= 0; i--) {
    if (fifo_push(&Serial.fifo_output, Serial.WordConverter.Bytes[i])) {
      for (j = 0; j < Serial.OBOH_Amount; j++)
        Serial.OutBufOverHandlers[j]();
    }
  }
  
  RunTransmission();
}
Example #30
0
void Serial_WriteLine(const char* line)
{
  unsigned int j;
  uint16_t i = 0;
  
  while(line[i] != '\0')
  {
    if (fifo_push(&Serial.fifo_output, line[i])) {
      for (j = 0; j < Serial.OBOH_Amount; j++)
        Serial.OutBufOverHandlers[j]();
    }
    i++;
  }
  
  RunTransmission();
}