gint main (gint argc, gchar * argv[]) { GThread *threads[MAX_THREADS]; gint num_threads; gint t; GstClock *sysclock; gst_init (&argc, &argv); if (argc != 2) { g_print ("usage: %s <num_threads>\n", argv[0]); exit (-1); } num_threads = atoi (argv[1]); if (num_threads <= 0 || num_threads > MAX_THREADS) { g_print ("number of threads must be between 0 and %d\n", MAX_THREADS); exit (-2); } sysclock = gst_system_clock_obtain (); for (t = 0; t < num_threads; t++) { GError *error = NULL; threads[t] = g_thread_try_new ("clockstresstest", run_test, sysclock, &error); if (error) { printf ("ERROR: g_thread_try_new() %s\n", error->message); exit (-1); } } printf ("main(): Created %d threads.\n", t); /* run for 5 seconds */ g_usleep (G_USEC_PER_SEC * 5); printf ("main(): Stopping threads...\n"); running = FALSE; for (t = 0; t < num_threads; t++) { g_thread_join (threads[t]); } g_print ("performed %d get_time operations\n", count); gst_object_unref (sysclock); return 0; }
static GThread *_thread_new(const gchar *name, GThreadFunc func, gpointer data) { GThread *thread = NULL; GError *error = NULL; #ifdef HAVE_THREAD_NEW thread = g_thread_try_new(name, func, data, &error); #else thread = g_thread_create(func, data, TRUE, &error); #endif return thread; }
static gboolean g_thread_pool_start_thread (GRealThreadPool *pool, GError **error) { gboolean success = FALSE; if (pool->num_threads >= pool->max_threads && pool->max_threads != -1) /* Enough threads are already running */ return TRUE; g_async_queue_lock (unused_thread_queue); if (g_async_queue_length_unlocked (unused_thread_queue) < 0) { g_async_queue_push_unlocked (unused_thread_queue, pool); success = TRUE; } g_async_queue_unlock (unused_thread_queue); if (!success) { GThread *thread; /* No thread was found, we have to start a new one */ G_LOCK (threads); while (finished_threads != NULL) { thread = finished_threads->data; finished_threads = g_slist_delete_link (finished_threads, finished_threads); G_UNLOCK (threads); g_thread_join (thread); G_LOCK (threads); } thread = g_thread_try_new ("pool", g_thread_pool_thread_proxy, pool, error); if (thread != NULL) active_threads = g_slist_prepend (active_threads, thread); G_UNLOCK (threads); if (thread == NULL) return FALSE; } /* See comment in g_thread_pool_thread_proxy as to why this is done * here and not there */ pool->num_threads++; return TRUE; }
void SpirallingMaster_post_sync(CO_Data* d) { if (set_up) { time_actual_sync = cantools_get_time(); if(!asserv_check()) { GThread * velstop = g_thread_try_new ("vel_stop", asserv_motor_stop,NULL, NULL); if (velstop == NULL) { errgen_set(ERR_VEL_STOP_LOOP,NULL); } } } sendPDOevent(d); }
/** * Create a new thread. * @param func Function to execute in new thread context * @param data User defined data to pass to func * @param prio_level Priority level. If greater than 0 then high priority scheduling will * be used, with the given priority level (used by pthreads only). 0 uses normal scheduling. * @param detach If TRUE, 'join' does not work and the thread destroys itself when finished. * @return New thread pointer or NULL on error */ fluid_thread_t * new_fluid_thread (const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach) { GThread *thread; fluid_thread_info_t *info; GError *err = NULL; g_return_val_if_fail (func != NULL, NULL); #if OLD_GLIB_THREAD_API /* Make sure g_thread_init has been called. * FIXME - Probably not a good idea in a shared library, * but what can we do *and* remain backwards compatible? */ if (!g_thread_supported ()) g_thread_init (NULL); #endif if (prio_level > 0) { info = FLUID_NEW (fluid_thread_info_t); if (!info) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } info->func = func; info->data = data; info->prio_level = prio_level; #if NEW_GLIB_THREAD_API thread = g_thread_try_new (name, fluid_thread_high_prio, info, &err); #else thread = g_thread_create (fluid_thread_high_prio, info, detach == FALSE, &err); #endif } #if NEW_GLIB_THREAD_API else thread = g_thread_try_new (name, (GThreadFunc)func, data, &err); #else else thread = g_thread_create ((GThreadFunc)func, data, detach == FALSE, &err);
int janus_events_init(gboolean enabled, GHashTable *handlers) { /* We setup a thread for passing events to the handlers */ GError *error = NULL; events_thread = g_thread_try_new("janus events thread", janus_events_thread, NULL, &error); if(error != NULL) { JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch the Events handler thread...\n", error->code, error->message ? error->message : "??"); return -1; } events = g_async_queue_new(); eventhandlers = handlers; eventsenabled = enabled; return 0; }
/** * @author sohu-inc.com * 启动后端检测的线程 * @param detect_thread */ void backend_detect_thread_start(backend_detect_thread_t *detect_thread) { GError *gerr = NULL; g_message("%s: starting a backend detect thread", G_STRLOC); detect_thread->thr = g_thread_try_new(detect_thread->name->str, (GThreadFunc) backend_detect_thread_loop, detect_thread, &gerr); if (gerr) { g_critical("%s: %s", G_STRLOC, gerr->message); g_error_free(gerr); gerr = NULL; } return; }
static gboolean start_decoder (App * app) { GstCaps *caps; app->file = g_mapped_file_new (app->file_name, FALSE, NULL); if (!app->file) return FALSE; app->file_size = g_mapped_file_get_length (app->file); app->file_data = (guint8 *) g_mapped_file_get_contents (app->file); if (!app->file_data) return FALSE; caps = caps_from_codec (app->codec); switch (app->codec) { case GST_VAAPI_CODEC_H264: app->decoder = gst_vaapi_decoder_h264_new (app->display, caps); break; #if USE_JPEG_DECODER case GST_VAAPI_CODEC_JPEG: app->decoder = gst_vaapi_decoder_jpeg_new (app->display, caps); break; #endif case GST_VAAPI_CODEC_MPEG2: app->decoder = gst_vaapi_decoder_mpeg2_new (app->display, caps); break; case GST_VAAPI_CODEC_MPEG4: app->decoder = gst_vaapi_decoder_mpeg4_new (app->display, caps); break; case GST_VAAPI_CODEC_VC1: app->decoder = gst_vaapi_decoder_vc1_new (app->display, caps); break; default: app->decoder = NULL; break; } if (!app->decoder) return FALSE; gst_vaapi_decoder_set_codec_state_changed_func (app->decoder, handle_decoder_state_changes, app); g_timer_start (app->timer); app->decoder_thread = g_thread_try_new ("Decoder Thread", decoder_thread, app, NULL); if (!app->decoder_thread) return FALSE; return TRUE; }
/** * vu_check_latest_version: * @window: Somewhere where we may need use the display to inform the user about the version status * * Periodically checks the released latest VERSION file on the website to compare with the running version * */ void vu_check_latest_version ( GtkWindow *window ) { if ( ! a_vik_get_check_version () ) return; gboolean do_check = FALSE; gint check_period; if ( ! a_settings_get_integer ( VIK_SETTINGS_VERSION_CHECK_PERIOD, &check_period ) ) { check_period = 14; } // Get last checked date... GDate *gdate_last = g_date_new(); GDate *gdate_now = g_date_new(); GTimeVal time_last; gchar *last_checked_date = NULL; // When no previous date available - set to do the version check if ( a_settings_get_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, &last_checked_date) ) { if ( g_time_val_from_iso8601 ( last_checked_date, &time_last ) ) { g_date_set_time_val ( gdate_last, &time_last ); } else do_check = TRUE; } else do_check = TRUE; GTimeVal time_now; g_get_current_time ( &time_now ); g_date_set_time_val ( gdate_now, &time_now ); if ( ! do_check ) { // Dates available so do the comparison g_date_add_days ( gdate_last, check_period ); if ( g_date_compare ( gdate_last, gdate_now ) < 0 ) do_check = TRUE; } g_date_free ( gdate_last ); g_date_free ( gdate_now ); if ( do_check ) { #if GLIB_CHECK_VERSION (2, 32, 0) g_thread_try_new ( "latest_version_thread", (GThreadFunc)latest_version_thread, window, NULL ); #else g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL ); #endif } }
/** * gda_worker_new: (skip) * * Creates a new #GdaWorker object. * * Returns: (transfer full): a new #GdaWorker, or %NULL if an error occurred * * Since: 6.0 */ GdaWorker * gda_worker_new (void) { GdaWorker *worker; worker = bg_get_spare_gda_worker (); if (worker) return worker; worker = g_slice_new0 (GdaWorker); worker->submit_its = itsignaler_new (); if (!worker->submit_its) { g_slice_free (GdaWorker, worker); return NULL; } worker->ref_count = 1; worker->callbacks_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) declared_callback_free); worker->jobs_hash = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, (GDestroyNotify) worker_job_free); worker->worker_must_quit = 0; worker->location = NULL; g_rec_mutex_init (& worker->rmutex); gchar *str; static guint counter = 0; str = g_strdup_printf ("gdaWrkrTh%u", counter); counter++; worker->worker_thread = g_thread_try_new (str, (GThreadFunc) worker_thread_main, worker, NULL); g_free (str); if (!worker->worker_thread) { itsignaler_unref (worker->submit_its); g_hash_table_destroy (worker->callbacks_hash); g_hash_table_destroy (worker->jobs_hash); g_rec_mutex_clear (& worker->rmutex); g_slice_free (GdaWorker, worker); return NULL; } else bg_update_stats (BG_STARTED_THREADS); #ifdef DEBUG_NOTIFICATION g_print ("[W] created GdaWorker %p\n", worker); #endif bg_update_stats (BG_CREATED_WORKER); return worker; }
static gboolean gst_audio_sink_ring_buffer_activate (GstAudioRingBuffer * buf, gboolean active) { GstAudioSink *sink; GstAudioSinkRingBuffer *abuf; GError *error = NULL; sink = GST_AUDIO_SINK (GST_OBJECT_PARENT (buf)); abuf = GST_AUDIO_SINK_RING_BUFFER_CAST (buf); if (active) { abuf->running = TRUE; GST_DEBUG_OBJECT (sink, "starting thread"); sink->thread = g_thread_try_new ("audiosink-ringbuffer", (GThreadFunc) audioringbuffer_thread_func, buf, &error); if (!sink->thread || error != NULL) goto thread_failed; GST_DEBUG_OBJECT (sink, "waiting for thread"); /* the object lock is taken */ GST_AUDIO_SINK_RING_BUFFER_WAIT (buf); GST_DEBUG_OBJECT (sink, "thread is started"); } else { abuf->running = FALSE; GST_DEBUG_OBJECT (sink, "signal wait"); GST_AUDIO_SINK_RING_BUFFER_SIGNAL (buf); GST_OBJECT_UNLOCK (buf); /* join the thread */ g_thread_join (sink->thread); GST_OBJECT_LOCK (buf); } return TRUE; /* ERRORS */ thread_failed: { if (error) GST_ERROR_OBJECT (sink, "could not create thread %s", error->message); else GST_ERROR_OBJECT (sink, "could not create thread for unknown reason"); g_clear_error (&error); return FALSE; } }
static gboolean gst_eglglessink_start (GstEglGlesSink * eglglessink) { GError *error = NULL; GST_DEBUG_OBJECT (eglglessink, "Starting"); if (!eglglessink->egl_started) { GST_ERROR_OBJECT (eglglessink, "EGL uninitialized. Bailing out"); goto HANDLE_ERROR; } /* Ask for a window to render to */ if (!eglglessink->have_window) gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (eglglessink)); if (!eglglessink->have_window && !eglglessink->create_window) { GST_ERROR_OBJECT (eglglessink, "Window handle unavailable and we " "were instructed not to create an internal one. Bailing out."); goto HANDLE_ERROR; } eglglessink->last_flow = GST_FLOW_OK; eglglessink->display_region.w = 0; eglglessink->display_region.h = 0; gst_data_queue_set_flushing (eglglessink->queue, FALSE); #if !GLIB_CHECK_VERSION (2, 31, 0) eglglessink->thread = g_thread_create ((GThreadFunc) render_thread_func, eglglessink, TRUE, &error); #else eglglessink->thread = g_thread_try_new ("eglglessink-render", (GThreadFunc) render_thread_func, eglglessink, &error); #endif if (!eglglessink->thread || error != NULL) goto HANDLE_ERROR; GST_DEBUG_OBJECT (eglglessink, "Started"); return TRUE; HANDLE_ERROR: GST_ERROR_OBJECT (eglglessink, "Couldn't start"); g_clear_error (&error); return FALSE; }
/** * e_alert_sink_submit_thread_job: * @alert_sink: an #EAlertSink instance * @description: user-friendly description of the job, to be shown in UI * @alert_ident: in case of an error, this alert identificator is used * for EAlert construction * @alert_arg_0: (allow-none): in case of an error, use this string as * the first argument to the EAlert construction; the second argument * is the actual error message; can be #NULL, in which case only * the error message is passed to the EAlert construction * @func: function to be run in a dedicated thread * @user_data: (allow-none): custom data passed into @func; can be #NULL * @free_user_data: (allow-none): function to be called on @user_data, * when the job is over; can be #NULL * * Runs the @func in a dedicated thread. Any error is propagated to UI. * The cancellable passed into the @func is a #CamelOperation, thus * the caller can overwrite progress and description message on it. * * Returns: (transfer full): Newly created #EActivity on success. * The caller is responsible to g_object_unref() it when done with it. * * Note: The @free_user_data, if set, is called in the main thread. * * Note: This function should be called only from the main thread. * * Since: 3.16 **/ EActivity * e_alert_sink_submit_thread_job (EAlertSink *alert_sink, const gchar *description, const gchar *alert_ident, const gchar *alert_arg_0, EAlertSinkThreadJobFunc func, gpointer user_data, GDestroyNotify free_user_data) { EActivity *activity; GCancellable *cancellable; EAlertSinkThreadJobData *job_data; GThread *thread; g_return_val_if_fail (E_IS_ALERT_SINK (alert_sink), NULL); g_return_val_if_fail (description != NULL, NULL); g_return_val_if_fail (func != NULL, NULL); activity = e_activity_new (); cancellable = camel_operation_new (); e_activity_set_alert_sink (activity, alert_sink); e_activity_set_cancellable (activity, cancellable); e_activity_set_text (activity, description); camel_operation_push_message (cancellable, "%s", description); job_data = g_new0 (EAlertSinkThreadJobData, 1); job_data->activity = g_object_ref (activity); job_data->alert_ident = g_strdup (alert_ident); job_data->alert_arg_0 = g_strdup (alert_arg_0); job_data->error = NULL; job_data->func = func; job_data->user_data = user_data; job_data->free_user_data = free_user_data; thread = g_thread_try_new (G_STRFUNC, e_alert_sink_thread_job, job_data, &job_data->error); g_object_unref (cancellable); if (thread) { g_thread_unref (thread); } else { g_prefix_error (&job_data->error, _("Failed to create a thread: ")); g_timeout_add (1, e_alert_sink_thread_job_done_cb, job_data); } return activity; }
void gldi_task_launch (GldiTask *pTask) { g_return_if_fail (pTask != NULL); if (pTask->get_data == NULL) // no asynchronous work -> just call the 'update' and directly schedule the next iteration { _set_elapsed_time (pTask); pTask->bContinue = pTask->update (pTask->pSharedMemory); if (! pTask->bContinue) { _cancel_next_iteration (pTask); } else { pTask->iFrequencyState = GLDI_TASK_FREQUENCY_NORMAL; _schedule_next_iteration (pTask); } } else // launch the asynchronous work in a thread { if (pTask->pThread == NULL) // no thread yet -> create and launch it { pTask->bIsRunning = TRUE; GError *erreur = NULL; #ifndef GLIB_VERSION_2_32 pTask->pThread = g_thread_create ((GThreadFunc) _get_data_threaded, pTask, TRUE, &erreur); // TRUE <=> joinable #else pTask->pThread = g_thread_try_new ("Cairo-Dock Task", (GThreadFunc) _get_data_threaded, pTask, &erreur); #endif if (erreur != NULL) // on n'a pas pu lancer le thread. { cd_warning (erreur->message); g_error_free (erreur); pTask->bIsRunning = FALSE; } } else // thread already exists; it's either running or sleeping or finished with a pending update if (pTask->pCond && g_mutex_trylock (pTask->pMutex)) // it's a periodic thread, and it's not currently running... { if (pTask->iSidUpdateIdle == 0) // ...and it doesn't have a pending update -> awake it and run it again. { pTask->bRunThread = TRUE; pTask->bIsRunning = TRUE; g_cond_signal (pTask->pCond); } g_mutex_unlock (pTask->pMutex); } // else it's a one-shot thread or it's currently running or has a pending update -> don't launch it. so if the task is periodic, it will skip this iteration. } }
extern EXPORT_API gboolean gst_dvb_css_wc_start(const gchar *address, gint port, gboolean followup, guint32 max_freq_error_ppm, gboolean isDebug) { GST_DEBUG("dvb_css_wc_start\n"); G_LOCK(mutex); sServer = server_new(); if (sServer == NULL) { goto server_struct_not_initialized; } gst_init(NULL, NULL); sServer->loop = g_main_loop_new(NULL, FALSE); sServer->clock = gst_system_clock_obtain(); if(isDebug == FALSE){ sServer->gstdvbcsswcserver = gst_dvb_css_wc_server_new(sServer->clock, address, port, followup, max_freq_error_ppm); } else{ sServer->gstdvbcsswcserver = gst_net_time_provider_new(sServer->clock, address, port); } if (sServer->gstdvbcsswcserver == NULL) { GST_ERROR("Dvb_css_wc server not created\n"); goto cleanup; } g_object_get(sServer->gstdvbcsswcserver, "port", &port, NULL); GST_DEBUG("Published network clock on port %u\n", port); sServer->thread = g_thread_try_new("dvb_css_wc_thread", (GThreadFunc) g_main_loop_run, sServer->loop, NULL); if (sServer->thread == NULL) { GST_ERROR("Thread for dvb_css_wc server not created\n"); goto cleanup; } GST_DEBUG("Dvb_css_wc server started\n"); G_UNLOCK(mutex); return TRUE; /* ERRORS */ server_struct_not_initialized:{ GST_ERROR("Dvb_css_wc server struct not initialized\n"); G_UNLOCK(mutex); return FALSE; } cleanup:{ server_free(&sServer); G_UNLOCK(mutex); return FALSE; } }
static void _server_start_one_worker(struct network_server_s *srv, gboolean counters_changed) { if (!srv->flag_continue) return; if (!counters_changed) _thread_start(srv); GThread *th = g_thread_try_new("worker", _thread_cb_worker, srv, NULL); if (!th) { _thread_stop(srv); g_message("Thread creation failure : worker"); } }
static GMainContext *get_my_context(GError **exception) { if (ctx == NULL) ctx = g_main_context_new(); if (thread == NULL) { thread = g_thread_try_new("gmain", run_main_loop, NULL, exception); if (*exception != NULL) { g_main_context_unref(ctx); ctx = NULL; } } return ctx; }
int start_event_loop(GError **gerr) { pending_callback = malloc(sizeof(GMutex)); if (pending_callback == NULL) { GError *err = g_error_new(BL_ERROR_DOMAIN, BL_MALLOC_ERROR, "Start event loop: Malloc error\n"); PROPAGATE_ERROR; goto error1; } g_mutex_init(pending_callback); g_mutex_lock(pending_callback); cb_mutex = malloc(sizeof(GMutex)); if (cb_mutex == NULL) { GError *err = g_error_new(BL_ERROR_DOMAIN, BL_MALLOC_ERROR, "Start event loop: Malloc error\n"); PROPAGATE_ERROR; goto error2; } g_mutex_init(cb_mutex); event_thread = g_thread_try_new("event_loop", _event_thread, NULL, gerr); for (int cnt = 0; (!is_event_loop_running()) && (cnt < 60) && (event_thread != NULL) && (get_conn_state() == STATE_CONNECTING); cnt++) { sleep(1); printf_dbg("wait for event loop\n"); } if (event_thread == NULL) { printf_dbg("%s\n", (*gerr)->message); goto error3; } return 0; error3: free(cb_mutex); cb_mutex = NULL; error2: free(pending_callback); pending_callback = NULL; error1: return -1; }
/** * start all the event-threads * * starts all the event-threads that got added by chassis_event_threads_add() * * @see chassis_event_threads_add */ void chassis_event_threads_start(GPtrArray *threads) { guint i; g_log_dbproxy(g_message, "starting %d threads", threads->len - 1); for (i = 1; i < threads->len; i++) { /* the 1st is the main-thread and already set up */ chassis_event_thread_t *thread = threads->pdata[i]; GError *gerr = NULL; thread->thr = g_thread_try_new("event thread", (GThreadFunc)chassis_event_thread_loop, thread, &gerr); if (gerr) { g_log_dbproxy(g_critical, "%s", gerr->message); g_error_free(gerr); gerr = NULL; } } }
/* ----------- Global Functions ---------------------------------- */ int scrobbler_init(void) { int rv = 0; GError *gerror = NULL; /* Get settings */ user = conf_get_scrobble_user(); md5pass = conf_get_scrobble_md5pass(); enable = conf_get_scrobble_enable(); /* Start scrobbler thread */ run = 1; tasks = g_async_queue_new(); thread = g_thread_try_new(STHNAME, scrobbler_thread, NULL, &gerror); return rv; }
/** * @author sohu-inc.com * 启动一个worker 线程 * @param worker */ void backend_status_update_worker_start( backend_status_update_worker *worker) { if (!worker) return; GError *gerr = NULL; g_message("%s: starting a status update thread", G_STRLOC); worker->thr = g_thread_try_new("backend status updater", (GThreadFunc) backend_status_update, worker, &gerr); if (gerr) { g_critical("%s: %s", G_STRLOC, gerr->message); g_error_free(gerr); gerr = NULL; } return; }
gint main (gint argc, gchar * argv[]) { GThread *threads[MAX_THREADS]; gint num_threads; gint t; gst_init (&argc, &argv); fdlock = g_mutex_new (); timer = g_timer_new (); if (argc != 2) { g_print ("usage: %s <num_threads>\n", argv[0]); exit (-1); } num_threads = atoi (argv[1]); set = gst_poll_new (TRUE); for (t = 0; t < num_threads; t++) { GError *error = NULL; #if !GLIB_CHECK_VERSION (2, 31, 0) threads[t] = g_thread_create (run_test, GINT_TO_POINTER (t), TRUE, &error); #else threads[t] = g_thread_try_new ("pollstresstest", run_test, GINT_TO_POINTER (t), &error); #endif if (error) { printf ("ERROR: g_thread_create() %s\n", error->message); exit (-1); } } printf ("main(): Created %d threads.\n", t); for (t = 0; t < num_threads; t++) { g_thread_join (threads[t]); } gst_poll_free (set); return 0; }
void test_combined_creation() { int thread_count = g_thread_count; int test_count = (g_task_count) / thread_count; g_message("Threads count: %d, Test per thread: %d", thread_count, test_count); tGThreadVector threads; threads.reserve(thread_count); s_default_ctx = sc_memory_initialize(¶ms); print_storage_statistics(); g_test_timer_start(); for (size_t i = 0; i < thread_count; ++i) { GThreadFunc f = create_node_thread; switch(g_random_int() % 3) { case 0: f = create_link_thread; break; case 1: f = create_arc_thread; break; default: break; } GThread * thread = g_thread_try_new(0, f, GINT_TO_POINTER(test_count), 0); if (thread == 0) continue; threads.push_back(thread); } for (size_t i = 0; i < thread_count; ++i) g_assert(GPOINTER_TO_INT(g_thread_join(threads[i])) == test_count); printf("Time: %lf\n", g_test_timer_elapsed()); print_storage_statistics(); sc_memory_shutdown(SC_FALSE); }
static GstFlowReturn final_sinkpad_bufferalloc (GstPad * pad, guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf) { BufferAllocHarness *h; GTimeVal deadline; h = g_object_get_qdata (G_OBJECT (pad), g_quark_from_static_string ("buffer-alloc-harness")); g_assert (h != NULL); if (--(h->countdown) == 0) { /* Time to make the app release the pad. */ h->app_thread_prepped = FALSE; h->bufferalloc_blocked = TRUE; h->app_thread = g_thread_try_new ("gst-check", app_thread_func, h, NULL); fail_if (h->app_thread == NULL); /* Wait for the app thread to get ready to call release_request_pad(). */ g_mutex_lock (&check_mutex); while (!h->app_thread_prepped) g_cond_wait (&check_cond, &check_mutex); g_mutex_unlock (&check_mutex); /* Now wait for it to do that within a second, to avoid deadlocking * in the event of future changes to the locking semantics. */ g_mutex_lock (&check_mutex); g_get_current_time (&deadline); deadline.tv_sec += 1; while (h->bufferalloc_blocked) { if (!g_cond_timed_wait (&check_cond, &check_mutex, &deadline)) break; } g_mutex_unlock (&check_mutex); } *buf = gst_buffer_new_and_alloc (size); gst_buffer_set_caps (*buf, caps); return GST_FLOW_OK; }
static gboolean gst_audioringbuffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec) { GstAudioSrc *src; GstAudioSrcClass *csrc; GstAudioRingBuffer *abuf; gboolean result = FALSE; src = GST_AUDIO_SRC (GST_OBJECT_PARENT (buf)); csrc = GST_AUDIO_SRC_GET_CLASS (src); if (csrc->prepare) result = csrc->prepare (src, spec); if (!result) goto could_not_open; buf->data = gst_buffer_new_and_alloc (spec->segtotal * spec->segsize); memset (GST_BUFFER_DATA (buf->data), 0, GST_BUFFER_SIZE (buf->data)); abuf = GST_AUDIORING_BUFFER (buf); abuf->running = TRUE; /* FIXME: handle thread creation failure */ #if !GLIB_CHECK_VERSION (2, 31, 0) src->thread = g_thread_create ((GThreadFunc) audioringbuffer_thread_func, buf, TRUE, NULL); #else src->thread = g_thread_try_new ("audiosrc-ringbuffer", (GThreadFunc) audioringbuffer_thread_func, buf, NULL); #endif GST_AUDIORING_BUFFER_WAIT (buf); return result; could_not_open: { return FALSE; } }
int janus_events_init(gboolean enabled, char *server_name, GHashTable *handlers) { eventsenabled = enabled; if(eventsenabled) { events = g_async_queue_new(); if(server_name != NULL) server = g_strdup(server_name); eventhandlers = handlers; /* We setup a thread for passing events to the handlers */ GError *error = NULL; events_thread = g_thread_try_new("janus events thread", janus_events_thread, NULL, &error); if(error != NULL) { eventsenabled = FALSE; g_free(server); g_async_queue_unref(events); JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch the Events handler thread...\n", error->code, error->message ? error->message : "??"); return -1; } } return 0; }
static gboolean egl_display_init (EglDisplay * display) { display->gl_queue = g_async_queue_new_full ((GDestroyNotify) gst_vaapi_mini_object_unref); if (!display->gl_queue) return FALSE; g_mutex_init (&display->mutex); g_cond_init (&display->gl_thread_ready); display->gl_thread = g_thread_try_new ("OpenGL Thread", egl_display_thread, display, NULL); if (!display->gl_thread) return FALSE; g_mutex_lock (&display->mutex); g_cond_wait (&display->gl_thread_ready, &display->mutex); g_mutex_unlock (&display->mutex); return display->base.is_valid; }
static gboolean net_io_do_async(net_io_request_t *request) { /* the request structure is shared between master and worker thread. */ /* typically the master thread will do some waiting until the worker */ /* thread returns. But the master may very well stop waiting since e.g. */ /* the user activated some cancel button. The client will learn this */ /* from the fact that it's holding the only reference to the request */ /* create worker thread */ request->refcount = 2; // master and worker hold a reference /* if(!g_thread_create(&worker_thread, request, FALSE, NULL) != 0) { */ if(g_thread_try_new("worker", &worker_thread, request, NULL) == NULL) { g_warning("failed to create the worker thread"); /* free request and return error */ request->refcount--; /* decrease by one for dead worker thread */ return FALSE; } return TRUE; }
void test_save() { // create nodes s_default_ctx = sc_memory_initialize(¶ms); sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8)); int const count = 1000000; for (int i = 0; i < count; ++i) { g_assert(SC_ADDR_IS_NOT_EMPTY(sc_memory_node_new(ctx, 0))); } sc_memory_context_free(ctx); GThread * thread = g_thread_try_new(0, start_save_threaded, 0, 0); test_creation(create_arc_thread, g_task_count, g_thread_count); g_thread_join(thread); sc_memory_shutdown(SC_FALSE); }
/* Plugin implementation */ int janus_videocall_init(janus_callbacks *callback, const char *config_path) { if(stopping) { /* Still stopping from before */ return -1; } if(callback == NULL || config_path == NULL) { /* Invalid arguments */ return -1; } /* Read configuration */ char filename[255]; sprintf(filename, "%s/%s.cfg", config_path, JANUS_VIDEOCALL_PACKAGE); JANUS_LOG(LOG_VERB, "Configuration file: %s\n", filename); janus_config *config = janus_config_parse(filename); if(config != NULL) janus_config_print(config); /* This plugin actually has nothing to configure... */ janus_config_destroy(config); config = NULL; sessions = g_hash_table_new(g_str_hash, g_str_equal); janus_mutex_init(&sessions_mutex); messages = g_async_queue_new_full((GDestroyNotify) janus_videocall_message_free); /* This is the callback we'll need to invoke to contact the gateway */ gateway = callback; initialized = 1; /* Launch the thread that will handle incoming messages */ GError *error = NULL; handler_thread = g_thread_try_new("janus videocall handler", janus_videocall_handler, NULL, &error); if(error != NULL) { initialized = 0; /* Something went wrong... */ JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch thread...\n", error->code, error->message ? error->message : "??"); return -1; } JANUS_LOG(LOG_INFO, "%s initialized!\n", JANUS_VIDEOCALL_NAME); return 0; }