コード例 #1
0
ファイル: tunala.c プロジェクト: 119120119/node
static void selector_add_tunala(tunala_selector_t * s, tunala_item_t * t)
{
    /* Set clean read if sm.clean_in is not full */
    if (t->clean_read != -1) {
        selector_add_raw_fd(s, t->clean_read,
                            (buffer_full(state_machine_get_buffer(&t->sm,
                                                                  SM_CLEAN_IN))
                             ? SEL_EXCEPTS : SEL_READS));
    }
    /* Set clean send if sm.clean_out is not empty */
    if (t->clean_send != -1) {
        selector_add_raw_fd(s, t->clean_send,
                            (buffer_empty(state_machine_get_buffer(&t->sm,
                                                                   SM_CLEAN_OUT))
                             ? SEL_EXCEPTS : SEL_SENDS));
    }
    /* Set dirty read if sm.dirty_in is not full */
    if (t->dirty_read != -1) {
        selector_add_raw_fd(s, t->dirty_read,
                            (buffer_full(state_machine_get_buffer(&t->sm,
                                                                  SM_DIRTY_IN))
                             ? SEL_EXCEPTS : SEL_READS));
    }
    /* Set dirty send if sm.dirty_out is not empty */
    if (t->dirty_send != -1) {
        selector_add_raw_fd(s, t->dirty_send,
                            (buffer_empty(state_machine_get_buffer(&t->sm,
                                                                   SM_DIRTY_OUT))
                             ? SEL_EXCEPTS : SEL_SENDS));
    }
}
コード例 #2
0
void write_uart(char c) {
	while(buffer_full());

	*uart = c;

	while(buffer_full());
}
コード例 #3
0
ファイル: buffer.c プロジェクト: gburri/MAVRIC_Library
uint8_t buffer_put(buffer_t * buffer, uint8_t byte) 
{
	uint8_t tmp;
	tmp = (buffer->buffer_head + 1)&BUFFER_MASK;

	if (tmp == buffer->buffer_tail) 
	{
		//error: buffer full! return 1
		return 1;
	}
	else
	{
		// store incoming data in buffer
		buffer->Buffer[buffer->buffer_head] = byte;
		buffer->buffer_head = tmp;
	
		if (buffer_full(buffer)) 
		{
			buffer->full = 1;
		}	 
		else 
		{
			buffer->full = 0;
		}
		
		return 0;
	}
}
コード例 #4
0
ファイル: buffer.c プロジェクト: gburri/MAVRIC_Library
uint8_t buffer_put_lossy(buffer_t * buffer, uint8_t byte) 
{
	uint8_t tmp;
	
	tmp = (buffer->buffer_head + 1)&BUFFER_MASK;

	if (tmp == buffer->buffer_tail) 
	{
		// error: receive buffer overflow!!
		// lose old incoming data at the end of the buffer
		buffer->buffer_tail = (buffer->buffer_tail + 1)&BUFFER_MASK;
	}

	// store incoming data in buffer
	buffer->Buffer[buffer->buffer_head] = byte;
	buffer->buffer_head = tmp;
	
	if (buffer_full(buffer)) 
	{
		buffer->full = 1;
	}
	else 
	{
		buffer->full = 0;
	}
	
	return 0;
}
コード例 #5
0
ファイル: gpiodump.c プロジェクト: 23ars/bbbtools
void *producer(void *ptr)
{
	struct s_VcdFormatValues buffervalues;
	static uint64_t nr_of_captures=0;
	const uint8_t mem_offset=4;
	while (producer_running)
	{
		pthread_mutex_lock(&shared_var_mutex);
		while (buffer_full(&dataCapturedValues))
		{
			pthread_cond_wait(&cond_producer, &shared_var_mutex);
		}
		/*Capture values from */

		dbg("\tWaiting for event...\n");
		prussdrv_pru_wait_event(PRU_EVTOUT_0);
		prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU1_ARM_INTERRUPT);
		buffervalues.values=shared_ram[mem_offset];
		buffervalues.seconds = sample_delay*nr_of_captures++;
		(void) buffer_push(&dataCapturedValues, buffervalues);
	
		pthread_cond_signal(&cond_consumer);/*wake up consumer*/
		pthread_mutex_unlock(&shared_var_mutex);
	}
	pthread_exit(0);
}
コード例 #6
0
ファイル: buffer.c プロジェクト: 0culus/openssl
void buffer_from_BIO(buffer_t *buf, BIO *bio)
{
	int ret;
	if(!bio || buffer_full(buf))
		return;
	ret = BIO_read(bio, buf->data + buf->used, buffer_unused(buf));
	if(ret > 0) {
		buf->used += ret;
		buf->total_in += ret;
	}
}
コード例 #7
0
ファイル: inputx.c プロジェクト: CrouchingLlama/openlase-mame
void inputx_postn_rate(const unicode_char_t *text, size_t text_len, mame_time rate)
{
	int last_cr = 0;
	unicode_char_t ch;
	const char *s;
	const struct CharInfo *ci;

	current_rate = rate;

	if (inputx_can_post())
	{
		while((text_len > 0) && !buffer_full())
		{
			ch = *(text++);
			text_len--;

			/* change all eolns to '\r' */
			if ((ch != '\n') || !last_cr)
			{
				if (ch == '\n')
					ch = '\r';
				else
					last_cr = (ch == '\r');

				if (LOG_INPUTX)
					logerror("inputx_postn(): code=%i (%s) port=%i ipt->name='%s'\n", (int) ch, charstr(ch), codes[ch].port[0], codes[ch].ipt[0] ? codes[ch].ipt[0]->name : "<null>");

				if (can_post_key_directly(ch))
				{
					/* we can post this key in the queue directly */
					internal_post_key(ch);
				}
				else if (can_post_key_alternate(ch))
				{
					/* we can post this key with an alternate representation */
					ci = find_charinfo(ch);
					assert(ci && ci->alternate);
					s = ci->alternate;
					while(*s)
					{
						s += uchar_from_utf8(&ch, s, strlen(s));
						internal_post_key(ch);
					}
				}
			}
			else
			{
				last_cr = 0;
			}
		}
	}
}
コード例 #8
0
ファイル: buffer.c プロジェクト: 0culus/openssl
void buffer_from_SSL(buffer_t *buf, SSL *ssl)
{
	int ret;
	if(!ssl || buffer_full(buf))
		return;
	ret = SSL_read(ssl, buf->data + buf->used, buffer_unused(buf));
	if(ret > 0) {
		buf->used += ret;
		buf->total_in += ret;
	}
	if(ret < 0)
		int_ssl_check(ssl, ret);
}
コード例 #9
0
ファイル: propagate.c プロジェクト: menrcom/propd
static struct propagate_packet *enqueue_route(struct cfg_ctx *cfg, struct in_addr *addr) {

	/*
	  Если уже есть буфер - заполнять его
	  Иначе делать новый и добавлять в список буферов

	  Возможные варианты:
	  - буферов нет вообще:      создавать новый буфер
	  - буфера есть
	  - последний заполнен:    создавать новый буфер
	  - последний не заполнен: пихать маршрут в существующий буфер
	*/

	struct pkt_buffer *b;

	if (cfg->send_queue && !buffer_full(cfg->send_queue)) {

		if(cfg->debug)
			syslog(LOG_INFO,
			       "enqueue_route: there is space left in buffer");
		b = LIST_GET(cfg->send_queue, struct pkt_buffer, lh);

	} else
コード例 #10
0
ファイル: hw2c.c プロジェクト: asanciangco/CS133
void produce()
{
        bool ret;
        int next;
	
	#pragma omp critical
        ret = buffer_full()
		|| consumer_count + (w_index - r_index)%FIFO_SIZE > N;

        if(ret)
                return;

	#pragma omp critical
        next = (w_index + 1) % FIFO_SIZE;

        double x = (double) rand() / RAND_MAX;
        double y = (double) rand() / RAND_MAX;

        if(!put_point(x, y, next))
                return;

	#pragma omp critical
        w_index = next;
}
コード例 #11
0
ファイル: codec.c プロジェクト: ittner/toxcore
/* Called from RTP */
void queue_message(RTPSession *session, RTPMessage *msg)
{
    /* This function is unregistered during call termination befor destroing
     * Codec session so no need to check for validity of cs
     */
    CSSession *cs = session->cs;

    if (!cs) return;

    /* Audio */
    if (session->payload_type == msi_TypeAudio % 128) {
        pthread_mutex_lock(cs->queue_mutex);
        int ret = jbuf_write(cs->j_buf, msg);
        pthread_mutex_unlock(cs->queue_mutex);

        if (ret == -1) {
            rtp_free_msg(NULL, msg);
        }
    }
    /* Video */
    else {
        uint8_t *packet = msg->data;
        uint32_t packet_size = msg->length;

        if (packet_size < VIDEOFRAME_HEADER_SIZE)
            goto end;

        uint8_t diff = packet[0] - cs->frameid_in;

        if (diff != 0) {
            if (diff < 225) { /* New frame */
                /* Flush last frames' data and get ready for this frame */
                Payload *p = malloc(sizeof(Payload) + cs->frame_size);

                if (p) {
                    pthread_mutex_lock(cs->queue_mutex);

                    if (buffer_full(cs->vbuf_raw)) {
                        LOGGER_DEBUG("Dropped video frame");
                        Payload *tp;
                        buffer_read(cs->vbuf_raw, &tp);
                        free(tp);
                    } else {
                        p->size = cs->frame_size;
                        memcpy(p->data, cs->frame_buf, cs->frame_size);
                    }

                    buffer_write(cs->vbuf_raw, p);
                    pthread_mutex_unlock(cs->queue_mutex);
                } else {
                    LOGGER_WARNING("Allocation failed! Program might misbehave!");
                    goto end;
                }

                cs->last_timestamp = msg->header->timestamp;
                cs->frameid_in = packet[0];
                memset(cs->frame_buf, 0, cs->frame_size);
                cs->frame_size = 0;

            } else { /* Old frame; drop */
                LOGGER_DEBUG("Old packet: %u", packet[0]);
                goto end;
            }
        }

        uint8_t piece_number = packet[1];

        uint32_t length_before_piece = ((piece_number - 1) * cs->video_frame_piece_size);
        uint32_t framebuf_new_length = length_before_piece + (packet_size - VIDEOFRAME_HEADER_SIZE);

        if (framebuf_new_length > cs->max_video_frame_size) {
            goto end;
        }

        /* Otherwise it's part of the frame so just process */
        /* LOGGER_DEBUG("Video Packet: %u %u", packet[0], packet[1]); */

        memcpy(cs->frame_buf + length_before_piece,
               packet + VIDEOFRAME_HEADER_SIZE,
               packet_size - VIDEOFRAME_HEADER_SIZE);

        if (framebuf_new_length > cs->frame_size) {
            cs->frame_size = framebuf_new_length;
        }

end:
        rtp_free_msg(NULL, msg);
    }
}
コード例 #12
0
ファイル: main.c プロジェクト: datafl4sh/seatalk
int main(int argc, char** argv) {

    int i,r;
    int rbuf[20];
    int data;
    int format;
    processor_init();
    uart1_init();
    uart2_init();

    TRISDbits.TRISD0 = 0;
    TRISBbits.TRISB12 = 0;
    TRISBbits.TRISB11 = 0;

    TRISBbits.TRISB0 = 1;
    TRISBbits.TRISB1 = 1;
    TRISBbits.TRISB2 = 1;
    ADPCFGbits.PCFG0 = 1;
    ADPCFGbits.PCFG1 = 1;
    ADPCFGbits.PCFG2 = 1;

    ledstatus = 0;

    cb = buffer_init();

    while(1)
    {
        if ( buffer_full(cb) )
            /* Signal buffer overflow */
            PORTDbits.RD0 = 1;

        if ( !buffer_empty(cb) )
        {
            int data;

            /* Get a 'char' from the buffer */
            buffer_read(cb, &data);

            if ( data & 0x0100 )
            {

                format = (~PORTB) & 0x3;
                /* Print the last sentence and begin reading the new one */
                PORTBbits.RB12 = 1;
                //transmit_raw_buffer(rbuf, r);
                process_seatalk_string(rbuf, r, format);
                PORTBbits.RB12 = 0;
                r = 0;
                rbuf[r++] = data;
            }

            else
            {
                /* Accumulate data into the buffer */
                //printf("rx: %x\n",data);
                rbuf[r++] = data;
            }

        }
    }

    return (EXIT_SUCCESS);
}