示例#1
1
static void
shell_recorder_src_init (ShellRecorderSrc      *src,
                         ShellRecorderSrcClass *klass)
{
    src->queue = g_async_queue_new ();
    src->mutex = g_mutex_new ();
}
示例#2
0
文件: iris-thread.c 项目: antono/iris
/**
 * iris_thread_new:
 * @exclusive: the thread is exclusive
 *
 * Createa a new #IrisThread instance that can be used to queue work items
 * to be processed on the thread.
 *
 * If @exclusive, then the thread will not yield to the scheduler and
 * therefore will not participate in scheduler thread balancing.
 *
 * Return value: the newly created #IrisThread instance
 */
IrisThread*
iris_thread_new (gboolean exclusive)
{
	IrisThread *thread;

	iris_debug (IRIS_DEBUG_THREAD);

#if LINUX
#elif defined(WIN32)
	g_once (&my_thread_once, (GThreadFunc)_winthreads_init, NULL);
#else
	pthread_once (&my_thread_once, _pthread_init);
#endif

	thread = g_slice_new0 (IrisThread);
	thread->exclusive = exclusive;
	thread->queue = g_async_queue_new ();
	thread->mutex = g_mutex_new ();
	thread->thread  = g_thread_create_full ((GThreadFunc)iris_thread_worker,
	                                        thread,
	                                        0,     /* stack size    */
	                                        FALSE, /* joinable      */
	                                        FALSE, /* system thread */
	                                        G_THREAD_PRIORITY_NORMAL,
	                                        NULL);
	thread->scheduler = NULL;

	return thread;
}
static void gst_scream_queue_init(GstScreamQueue *self)
{
    self->sink_pad = gst_pad_new_from_static_template(&sink_template, "sink");
    gst_pad_set_chain_function(self->sink_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_sink_chain));
    gst_pad_set_event_function(self->sink_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_sink_event));
    GST_PAD_SET_PROXY_CAPS(self->sink_pad);
    gst_element_add_pad(GST_ELEMENT(self), self->sink_pad);

    self->src_pad = gst_pad_new_from_static_template(&src_template, "src");
    gst_pad_set_event_function(self->src_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_src_event));
    GST_PAD_SET_PROXY_CAPS(self->src_pad);
    gst_element_add_pad(GST_ELEMENT(self), self->src_pad);

    g_rw_lock_init(&self->lock);
    self->streams = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify) destroy_stream);
    self->adapted_stream_ids = g_hash_table_new(NULL, NULL);
    self->ignored_stream_ids = g_hash_table_new(NULL, NULL);

    self->scream_controller_id = DEFAULT_GST_SCREAM_CONTROLLER_ID;
    self->scream_controller = NULL;
    self->approved_packets = gst_data_queue_new(
        (GstDataQueueCheckFullFunction)fake_queue_check_full_cb,
        NULL, NULL, self);

    self->incoming_packets = g_async_queue_new();

    self->priority = DEFAULT_PRIORITY;
    self->pass_through = DEFAULT_PASS_THROUGH;
    self->next_approve_time = 0;
}
示例#4
0
文件: emc_server.c 项目: regit/nufw
int emc_init_server(struct emc_server_context *ctx)
{
	int result;
	int max_workers;
	char *emc_data_file;

	g_thread_init(NULL);

	max_workers = emc_config_table_get_or_default_int("emc_max_workers", EMC_DEFAULT_MAX_WORKERS);
	emc_data_file = emc_config_table_get("emc_data_file");

	ctx->nuauth_directory = g_tree_new( emc_netmask_order_func );

	result = emc_parse_datafile(ctx, emc_data_file);
	if (result < 0) {
		return -1;
	}

	loop = ev_default_loop(0);

	result = emc_setup_servers(loop, ctx);
	if (result < 0) {
		return -1;
	}

	ev_signal_init(&sigint_watcher, sigint_cb, SIGINT);
	ev_signal_start(loop, &sigint_watcher);

	ev_signal_init(&sigterm_watcher, sigint_cb, SIGTERM);
	ev_signal_start(loop, &sigterm_watcher);

	ev_signal_init(&sigusr1_watcher, sigusr1_cb, SIGUSR1);
	ev_signal_start(loop, &sigusr1_watcher);

	ev_async_init(&client_ready_signal, emc_client_ready_cb);
	ev_async_start(loop, &client_ready_signal);

	ctx->continue_processing = 1;
	sigint_watcher.data = ctx;
	sigterm_watcher.data = ctx;
	sigusr1_watcher.data = ctx;
	client_ready_signal.data = ctx;

	g_thread_pool_set_max_unused_threads( (int)(max_workers/2) );

	ctx->pool_tls_handshake = g_thread_pool_new((GFunc)emc_worker_tls_handshake, NULL,
						    max_workers, FALSE,
						    NULL);
	ctx->pool_reader = g_thread_pool_new((GFunc)emc_worker_reader, NULL,
						    max_workers, FALSE,
						    NULL);

	ctx->work_queue = g_async_queue_new();

	ctx->tls_client_list_mutex = g_mutex_new();

	log_printf(DEBUG_LEVEL_DEBUG, "Max: %d", g_thread_pool_get_max_unused_threads());

	return 0;
}
示例#5
0
int main ()
{
  appdata ad;

  // init 
  ad.gloop = g_main_loop_new (NULL, FALSE);
  ad.queue = g_async_queue_new ();
  ad.stop_thread = FALSE;

  // get item per sec
  g_timeout_add (1000, mainloop_callback, &ad);

  // make thread
  ad.thread = g_thread_new ("test_thread", (GThreadFunc)thread_func, &ad);

  // start mainloop
  g_main_loop_run (ad.gloop);
  
  


  // fin
  g_async_queue_unref (ad.queue);
  g_main_loop_unref (ad.gloop);

  return 0;
}
示例#6
0
ManglerAudio::ManglerAudio(int type, uint32_t rate, uint8_t channels, uint32_t pcm_framesize, uint8_t buffer, bool check_loggedin) {/*{{{*/
    this->type           = type;
    this->rate           = rate;
    this->channels       = channels;
    this->pcm_framesize  = pcm_framesize;
    this->buffer         = buffer;
    this->check_loggedin = check_loggedin;
    outputStreamOpen = false;
    inputStreamOpen = false;
    backend = NULL;
    if (type < AUDIO_INPUT || !rate) {
        return;
    }
    if (type >= AUDIO_OUTPUT) {
        if (!open()) {
            return;
        }
        outputStreamOpen = true;
        stop_output = false;
        pcm_queue = g_async_queue_new();
        Glib::Thread::create(sigc::mem_fun(*this, &ManglerAudio::output), false);
    } else {
        if (!pcm_framesize) {
            fprintf(stderr, "pcm frame size not specified on input stream open; unsupported codec?\n");
            return;
        }
        if (!open()) {
            return;
        }
        inputStreamOpen = true;
        stop_input = false;
        Glib::Thread::create(sigc::mem_fun(*this, &ManglerAudio::input), false);
    }
}/*}}}*/
/**
 * g_async_queue_new_full:
 * @item_free_func: function to free queue elements
 * 
 * Creates a new asynchronous queue with an initial reference count of 1 and
 * sets up a destroy notify function that is used to free any remaining
 * queue items when the queue is destroyed after the final unref.
 *
 * Return value: the new #GAsyncQueue.
 *
 * Since: 2.16
 **/
GAsyncQueue*
g_async_queue_new_full (GDestroyNotify item_free_func)
{
  GAsyncQueue *async_queue = g_async_queue_new ();
  async_queue->item_free_func = item_free_func;
  return async_queue;
}
示例#8
0
文件: worker.c 项目: ayyi/libwaveform
void
wf_worker_init(WfWorker* worker)
{
	worker->msg_queue = g_async_queue_new();

#ifdef HAVE_GLIB_2_32
	if(!g_thread_new("file load thread", worker_thread, worker)){
		perr("error creating thread\n");
#else
	GError* error = NULL;
	if(!g_thread_create(worker_thread, worker, false, &error)){
		perr("error creating thread: %s\n", error->message);
		g_error_free(error);
#endif
	}
}


	typedef struct {
		WfWorker*  worker;
		QueueItem* job;
	} WorkerJob;

	// note that withoug an idle fn, unreffing in the worker can cause a finalize in the worker thread
	static bool worker_unref_waveform(gpointer _w)
	{
		Waveform* waveform = _w;
		g_object_unref(waveform); // remove the reference added by g_weak_ref_get()
		return G_SOURCE_REMOVE;
	}
//
// Constructor
//
CNewFilesBox::CNewFilesBox(void):CInfoBox("Process new frames"), m_Thread(NULL), 
	m_StopThread(false), m_SuspendRq(false), m_Delay(false), m_OutFiles(0), 
	m_ExitCode(0), m_State(STATE_STOP), m_Proc(NULL)
{
	GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
	gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
	gtk_box_pack_start(GTK_BOX(m_Box), hbox, FALSE, TRUE, 0);

	// Two text lines
	GtkWidget *vbox = gtk_vbox_new(TRUE, 8);
	gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
	m_Line1 = gtk_label_new(NULL);
	gtk_misc_set_alignment(GTK_MISC(m_Line1), 0, 0.5);
	gtk_box_pack_start(GTK_BOX(vbox), m_Line1, TRUE, TRUE, 0);
	m_Line2 = gtk_label_new(NULL);
	gtk_misc_set_alignment(GTK_MISC(m_Line2), 0, 0.5);
	gtk_box_pack_start(GTK_BOX(vbox), m_Line2, TRUE, TRUE, 0);

	// Button box
	GtkWidget *bbox = gtk_vbutton_box_new();
	gtk_box_pack_start(GTK_BOX(hbox), bbox, FALSE, TRUE, 0);
	m_CancelBtn = gtk_button_new_with_label("Cancel");
	gtk_box_pack_start(GTK_BOX(bbox), m_CancelBtn, FALSE, TRUE, 0);
	g_signal_connect(m_CancelBtn, "clicked", G_CALLBACK(cancel_clicked), this);
	m_PauseBtn = gtk_button_new_with_label("Pause");
	gtk_box_pack_start(GTK_BOX(bbox), m_PauseBtn, FALSE, TRUE, 0);
	g_signal_connect(m_PauseBtn, "clicked", G_CALLBACK(pause_clicked), this);

	m_Con = new CNFConsole(this);
	m_Queue = g_async_queue_new();
	m_DataMutex = g_mutex_new();
	m_Cond = g_cond_new();
}
示例#10
0
static void thread_init(global_conf_st * g_conf)
{
    int i;
    pthread_mutex_init(&init_lock,NULL);
    pthread_cond_init(&init_cond,NULL);
    
    int nthreads = g_conf->max_thread;
    threads = calloc(nthreads,sizeof(work_thread));
    if(!threads){
	fprintf(stderr,"%s:%d :Cant allocate threads info",__FILE__,__LINE__);
	exit(-1);
    }
    for(i = 0 ;i < nthreads;i++){
	threads[i].g_conf = g_conf;
	threads[i].msg_queue = g_async_queue_new();
    }
    for(i = 0 ;i < nthreads;i++){
	create_worker(worker_thread,&threads[i]);
    }
    pthread_mutex_lock(&init_lock);
    while(init_count < nthreads){
	pthread_cond_wait(&init_cond,&init_lock);
    }
    pthread_mutex_unlock(&init_lock);
}
static void
ide_git_buffer_change_monitor_class_init (IdeGitBufferChangeMonitorClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  IdeBufferChangeMonitorClass *parent_class = IDE_BUFFER_CHANGE_MONITOR_CLASS (klass);

  object_class->dispose = ide_git_buffer_change_monitor_dispose;
  object_class->finalize = ide_git_buffer_change_monitor_finalize;
  object_class->set_property = ide_git_buffer_change_monitor_set_property;

  parent_class->set_buffer = ide_git_buffer_change_monitor_set_buffer;
  parent_class->get_change = ide_git_buffer_change_monitor_get_change;

  gParamSpecs [PROP_REPOSITORY] =
    g_param_spec_object ("repository",
                         _("Repository"),
                         _("The repository to use for calculating diffs."),
                         GGIT_TYPE_REPOSITORY,
                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);

  gWorkQueue = g_async_queue_new ();
  gWorkThread = g_thread_new ("IdeGitBufferChangeMonitorWorker",
                              ide_git_buffer_change_monitor_worker,
                              gWorkQueue);
}
示例#12
0
文件: ipc.c 项目: aidanholm/luakit
void
ipc_send(ipc_endpoint_t *ipc, const ipc_header_t *header, const void *data)
{
    if (!send_thread) {
        send_queue = g_async_queue_new();
        send_thread = g_thread_new("send_thread", ipc_send_thread, NULL);
    }

    /* Keep the endpoint alive while the message is being sent */
    if (!ipc_endpoint_incref(ipc))
        return;

    if (header->type != IPC_TYPE_log)
        debug("Process '%s': send " ANSI_COLOR_BLUE "%s" ANSI_COLOR_RESET " message",
                ipc->name, ipc_type_name(header->type));

    g_assert((header->length == 0) == (data == NULL));

    /* Alloc and push a queued message; the send thread frees it */
    queued_ipc_t *msg = g_malloc(sizeof(*msg) + header->length);
    msg->ipc = ipc;
    msg->header = *header;
    if (header->length)
        memcpy(msg->payload, data, header->length);

    if (ipc->channel)
        g_async_queue_push(send_queue, msg);
    else
        g_queue_push_tail(ipc->queue, msg);
}
示例#13
0
int v9fs_init_worker_threads(void)
{
    int ret = 0;
    V9fsThPool *p = &v9fs_pool;
    sigset_t set, oldset;

    sigfillset(&set);
    /* Leave signal handling to the iothread.  */
    pthread_sigmask(SIG_SETMASK, &set, &oldset);

    p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
    if (!p->pool) {
        ret = -1;
        goto err_out;
    }
    p->completed = g_async_queue_new();
    if (!p->completed) {
        /*
         * We are going to terminate.
         * So don't worry about cleanup
         */
        ret = -1;
        goto err_out;
    }
    event_notifier_init(&p->e, 0);

    event_notifier_set_handler(&p->e, v9fs_qemu_process_req_done);
err_out:
    pthread_sigmask(SIG_SETMASK, &oldset, NULL);
    return ret;
}
示例#14
0
/**
 * oh_create_session
 * @did:
 *
 *
 *
 * Returns:
 **/
SaHpiSessionIdT oh_create_session(SaHpiDomainIdT did)
{
        struct oh_session *session = NULL;
        struct oh_domain *domain = NULL;
        static SaHpiSessionIdT id = 1;        /* Session ids will start at 1 */

        if (did == SAHPI_UNSPECIFIED_DOMAIN_ID)
                did = OH_DEFAULT_DOMAIN_ID;

        session = g_new0(struct oh_session, 1);
        if (!session)
                return 0;

        session->did = did;
        session->eventq = g_async_queue_new();
        session->subscribed = SAHPI_FALSE;

        domain = oh_get_domain(did);
        if (!domain) {
                g_async_queue_unref(session->eventq);
                g_free(session);
                return 0;
        }
        wrap_g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
        session->id = id++;
        g_hash_table_insert(oh_sessions.table, &(session->id), session);
        oh_sessions.list = g_slist_append(oh_sessions.list, session);
        wrap_g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
        oh_release_domain(domain);

        return session->id;
}
示例#15
0
struct gridd_client_pool_s *
gridd_client_pool_create(void)
{
	int fdmon, fd[2];
	struct gridd_client_pool_s *pool;

	if (0 != pipe(fd)) {
		GRID_WARN("pipe() error: (%d) %s", errno, strerror(errno));
		metautils_pclose(&(fd[0]));
		metautils_pclose(&(fd[1]));
		return NULL;
	}

	if (0 > (fdmon = epoll_create(64))) {
		GRID_WARN("epoll_create error: (%d) %s", errno, strerror(errno));
		metautils_pclose(&(fd[0]));
		metautils_pclose(&(fd[1]));
		return NULL;
	}

	// TODO FIXME factorize this in metautils
	struct rlimit limit;
	memset(&limit, 0, sizeof(limit));
	if (0 != getrlimit(RLIMIT_NOFILE, &limit))
		limit.rlim_cur = limit.rlim_max = 32768;

	pool = g_malloc0(sizeof(*pool));
	pool->pending_clients = g_async_queue_new();

	pool->fdmon = fdmon;
	pool->active_max = limit.rlim_cur;
	pool->active_clients_size = limit.rlim_cur;
	pool->active_clients = g_malloc0(pool->active_clients_size
			* sizeof(struct event_client_s*));

	pool->fd_in = fd[0];
	fd[0] = -1;
	metautils_syscall_shutdown(pool->fd_in, SHUT_WR);
	sock_set_non_blocking(pool->fd_in, TRUE);

	pool->fd_out = fd[1];
	fd[1] = -1;
	metautils_syscall_shutdown(pool->fd_out, SHUT_RD);
	sock_set_non_blocking(pool->fd_out, TRUE);

	/* then monitors at least the notifications pipe's output */
	struct epoll_event ev;
	memset(&ev, 0, sizeof(ev));
	ev.events = EPOLLIN;
	ev.data.fd = pool->fd_in;
	if (0 > epoll_ctl(pool->fdmon, EPOLL_CTL_ADD, pool->fd_in, &ev)) {
		GRID_ERROR("epoll error: (%d) %s", errno, strerror(errno));
		gridd_client_pool_destroy(pool);
		return NULL;
	}

	pool->vtable = &VTABLE;
	return pool;
}
示例#16
0
static bool uart_init() {

	int ptm;

	struct termios tattr;

	for (int i = 0; i < NUMOFCHANNELS; i++) {
		log_println(LEVEL_INFO, TAG, "Opening PTY for channel %d", i);
		ptm = posix_openpt(O_RDWR | O_NOCTTY);
		if (ptm == -1) {
			log_println(LEVEL_INFO, TAG, "failed opening PTY!");
			return false;
		} else {
			if (grantpt(ptm) < 0) {
				log_println(LEVEL_INFO, TAG, "failed granting PTY!");
				return false;
			}
			if (unlockpt(ptm) < 0) {
				log_println(LEVEL_INFO, TAG, "failed unlocking PTY!");
				return false;
			}

			log_println(LEVEL_INFO, TAG, "Channel %d pts is %s", i,
					ptsname(ptm));
			channels[i].ptm = ptm;
			tcgetattr(ptm, &tattr);
			cfmakeraw(&tattr);
			tcsetattr(ptm, 0, &tattr);

			int flags = fcntl(ptm, F_GETFL);
			if (!(flags & O_NONBLOCK)) {
				fcntl(ptm, F_SETFL, flags | O_NONBLOCK);
			}
		}

		channels[i].txfifo = g_async_queue_new();
		channels[i].rxfifo = g_async_queue_new();
		uart_reset_channel(&(channels[i]));

		pollfds[i].fd = channels[i].ptm;
		pollfds[i].events = POLL_IN;

	}

	return true;
}
示例#17
0
static void
ephy_history_service_init (EphyHistoryService *self)
{
  self->priv = EPHY_HISTORY_SERVICE_GET_PRIVATE (self);

  self->priv->history_thread = g_thread_new ("EphyHistoryService", (GThreadFunc) run_history_service_thread, self);
  self->priv->queue = g_async_queue_new ();
}
示例#18
0
void *sim_open(GHashTable *handler_config)
{
    struct oh_handler_state *state = NULL;
    char *tok = NULL;

    if (!handler_config) {
        dbg("GHashTable *handler_config is NULL!");
        return NULL;
    }
    /* check for required hash table entries */
    tok = g_hash_table_lookup(handler_config, "entity_root");
    if (!tok) {
        dbg("entity_root is needed and not present in conf");
        return NULL;
    }
    tok = g_hash_table_lookup(handler_config, "handler_name");
    if (!tok) {
        dbg("handler_name is needed and not present in conf");
        return NULL;
    }

    state = g_malloc0(sizeof(struct oh_handler_state));
    if (!state) {
        dbg("out of memory");
        return NULL;
    }

    /* initialize rpt hashtable pointer */
    state->rptcache = (RPTable *)g_malloc0(sizeof(RPTable));
    oh_init_rpt(state->rptcache);

    /* initialize the event log */
    state->elcache = oh_el_create(256);
    if (!state->elcache) {
        dbg("Event log creation failed");
        g_free(state->rptcache);
        g_free(state);
        return NULL;
    }

    /* initialize the async event queue */
    if (!(state->eventq_async = g_async_queue_new())) {
        dbg("Async event log creation failed");
        g_free(state->rptcache);
        oh_el_close(state->elcache);
        g_free(state);
        return NULL;
    }

    /* save the handler config hash table it holds  */
    /* the openhpi.conf file config info            */
    state->config = handler_config;

    /* save the handler state to our list */
    sim_handler_states = g_slist_append(sim_handler_states, state);

    return (void *)state;
}
示例#19
0
static void
rb_mtp_thread_init (RBMtpThread *thread)
{
	thread->queue = g_async_queue_new ();
	
	thread->albums = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) LIBMTP_destroy_album_t);

	thread->thread = g_thread_create ((GThreadFunc) task_thread, thread, TRUE, NULL);		/* XXX should handle errors i guess */
}
示例#20
0
void queueTest() {
	gpointer *data;
	queue1 = g_async_queue_new();
	printf("Queue test\n");
	while(1) {
		data=g_async_queue_pop(queue1);
		printf("Data received\n");
	}	
}
示例#21
0
void li_job_queue_init(liJobQueue* jq, liEventLoop *loop) {
	li_event_prepare_init(loop, &jq->prepare_watcher, job_queue_prepare_cb);
	li_event_async_init(loop, &jq->async_queue_watcher, job_async_queue_cb);
	li_event_timer_init(loop, &jq->queue_watcher, job_queue_watcher_cb);

	/* job queue */
	g_queue_init(&jq->queue);
	jq->async_queue = g_async_queue_new();
}
示例#22
0
static void
start_pipeline (GstElement * element)
{
  id = gst_pad_add_probe (mysinkpad, GST_PAD_PROBE_TYPE_BUFFER,
      (GstPadProbeCallback) buffer_probe, NULL, NULL);

  pending_buffers = g_async_queue_new ();
  gst_element_set_state (element, GST_STATE_PLAYING);
}
示例#23
0
int
DM_init()
{
	pthread_t thr;

	ioq = g_async_queue_new();
	pthread_create(&thr, NULL, ioq_handler, 0);
	return 0;
}
static void
shell_recorder_src_init (ShellRecorderSrc      *src)
{
    gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);

    src->queue = g_async_queue_new ();
    src->mutex = &src->mutex_data;
    g_mutex_init (src->mutex);
}
示例#25
0
/*!
 \brief Issues a packet to the ECU to get its revision information. 
 \param length is a pointer to a location to store the length of the data
 received, or NULL
 \returns the Firmware version as a text string
 */
G_MODULE_EXPORT gchar *raw_request_firmware_version(gint *length)
{
	OutputData *output = NULL;
	GAsyncQueue *queue = NULL;
	FreeEMS_Packet *packet = NULL;
	gchar *version = NULL;
	GTimeVal tval;
	Serial_Params *serial_params = NULL;
	/* Raw packet */
	guint8 *buf = NULL;
	gint len = FIRMWARE_VERSION_REQ_PKT_LEN;
	guint8 pkt[FIRMWARE_VERSION_REQ_PKT_LEN];
	gint req = REQUEST_FIRMWARE_VERSION;
	gint resp = RESPONSE_FIRMWARE_VERSION;
	gint res = 0;
	gint i = 0;
	guint8 sum = 0;
	gint tmit_len = 0;

	serial_params = DATA_GET(global_data,"serial_params");
	g_return_val_if_fail(serial_params,NULL);

	if (DATA_GET(global_data,"offline"))
		return g_strdup("Offline");

	pkt[HEADER_IDX] = 0;
	pkt[H_PAYLOAD_IDX] = (req & 0xff00 ) >> 8;
	pkt[L_PAYLOAD_IDX] = (req & 0x00ff );
	for (i=0;i<len-1;i++)
		sum += pkt[i];
	pkt[len-1] = sum;
	buf = finalize_packet((guint8 *)&pkt,len,&tmit_len);
	queue = g_async_queue_new();
	register_packet_queue(PAYLOAD_ID,queue,resp);
	if (!write_wrapper_f(serial_params->fd,buf, tmit_len, NULL))
	{
		deregister_packet_queue(PAYLOAD_ID,queue,resp);
		g_free(buf);
		g_async_queue_unref(queue);
		return NULL;
	}
	g_free(buf);
	g_get_current_time(&tval);
	g_time_val_add(&tval,500000);
	packet = g_async_queue_timed_pop(queue,&tval);
	deregister_packet_queue(PAYLOAD_ID,queue,resp);
	g_async_queue_unref(queue);
	if (packet)
	{
		version = g_strndup((const gchar *)(packet->data+packet->payload_base_offset),packet->payload_length);
		if (length)
			*length = packet->payload_length;
		freeems_packet_cleanup(packet);
	}
	return version;
}
/* should only be called once on initialization */
void
dropbox_command_client_setup(DropboxCommandClient *dcc) {
  dcc->command_queue = g_async_queue_new();
  dcc->command_connected_mutex = g_mutex_new();
  dcc->command_connected = FALSE;
  dcc->ca_hooklist = NULL;

  g_hook_list_init(&(dcc->ondisconnect_hooklist), sizeof(GHook));
  g_hook_list_init(&(dcc->onconnect_hooklist), sizeof(GHook));
}
示例#27
0
static void
yelp_transform_init (YelpTransform *transform)
{
    YelpTransformPrivate *priv = GET_PRIV (transform);
    priv->queue = g_async_queue_new ();
    priv->chunks = g_hash_table_new_full (g_str_hash,
                                          g_str_equal,
                                          g_free,
                                          NULL);
}
示例#28
0
static void
byzanz_queue_init (ByzanzQueue *queue)
{
  queue->files = g_async_queue_new ();

  queue->input = byzanz_queue_input_stream_new (queue);
  queue->output = byzanz_queue_output_stream_new (queue);

  queue->shared_count = 3;
}
示例#29
0
/**
 * Inits main server's structure
 * @param argc : number of arguments given on the command line.
 * @param argv : an array of strings that contains command line arguments.
 * @returns a server_struct_t * structure that contains everything that is
 *          needed for 'cdpfglserver' program.
 */
static server_struct_t *init_server_main_structure(int argc, char **argv)
{
    server_struct_t *server_struct = NULL;  /** main structure for 'server' program. */

    server_struct = (server_struct_t *) g_malloc0(sizeof(server_struct_t));

    server_struct->data_thread = NULL;
    server_struct->meta_thread = NULL;
    server_struct->opt = do_what_is_needed_from_command_line_options(argc, argv);
    server_struct->d = NULL;            /* libmicrohttpd daemon pointer */
    server_struct->meta_queue = g_async_queue_new();
    server_struct->data_queue = g_async_queue_new();
    server_struct->loop = NULL;

    /* default backend (file_backend) */
    server_struct->backend = init_backend_structure(file_store_smeta, file_store_data, file_init_backend, file_build_needed_hash_list, file_get_list_of_files, file_retrieve_data);

    return server_struct;
}
示例#30
0
文件: worker.c 项目: EQ4/samplecat
void
worker_thread_init()
{
	dbg(3, "creating overview thread...");

	msg_queue = g_async_queue_new();

	if(!g_thread_new("worker", worker_thread, NULL)){
		perr("failed to create worker thread");
	}
}