/* The create() virtual function is responsible for returning the next buffer. * We just pop buffers off of the queue and block if necessary. */ static GstFlowReturn shell_recorder_src_create (GstPushSrc *push_src, GstBuffer **buffer_out) { ShellRecorderSrc *src = SHELL_RECORDER_SRC (push_src); GstBuffer *buffer; if (src->closed) return GST_FLOW_EOS; buffer = g_async_queue_pop (src->queue); if (src->last_frame_time == 0) src->last_frame_time = gst_clock_get_time (GST_CLOCK (src->clock)); if (buffer == RECORDER_QUEUE_END) { /* Returning UNEXPECTED here will cause a EOS message to be sent */ src->closed = TRUE; return GST_FLOW_EOS; } shell_recorder_src_update_memory_used (src, - (int)(gst_buffer_get_size(buffer) / 1024)); *buffer_out = buffer; GST_BUFFER_DURATION(*buffer_out) = GST_CLOCK_DIFF (src->last_frame_time, gst_clock_get_time (GST_CLOCK (src->clock))); src->last_frame_time = gst_clock_get_time (GST_CLOCK (src->clock)); return GST_FLOW_OK; }
/* The create() virtual function is responsible for returning the next buffer. * We just pop buffers off of the queue and block if necessary. */ static GstFlowReturn shell_recorder_src_create (GstPushSrc *push_src, GstBuffer **buffer_out) { ShellRecorderSrc *src = SHELL_RECORDER_SRC (push_src); GstBuffer *buffer; if (src->closed) return GST_FLOW_UNEXPECTED; buffer = g_async_queue_pop (src->queue); if (buffer == RECORDER_QUEUE_END) { /* Returning UNEXPECTED here will cause a EOS message to be sent */ src->closed = TRUE; return GST_FLOW_UNEXPECTED; } shell_recorder_src_update_memory_used (src, - (int)(GST_BUFFER_SIZE(buffer) / 1024)); *buffer_out = buffer; return GST_FLOW_OK; }
static void * worker_thread(void *arg) { work_thread * thread_info = (work_thread *)arg; GAsyncQueue *mq = thread_info->msg_queue; global_conf_st * g_conf = thread_info->g_conf; thread_info->ppid = pthread_self(); msg_st * msg; pthread_mutex_lock(&init_lock); init_count++; pthread_cond_signal(&init_cond); pthread_mutex_unlock(&init_lock); pthread_cleanup_push(cleanup,"exit"); while(1){ sleep(1); msg = (msg_st *)g_async_queue_pop(mq); if(NULL== msg) continue; decrMsgProcNum(); do_link_mining(g_conf,msg); //TODO:do link mining fprintf(stderr,"%d is runnning,one message from pnum(%s) processed\n",(int)thread_info->ppid,msg->src_pnum); sleep(1); free(msg); } pthread_cleanup_pop(1); pthread_exit(NULL); }
ArvBuffer * arv_stream_pop_buffer (ArvStream *stream) { g_return_val_if_fail (ARV_IS_STREAM (stream), NULL); return g_async_queue_pop (stream->priv->output_queue); }
gpointer probe_request_thread_func (gpointer user_data) { UDisksLinuxProvider *provider = UDISKS_LINUX_PROVIDER (user_data); ProbeRequest *request; do { request = g_async_queue_pop (provider->probe_request_queue); /* used by _finalize() above to stop this thread - if received, we can * no longer use @provider */ if (request == (gpointer) 0xdeadbeef) goto out; /* probe the device - this may take a while */ request->udisks_device = udisks_linux_device_new_sync (request->udev_device); /* now that we've probed the device, post the request back to the main thread */ g_idle_add (on_idle_with_probed_uevent, request); } while (TRUE); out: return NULL; }
PRIVATE gpointer req_thread( Generator *g ) { Data *data = g->data; GtkWidget *fs; while( 1 ) { gpointer ptr = g_async_queue_pop( data->req ); if( ptr == NULL ) break; else { gdk_threads_enter(); fs = gtk_file_selection_new("Select File"); gtk_object_set_data(GTK_OBJECT(fs), "Generator", g); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button), "clicked", GTK_SIGNAL_FUNC(access_output_file), fs); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(fs)); if (data->filename != NULL) gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), data->filename); gtk_window_set_modal(GTK_WINDOW(fs), TRUE); gtk_widget_show(fs); gdk_threads_leave(); } } return NULL; }
static void* hrt_thread_pool_thread(void *data) { HrtThreadPool *pool; void *thread_data; pool = HRT_THREAD_POOL(data); thread_data = (* pool->vtable->thread_data_new) (pool->vfunc_data); while (TRUE) { void *item; item = g_async_queue_pop(pool->queue); g_assert(item != NULL); if (item == shutting_down_item) { /* time to quit */ break; } else { (* pool->vtable->handle_item) (thread_data, item, pool->vfunc_data); } } (* pool->vtable->thread_data_free) (thread_data, pool->vfunc_data); g_object_unref(pool); return NULL; }
/* * execute client destruction task */ static void client_destructor_cb(struct ev_loop *loop, ev_async *w, int revents) { struct tls_user_context_t *context = (struct tls_user_context_t *) w->data; disconnect_user_msg_t *disconnect_msg; user_session_t *session; disconnect_msg = g_async_queue_pop(context->cmd_queue); if (disconnect_msg->socket == -1) { disconnect_msg->result = kill_all_clients(); } else { session = get_client_datas_by_socket(disconnect_msg->socket); if (session == NULL) { g_mutex_lock(disconnect_msg->mutex); disconnect_msg->result = NU_EXIT_ERROR; g_cond_signal(disconnect_msg->cond); g_mutex_unlock(disconnect_msg->mutex); unlock_client_datas(); return; } if (g_mutex_trylock(session->rw_lock)) { ev_io_stop(session->srv_context->loop, &session->client_watcher); disconnect_msg->result = delete_rw_locked_client(session); } else { session->pending_disconnect = TRUE; disconnect_msg->result = NU_EXIT_OK; } unlock_client_datas(); } g_mutex_lock(disconnect_msg->mutex); g_cond_signal(disconnect_msg->cond); g_mutex_unlock(disconnect_msg->mutex); }
void *process_queue(struct thread_data* td) { struct configuration *conf = td->conf; g_async_queue_push(conf->ready,GINT_TO_POINTER(1)); struct job* jb = NULL; struct migrate_job* mjb = NULL; for(;;) { jb = (struct job*)g_async_queue_pop(conf->queue); switch(jb->type) { case JOB_TEST1: mjb = (struct migrate_job *)jb->data; g_message("JOB_TEST1 in thread %d, keyname=%s" , td->thread_id, mjb->keyname); g_free(jb); break; case JOB_TEST2: g_message("JOB_TEST2 in thread %d", td->thread_id); g_free(jb); break; case JOB_SHUTDOWN: g_message("Thread %d shutting down", td->thread_id); g_free(jb); return NULL; break; } } }
static gpointer ide_git_buffer_change_monitor_worker (gpointer data) { GAsyncQueue *queue = data; GTask *task; g_assert (queue); while ((task = g_async_queue_pop (queue))) { IdeGitBufferChangeMonitor *self; DiffTask *diff; GError *error = NULL; self = g_task_get_source_object (task); diff = g_task_get_task_data (task); if (!ide_git_buffer_change_monitor_calculate_threaded (self, diff, &error)) g_task_return_error (task, error); else g_task_return_pointer (task, g_hash_table_ref (diff->state), (GDestroyNotify)g_hash_table_unref); g_object_unref (task); } return NULL; }
/* Our polling thread */ gpointer apollo_orbiter(gpointer gp_queue) { FinishedNotify * pn = gp_queue; g_async_queue_ref(pn->queue); while(TRUE) { g_print("\n-----------\n\n"); gpointer thread_data = g_async_queue_pop(pn->queue); if(thread_data == THREAD_TERMINATOR) { g_printerr("\n-- Terminating --\n"); break; } else { GlyrQuery * q = thread_data; GlyrMemCache * head = glyr_get(q,NULL,NULL); if(head != NULL) { g_print("//////// ITEM %d ////////\n",++pn->counter); glyr_cache_print(head); glyr_free_list(head); g_print("/////////////////////////\n"); } glyr_query_destroy(q); } } g_async_queue_unref(pn->queue); return NULL; }
RmHasherTask *rm_hasher_task_new(RmHasher *hasher, RmDigest *digest, gpointer task_user_data) { g_mutex_lock(&hasher->lock); { hasher->active_tasks++; } g_mutex_unlock(&hasher->lock); RmHasherTask *self = g_slice_new0(RmHasherTask); self->hasher = hasher; if(digest) { self->digest = digest; } else { self->digest = rm_digest_new(hasher->digest_type, 0, 0, 0, hasher->digest_type == RM_DIGEST_PARANOID); } /* get a recycled hashpipe if available */ self->hashpipe = g_async_queue_try_pop(hasher->hashpipe_pool); if(!self->hashpipe) { if(g_atomic_int_get(&hasher->unalloc_hashpipes) > 0) { /* create a new hashpipe */ g_atomic_int_dec_and_test(&hasher->unalloc_hashpipes); self->hashpipe = rm_util_thread_pool_new((GFunc)rm_hasher_hashpipe_worker, hasher, 1); } else { /* already at thread limit - wait for a hashpipe to come available */ self->hashpipe = g_async_queue_pop(hasher->hashpipe_pool); } } rm_assert_gentle(self->hashpipe); self->task_user_data = task_user_data; return self; }
/** * Thread whose aim is to store data according to the selected backend * @param data : server_struct_t * structure. * @returns NULL to fullfill the template needed to create a GThread */ static gpointer data_thread(gpointer user_data) { server_struct_t *dt_server_struct = user_data; hash_data_t *hash_data = NULL; if (dt_server_struct != NULL && dt_server_struct->meta_queue != NULL) { if (dt_server_struct->backend != NULL && dt_server_struct->backend->store_data != NULL) { while (TRUE) { hash_data = g_async_queue_pop(dt_server_struct->data_queue); if (hash_data != NULL) { dt_server_struct->backend->store_data(dt_server_struct, hash_data); } } } else { print_error(__FILE__, __LINE__, _("Error: no data store backend defined, data's thread terminating...\n")); } } else { print_error(__FILE__, __LINE__, _("Error while trying to launch data thread")); } return NULL; }
static void *process_pending_work(void *unused) { struct pending_work *item; g_async_queue_ref(pending_work_queue); while (1) { item=g_async_queue_pop(pending_work_queue); switch (item->proc) { case nr_proto_client_check_int: if (item->integer == INT_VALUE) proto_client_check_int_send_async_reply( item->msg); else proto_client_check_int_send_async_reply_error( item->msg, 1); break; case nr_proto_notify: pthread_mutex_lock(item->lock); pthread_cond_broadcast(item->cond); pthread_mutex_unlock(item->lock); break; } g_slice_free(struct pending_work, item); } return NULL; }
/* fakesink handoff callback */ static void on_gst_buffer (GstElement * fakesink, GstBuffer * buf, GstPad * pad, gpointer data) { GAsyncQueue *queue_input_buf = NULL; GAsyncQueue *queue_output_buf = NULL; /* ref then push buffer to use it in sdl */ gst_buffer_ref (buf); queue_input_buf = (GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink), "queue_input_buf"); g_async_queue_push (queue_input_buf, buf); if (g_async_queue_length (queue_input_buf) > 3) g_idle_add (update_sdl_scene, (gpointer) fakesink); /* pop then unref buffer we have finished to use in sdl */ queue_output_buf = (GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink), "queue_output_buf"); if (g_async_queue_length (queue_output_buf) > 3) { GstBuffer *buf_old = (GstBuffer *) g_async_queue_pop (queue_output_buf); gst_buffer_unref (buf_old); } }
GThreadFunc Stdout_Handler (gpointer data) { zt_outmsg *out_msg; while (1) { out_msg = (zt_outmsg *)g_async_queue_pop(Stdout); g_mutex_lock(&curses_mutex); if (strncmp(out_msg->pi_tag, " CORE ", 6) == 0) { wattron(stdout_win, COLOR_PAIR(4)); wprintw(stdout_win, "[%-8s] %s", out_msg->pi_tag, out_msg->content); wrefresh(stdout_win); wattroff(stdout_win, COLOR_PAIR(4)); wattron(stdout_win, COLOR_PAIR(2)|A_BOLD); } else { wprintw(stdout_win, "[%-8s] %s", out_msg->pi_tag, out_msg->content); wrefresh(stdout_win); } g_mutex_unlock(&curses_mutex); free(out_msg->content); free(out_msg); } }
static gboolean update_sdl_scene (void *fk) { GstElement *fakesink = (GstElement *) fk; GMainLoop *loop = (GMainLoop *) g_object_get_data (G_OBJECT (fakesink), "loop"); GAsyncQueue *queue_input_buf = (GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink), "queue_input_buf"); GAsyncQueue *queue_output_buf = (GAsyncQueue *) g_object_get_data (G_OBJECT (fakesink), "queue_output_buf"); GstBuffer *buf = (GstBuffer *) g_async_queue_pop (queue_input_buf); SDL_Event event; while (SDL_PollEvent (&event)) { if (event.type == SDL_QUIT) { g_main_loop_quit (loop); } if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) { g_main_loop_quit (loop); } } } DrawGLScene (buf); /* push buffer so it can be unref later */ g_async_queue_push (queue_output_buf, buf); return FALSE; }
static gpointer run_history_service_thread (EphyHistoryService *self) { EphyHistoryServicePrivate *priv = self->priv; EphyHistoryServiceMessage *message; g_assert (priv->history_thread == g_thread_self ()); if (ephy_history_service_open_database_connections (self) == FALSE) return NULL; do { message = g_async_queue_try_pop (priv->queue); if (!message) { /* Schedule commit if needed. */ if (ephy_history_service_is_scheduled_to_commit (self)) ephy_history_service_commit (self); /* Block the thread until there's data in the queue. */ message = g_async_queue_pop (priv->queue); } /* Process item. */ ephy_history_service_process_message (self, message); } while (!ephy_history_service_is_scheduled_to_quit (self)); ephy_history_service_close_database_connections (self); ephy_history_service_execute_quit (self, NULL, NULL); return NULL; }
static gpointer iris_thread_worker (IrisThread *thread) { IrisMessage *message; GTimeVal timeout = {0,0}; g_return_val_if_fail (thread != NULL, NULL); g_return_val_if_fail (thread->queue != NULL, NULL); #if LINUX my_thread = thread; #else pthread_setspecific (my_thread, thread); #endif iris_debug_init_thread (); iris_debug (IRIS_DEBUG_THREAD); next_message: if (thread->exclusive) { message = g_async_queue_pop (thread->queue); } else { /* If we do not get any schedulers to work for within our * timeout period, we can safely shutdown. */ g_get_current_time (&timeout); g_time_val_add (&timeout, G_USEC_PER_SEC * 5); message = g_async_queue_timed_pop (thread->queue, &timeout); if (!message) { /* Make sure that the manager removes us from the * free thread list. */ iris_scheduler_manager_destroy (thread); /* make sure nothing was added while we * removed ourselves */ message = g_async_queue_try_pop (thread->queue); } } if (!message) return NULL; switch (message->what) { case MSG_MANAGE: iris_thread_handle_manage (thread, iris_message_get_pointer (message, "queue"), iris_message_get_boolean (message, "exclusive"), iris_message_get_boolean (message, "leader")); break; case MSG_SHUTDOWN: iris_thread_handle_shutdown (thread); break; default: g_warn_if_reached (); break; } goto next_message; }
static void save_dump(global_conf_st *g_conf) { FILE *fp = NULL; xode msg = NULL; char *msg_str = NULL; int i; if (g_conf->reload_file) { fp = fopen(g_conf->reload_file, "a+"); if (fp == NULL) { jlog(L_DEBUG, "try to create %s error\n", g_conf->reload_file); global_conf_free(g_conf); exit(-1); } for (i = 0; i < g_conf->max_thread; i++) { while (g_async_queue_length(threads[i].msg_queue) > 0) { msg = (xode) g_async_queue_pop(threads[i].msg_queue); decrMsgProcNum(); msg_str = xode_to_str(msg); if (msg_str && (!is_blank_line(msg_str))) { fprintf(fp, "%s\n", msg_str); jlog(L_DEBUG, "save %s\n", msg_str); } xode_free(msg); } } fclose(fp); } }
static void pop_queue_n_times(GAsyncQueue *queue, guint size) { guint i; for (i = 0; i < size; i++) { g_async_queue_pop(queue); } }
void *process_queue(struct thread_data *td) { struct configuration *conf= td->conf; g_mutex_lock(init_mutex); MYSQL *thrconn= mysql_init(NULL); g_mutex_unlock(init_mutex); mysql_options(thrconn, MYSQL_READ_DEFAULT_GROUP, "myloader"); if (compress_protocol) mysql_options(thrconn, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(thrconn, hostname, username, password, NULL, port, socket_path, 0)) { g_critical("Failed to connect to MySQL server: %s", mysql_error(thrconn)); exit(EXIT_FAILURE); } if (!enable_binlog) mysql_query(thrconn, "SET SQL_LOG_BIN=0"); mysql_query(thrconn, "/*!40101 SET NAMES binary*/"); mysql_query(thrconn, "SET autocommit=0"); g_async_queue_push(conf->ready, GINT_TO_POINTER(1)); struct job* job= NULL; struct restore_job* rj= NULL; for(;;) { job= (struct job*)g_async_queue_pop(conf->queue); switch (job->type) { case JOB_RESTORE: rj= (struct restore_job *)job->job_data; g_message("Thread %d restoring `%s`.`%s` part %d", td->thread_id, rj->database, rj->table, rj->part); restore_data(thrconn, rj->database, rj->table, rj->filename, FALSE); if (rj->database) g_free(rj->database); if (rj->table) g_free(rj->table); if (rj->filename) g_free(rj->filename); g_free(rj); g_free(job); break; case JOB_SHUTDOWN: g_message("Thread %d shutting down", td->thread_id); if (thrconn) mysql_close(thrconn); g_free(job); mysql_thread_end(); return NULL; break; default: g_critical("Something very bad happened!"); exit(EXIT_FAILURE); } } if (thrconn) mysql_close(thrconn); mysql_thread_end(); return NULL; }
/* [user thread] */ void _al_close_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog) { gdk_threads_add_timeout(0, do_close_native_text_log, textlog); while (g_async_queue_pop(textlog->async_queue) != ACK_CLOSED) ; g_async_queue_unref(textlog->async_queue); textlog->async_queue = NULL; }
static void emc_client_ready_cb (struct ev_loop *loop, ev_async *w, int revents) { struct emc_server_context *ctx = (struct emc_server_context*)w->data; ev_io *client_watcher; client_watcher = (ev_io *)g_async_queue_pop(ctx->work_queue); ev_io_start(EV_DEFAULT_ client_watcher); }
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"); } }
void thread_1(void *ptr) { gpointer *data; printf("Starting thread 1\n"); while (1) { data=g_async_queue_pop(queue1); printf("Data received from queue\n"); } }
gint parallelSearchResult(Move* move,gint* alpha, gint* type){ gint eval; Message* m = (Message*)g_async_queue_pop(slaveMaster); eval = m->eval; *move = m->move; *alpha = m->alpha; *type = m->type; g_free(m); return eval; }
static void player_av_stop (Player *self) { PlayerAVPrivate *priv = PLAYER_AV (self)->priv; if (!priv->entry) { return; } player_av_set_state (PLAYER_AV (self), PLAYER_STATE_STOPPED); if (entry_get_state (priv->entry) != ENTRY_STATE_MISSING) { entry_set_state (priv->entry, ENTRY_STATE_NONE); } if (priv->athread) { g_thread_join (priv->athread); priv->athread = NULL; } priv->vt_id = -1; priv->start_time = priv->stop_time = -1; while (g_async_queue_length (priv->apq) > 0) { AVPacket *packet = g_async_queue_pop (priv->apq); if (packet->data) { av_free_packet (packet); } av_free (packet); } while (g_async_queue_length (priv->vpq) > 0) { AVPacket *packet = g_async_queue_pop (priv->vpq); if (packet->data) { av_free_packet (packet); } av_free (packet); } _player_emit_position_changed (self, 0); }
static void single_thread_get_metadata (GAsyncQueue *queue) { while (TRUE) { TrackerExtractTask *task; task = g_async_queue_pop (queue); g_message ("Dispatching '%s' in dedicated thread", task->file); get_metadata (task); } }
GThreadFunc Stderr_Handler (gpointer data) { zt_outmsg *out_msg; while (1) { out_msg = (zt_outmsg *)g_async_queue_pop(Stderr); fprintf(stderr, "\x1B[31m[!!> %s] %s\x1B[0m", out_msg->pi_tag, out_msg->content); fflush(stderr); free(out_msg->content); free(out_msg); } }