コード例 #1
0
ファイル: engine.c プロジェクト: fizx/sit
Engine *
engine_new(Parser *parser, pstring *data_dir, long size, bool dedupe, pstring *auth) {
  Engine *engine = calloc(1, sizeof(Engine));
	engine->queries = dictCreate(getTermQueryNodeDict(), 0);
	engine->parser = parser;
	engine->query_id = 0;
  engine->catchall_callbacks = NULL;
	engine->after_on_document = NULL;
	engine->stream = ring_buffer_new(size / 4);
  engine->term_dictionary = lrw_dict_new(getTermPlistDict(), size / 32);
	engine->postings = plist_pool_new(size / 4);
	engine->docs = ring_buffer_new((size / 4 / sizeof(DocRef)) * sizeof(DocRef));
	engine->data = NULL;
	if(auth) {
    engine->auth = pcpy(auth);
  }
	engine->ints_capacity = size / 4;
	engine->ints = dictCreate(getPstrRingBufferDict(), 0);
  if(data_dir) {
    engine->data_dir = pcpy(data_dir);
    engine_replay_journal(engine);
    engine_reopen_journal(engine);
  }
	if(dedupe) {
    engine->doc_set = dictCreate(getDocRefDict(), engine);
    engine->docs->on_evict = callback_new(_doc_evict, engine);	  
	} else {
    engine->doc_set = NULL;
	}
  engine->error = NULL;
	return engine;
}
コード例 #2
0
ファイル: engine.c プロジェクト: fizx/sit
void
engine_set_int(Engine *engine, long doc_id, pstring *field, int value) {
  //FIXME?!
  RingBuffer *rb = dictFetchValue(engine->ints, field);
  assert(field);
  if(rb == NULL) {
    rb = ring_buffer_new(engine->ints_capacity);
    dictAdd(engine->ints, field, rb);
  }
  ring_buffer_put(rb, doc_id * sizeof(int), &value, sizeof(int));
}
コード例 #3
0
ファイル: gathdlc.c プロジェクト: yongsu/oFono
GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
{
	GAtHDLC *hdlc;
	unsigned char *buf;

	if (io == NULL)
		return NULL;

	hdlc = g_try_new0(GAtHDLC, 1);
	if (hdlc == NULL)
		return NULL;

	hdlc->ref_count = 1;
	hdlc->decode_fcs = HDLC_INITFCS;
	hdlc->decode_offset = 0;
	hdlc->decode_escape = FALSE;

	hdlc->xmit_accm[0] = ~0U;
	hdlc->xmit_accm[3] = 0x60000000; /* 0x7d, 0x7e */
	hdlc->recv_accm = ~0U;

	hdlc->write_buffer = ring_buffer_new(BUFFER_SIZE * 2);
	if (!hdlc->write_buffer)
		goto error;

	/* Write an initial 0x7e as wakeup character */
	buf = ring_buffer_write_ptr(hdlc->write_buffer, 0);
	*buf = HDLC_FLAG;
	ring_buffer_write_advance(hdlc->write_buffer, 1);

	hdlc->decode_buffer = g_try_malloc(BUFFER_SIZE * 2);
	if (!hdlc->decode_buffer)
		goto error;

	hdlc->record_fd = -1;

	hdlc->io = g_at_io_ref(io);
	g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc);

	return hdlc;

error:
	if (hdlc->write_buffer)
		ring_buffer_free(hdlc->write_buffer);

	if (hdlc->decode_buffer)
		g_free(hdlc->decode_buffer);

	g_free(hdlc);

	return NULL;
}
コード例 #4
0
ファイル: test.c プロジェクト: chris1287/RingBuffer
int main(int argc, const char *argv[])
{
	t_ring_buffer *r = NULL;
	int elem1 = 4;
	int elem2 = 6;
	int elem3 = 2;
	int elem4 = 3;
	gpointer oldelem = NULL;
	gpointer popelem = NULL;

	g_message("Test RingBuffer");
	
	r = ring_buffer_new(2);
	g_assert(NULL != r);

	oldelem = ring_buffer_push(r, &elem1);
	g_assert(NULL == oldelem);
	g_assert(1 == ring_buffer_stored_elements(r));

	oldelem = ring_buffer_push(r, &elem2);
	g_assert(NULL == oldelem);
	g_assert(2 == ring_buffer_stored_elements(r));
	
	oldelem = ring_buffer_push(r, &elem3);
	g_assert(NULL != oldelem && *((int *)oldelem) == elem1);
	g_assert(2 == ring_buffer_stored_elements(r));
	
	oldelem = ring_buffer_push(r, &elem4);
	g_assert(NULL != oldelem && *((int *)oldelem) == elem2);

	popelem = ring_buffer_pop(r);
	g_assert(NULL != popelem && *((int *)popelem) == elem4);

	popelem = ring_buffer_pop(r);
	g_assert(NULL != popelem && *((int *)popelem) == elem3);

	popelem = ring_buffer_pop(r);
	g_assert(NULL == popelem);
	g_assert(0 == ring_buffer_stored_elements(r));

	r = ring_buffer_free(r);
	g_assert(NULL == r);

	g_message("Test RingBuffer complete");

	return 0;
}
コード例 #5
0
ファイル: grilio.c プロジェクト: saukko/ofono
static GRilIO *create_io(GIOChannel *channel, GIOFlags flags)
{
	GRilIO *io;

	if (channel == NULL)
		return NULL;

	io = g_try_new0(GRilIO, 1);
	if (io == NULL)
		return io;

	io->ref_count = 1;
	io->debugf = NULL;

	if (flags & G_IO_FLAG_NONBLOCK) {
		io->max_read_attempts = 3;
		io->use_write_watch = TRUE;
	} else {
		io->max_read_attempts = 1;
		io->use_write_watch = FALSE;
	}

	io->buf = ring_buffer_new(8192);

	if (!io->buf)
		goto error;

	if (!g_ril_util_setup_io(channel, flags))
		goto error;

	io->channel = channel;
	io->read_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
				received_data, io,
				read_watcher_destroy_notify);

	return io;

error:
	if (io->buf)
		ring_buffer_free(io->buf);

	g_free(io);

	return NULL;
}
コード例 #6
0
ファイル: gatmux.c プロジェクト: Conjuror/ofono
GIOChannel *g_at_mux_create_channel(GAtMux *mux)
{
	GAtMuxChannel *mux_channel;
	GIOChannel *channel;
	int i;

	for (i = 0; i < MAX_CHANNELS; i++) {
		if (mux->dlcs[i] == NULL)
			break;
	}

	if (i == MAX_CHANNELS)
		return NULL;

	mux_channel = g_try_new0(GAtMuxChannel, 1);
	if (mux_channel == NULL)
		return NULL;

	if (mux->driver->open_dlc)
		mux->driver->open_dlc(mux, i+1);

	channel = (GIOChannel *) mux_channel;

	g_io_channel_init(channel);
	channel->close_on_unref = TRUE;
	channel->funcs = &channel_funcs;

	channel->is_seekable = FALSE;
	channel->is_readable = TRUE;
	channel->is_writeable = TRUE;

	channel->do_encode = FALSE;

	mux_channel->mux = mux;
	mux_channel->dlc = i+1;
	mux_channel->buffer = ring_buffer_new(MUX_CHANNEL_BUFFER_SIZE);
	mux_channel->throttled = FALSE;

	mux->dlcs[i] = mux_channel;

	debug(mux, "created channel %p, dlc: %d", channel, i+1);

	return channel;
}
コード例 #7
0
ファイル: SoundSDL.c プロジェクト: ExPixel/visualboyadvance
SoundDriver *sound_sdl_init(GError **err) {
	g_return_val_if_fail(err == NULL || *err == NULL, NULL);

	SoundDriver *driver = g_new(SoundDriver, 1);
	driver->write = sound_sdl_write;
	driver->pause = sound_sdl_pause;
	driver->reset = sound_sdl_reset;

	guint sampleRate = settings_sound_sample_rate();

	SDL_InitSubSystem(SDL_INIT_AUDIO);

	SDL_AudioSpec audio;
	audio.freq = sampleRate;
	audio.format = AUDIO_S16SYS;
	audio.channels = 2;
	audio.samples = 1024;
	audio.callback = sound_sdl_callback;
	audio.userdata = driver;

	if (SDL_OpenAudio(&audio, NULL)) {
		g_set_error(err, SOUND_ERROR, G_SOUND_ERROR_FAILED,
				"Failed to open audio: %s", SDL_GetError());
		g_free(driver);
		return NULL;
	}

	DriverData *data = g_new(DriverData, 1);
	data->_rbuf = ring_buffer_new(delay * sampleRate * 2 * sizeof(guint16));
	data->_cond = SDL_CreateCond();
	data->_mutex = SDL_CreateMutex();
	data->_initialized = TRUE;
	data->sync = TRUE;

	driver->driverData = data;

	return driver;
}