static void log_reader_work_finished(void *s) { LogReader *self = (LogReader *) s; if (self->pending_proto_present) { /* pending proto is only set in the main thread, so no need to * lock it before coming here. After we're syncing with the * log_writer_reopen() call, quite possibly coming from a * non-main thread. */ g_static_mutex_lock(&self->pending_proto_lock); log_reader_apply_proto_and_poll_events(self, self->pending_proto, self->pending_poll_events); self->pending_proto = NULL; self->pending_poll_events = NULL; self->pending_proto_present = FALSE; g_cond_signal(self->pending_proto_cond); g_static_mutex_unlock(&self->pending_proto_lock); } if (self->notify_code) { gint notify_code = self->notify_code; self->notify_code = 0; log_pipe_notify(self->control, notify_code, self); } if (self->super.super.flags & PIF_INITIALIZED) { /* reenable polling the source assuming that we're still in * business (e.g. the reader hasn't been uninitialized) */ log_proto_server_reset_error(self->proto); log_reader_update_watches(self); } log_pipe_unref(&self->super.super); }
static void daap_mdns_resolve_browser_remove_cb ( AvahiServiceResolver *resolv, AvahiIfIndex iface, AvahiProtocol proto, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *hostname, const AvahiAddress *addr, guint16 port, AvahiStringList *text, AvahiLookupResultFlags flags, void *userdata) { gchar ad[ADDR_LEN]; if (!resolv) { return; } switch (event) { case AVAHI_RESOLVER_FOUND: avahi_address_snprint (ad, sizeof (ad), addr); g_static_mutex_lock (&serv_list_mut); g_server_list = daap_mdns_serv_remove (g_server_list, ad, port); g_static_mutex_unlock (&serv_list_mut); break; case AVAHI_RESOLVER_FAILURE: break; default: break; } avahi_service_resolver_free (resolv); }
static inline int pgm_rxw_pkt_free1 ( pgm_rxw_t* r, pgm_rxw_packet_t* rp ) { ASSERT_RXW_BASE_INVARIANT(r); g_assert ( rp != NULL ); if (rp->data) { pgm_rxw_data_free1 (r, rp); } // g_slice_free1 (sizeof(pgm_rxw_t), rp); g_static_mutex_lock (r->trash_mutex); g_trash_stack_push (r->trash_packet, rp); g_static_mutex_unlock (r->trash_mutex); ASSERT_RXW_BASE_INVARIANT(r); return PGM_RXW_OK; }
static void xmms_samba_destroy (xmms_xform_t *xform) { gint err; xmms_samba_data_t *data; g_return_if_fail (xform); data = xmms_xform_private_data_get (xform); g_return_if_fail (data); if (data->fd != -1) { g_static_mutex_lock (&mutex); err = smbc_close (data->fd); g_static_mutex_unlock (&mutex); if (err < 0) { xmms_log_error ("%s", strerror (errno)); } } g_free (data); }
static inline gpointer pgm_rxw_alloc0_packet ( pgm_rxw_t* r ) { ASSERT_RXW_BASE_INVARIANT(r); gpointer p; g_static_mutex_lock (r->trash_mutex); if (*r->trash_packet) { p = g_trash_stack_pop (r->trash_packet); memset (p, 0, sizeof(pgm_rxw_packet_t)); } else { p = g_slice_alloc0 (sizeof(pgm_rxw_packet_t)); } g_static_mutex_unlock (r->trash_mutex); ASSERT_RXW_BASE_INVARIANT(r); return p; }
void gftpui_common_cancel_file_transfer (gftp_transfer * tdata) { g_static_mutex_lock (&tdata->structmutex); if (tdata->started) { gftpui_cancel_file_transfer (tdata); tdata->skip_file = 0; } else tdata->done = 1; tdata->fromreq->stopable = 0; tdata->toreq->stopable = 0; g_static_mutex_unlock (&tdata->structmutex); tdata->fromreq->logging_function (gftp_logging_misc, tdata->fromreq, _("Stopping the transfer on host %s\n"), tdata->toreq->hostname); }
static DBusGProxy *get_dbus_proxy (MoonshotError **error) { static DBusGProxy *dbus_proxy = NULL; static GStaticMutex init_lock = G_STATIC_MUTEX_INIT; g_static_mutex_lock (&init_lock); if (dbus_proxy == NULL) { /* Make sure GObject is initialised, in case we are the only user * of GObject in the process */ g_type_init (); dbus_proxy = dbus_connect (error); } if (dbus_proxy != NULL) g_object_ref (dbus_proxy); g_static_mutex_unlock (&init_lock); return dbus_proxy; }
static void filetype_add_to_tree(GTree *tree, const gchar *extension, const gchar *description, const gpointer func, const gint priority, const RSLoaderFlags flags) { RSFiletype *filetype = g_new(RSFiletype, 1); g_assert(rs_filetype_is_initialized); g_assert(tree != NULL); g_assert(extension != NULL); g_assert(extension[0] == '.'); g_assert(description != NULL); g_assert(func != NULL); g_assert(priority > 0); filetype->extension = g_strdup(extension); filetype->description = g_strdup(description); filetype->priority = priority; filetype->flags = flags; g_static_mutex_lock(&lock); g_tree_insert(tree, filetype, func); g_static_mutex_unlock(&lock); }
static gboolean fifo_read (GIOChannel *chan, GIOCondition cond, gpointer data) { char *command; gsize term; GError *err; gboolean ret; g_static_mutex_lock (&main_fifo_mutex); err = NULL; if (cond & G_IO_IN) { while (g_io_channel_read_line (chan, &command, NULL, &term, &err) == G_IO_STATUS_NORMAL) { command[term] = '\0'; fifo_execute (command); g_free (command); } if (err) { g_warning ("error reading fifo: %s", err->message); g_error_free (err); } } if (cond & G_IO_HUP || cond & G_IO_ERR) { fifo_close (); if (!fifo_open ()) { g_critical ("failed to reopen fifo"); main_quit (); } ret = FALSE; /* remove me from the watch */ } else ret = TRUE; g_static_mutex_unlock (&main_fifo_mutex); return ret; }
/** * z_policy_unref: * @self: this * * Decrements the reference counter of a ZProxy, freeing the instance if * the counter drops to zero. */ void z_policy_unref(ZPolicy *self) { g_static_mutex_lock(&policy_ref_lock); g_assert(self->ref_cnt > 0); --self->ref_cnt; /* NOTE: This reference counter counts two different reference types: * * the number of references to this ZPolicy instance by the rest of Zorp * * the number of internal references between ZPolicy and the * ZPolicyThread instances started in z_policy_new(): main thread * and notification thread * * The main and notification threads form circular references, their * destruction must be triggered somehow. Whenever the number of * references go low enough we trigger destruction, which will eventually * cause the refcounter to go to 0. * * The trigger to terminate the notification thread is also sent from * here, when the refcount goes to 3. * */ /* main thread */ #define ZPOLICY_BASE_REFCOUNT 1 if (self->ref_cnt == ZPOLICY_BASE_REFCOUNT) { /* ok, only the notification thread & main thread remains, start destructing them now */ g_static_mutex_unlock(&policy_ref_lock); z_policy_free(self); } else { g_static_mutex_unlock(&policy_ref_lock); } }
static void gst_alsasink_init (GstAlsaSink * alsasink, GstAlsaSinkClass * g_class) { GST_DEBUG_OBJECT (alsasink, "initializing alsasink"); alsasink->device = g_strdup (DEFAULT_DEVICE); alsasink->handle = NULL; alsasink->cached_caps = NULL; alsasink->alsa_lock = g_mutex_new (); alsasink->delay_lock = g_mutex_new (); g_static_mutex_lock (&output_mutex); if (output_ref == 0) { snd_output_stdio_attach (&output, stdout, 0); ++output_ref; } g_static_mutex_unlock (&output_mutex); gst_pad_set_acceptcaps_function (GST_BASE_SINK (alsasink)->sinkpad, GST_DEBUG_FUNCPTR (gst_alsasink_acceptcaps)); }
int g_string_get_time(GString *s, GTimeVal *gt) { time_t t = gt->tv_sec; #ifndef HAVE_GMTIME_R static GStaticMutex m = G_STATIC_MUTEX_INIT; /* gmtime() isn't thread-safe */ g_static_mutex_lock(&m); s->len = strftime(s->str, s->allocated_len, "%Y-%m-%dT%H:%M:%S.", gmtime(&(t))); g_static_mutex_unlock(&m); #else struct tm tm; gmtime_r(&(t), &tm); s->len = strftime(s->str, s->allocated_len, "%Y-%m-%dT%H:%M:%S.", &tm); #endif /* append microsec + Z */ g_string_append_printf(s, "%03ldZ", gt->tv_usec / 1000); return 0; }
static void empathy_audio_sink_volume_updated (GObject *object, GParamSpec *pspec, gpointer user_data) { EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (user_data); gdouble volume; g_static_mutex_lock (&self->priv->volume_mutex); g_object_get (object, "volume", &volume, NULL); if (self->priv->volume == volume) goto out; self->priv->volume = volume; if (self->priv->volume_idle_id == 0) self->priv->volume_idle_id = g_idle_add ( empathy_audio_sink_volume_idle_updated, self); out: g_static_mutex_unlock (&self->priv->volume_mutex); }
void gegl_buffer_cl_cache_new (GeglBuffer *buffer, const GeglRectangle *roi, cl_mem tex) { g_static_mutex_lock (&cache_mutex); { CacheEntry *e = g_slice_new (CacheEntry); e->buffer = buffer; e->tile_storage = buffer->tile_storage; e->roi = *roi; e->tex = tex; e->valid = TRUE; e->used = 0; cache_entries = g_list_prepend (cache_entries, e); } g_static_mutex_unlock (&cache_mutex); }
static Tuple *get_song_tuple(char *filename) { Tuple *tuple; xmp_context ctx2; int lret; struct xmp_module_info mi; struct xmp_options *opt; strip_vfs(filename); /* Sorry, no VFS support */ tuple = aud_tuple_new_from_filename(filename); /* Create new context to load a file and get the length */ ctx2 = xmp_create_context(); opt = xmp_get_options(ctx2); opt->skipsmp = 1; /* don't load samples */ g_static_mutex_lock(&load_mutex); lret = xmp_load_module(ctx2, filename); g_static_mutex_unlock(&load_mutex); if (lret < 0) { xmp_free_context(ctx2); return NULL; } xmp_get_module_info(ctx2, &mi); aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, mi.name); aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, mi.type); aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, lret); xmp_release_module(ctx2); xmp_free_context(ctx2); return tuple; }
static void gftpui_gtk_set_action (gftp_transfer * tdata, char * transfer_str, int transfer_action) { GList * templist, * filelist; gftp_file * tempfle; int curpos; g_static_mutex_lock (&tdata->structmutex); curpos = 0; filelist = tdata->files; templist = GTK_CLIST (tdata->clist)->selection; while (templist != NULL) { templist = get_next_selection (templist, &filelist, &curpos); tempfle = filelist->data; tempfle->transfer_action = transfer_action; gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, transfer_str); } g_static_mutex_unlock (&tdata->structmutex); }
/*! \brief update_logview_traces_pf() updates each trace in turn and then scrolls the display \param force_redraw flag to force all data to be redrawn not just the new data... \returns TRUE */ G_MODULE_EXPORT gboolean update_logview_traces_pf(gboolean force_redraw) { if (DATA_GET(global_data,"playback_mode")) return TRUE; if (!((DATA_GET(global_data,"connected")) && (DATA_GET(global_data,"interrogated")))) return FALSE; if (!lv_data) return FALSE; if ((lv_data->traces) && (g_list_length(lv_data->tlist) > 0)) { adj_scale = TRUE; g_static_mutex_lock(&update_mutex); trace_update(force_redraw); g_static_mutex_unlock(&update_mutex); scroll_logviewer_traces(); } return TRUE; }
static void setup_segv_redirect (void) { struct sigaction sa, osa; sigaction (SIGSEGV, NULL, &osa); if (osa.sa_handler == SIG_DFL) return; main_thread = pthread_self (); sa.sa_flags = 0; sigemptyset (&sa.sa_mask); sa.sa_handler = segv_redirect; sigaction (SIGSEGV, &sa, NULL); sigaction (SIGBUS, &sa, NULL); sigaction (SIGFPE, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGXFSZ, &sa, NULL); gnome_segv_handler = osa.sa_handler; g_static_mutex_lock (&segv_mutex); }
EXPORT_C #endif void gst_task_cleanup_all (void) { GstTaskClass *klass; if ((klass = g_type_class_peek (GST_TYPE_TASK))) { g_static_mutex_lock (&pool_lock); if (klass->pool) { /* Shut down all the threads, we still process the ones scheduled * because the unref happens in the thread function. * Also wait for currently running ones to finish. */ g_thread_pool_free (klass->pool, FALSE, TRUE); /* create new pool, so we can still do something after this * call. */ klass->pool = g_thread_pool_new ( (GFunc) gst_task_func, klass, -1, FALSE, NULL); } g_static_mutex_unlock (&pool_lock); } }
static void gftpui_gtk_set_action (gftp_transfer * tdata, int transfer_action) { GList * templist, * filelist; gftp_file * tempfle; GtkTreeSelection *select; GtkTreeIter iter; GtkTreeModel * model; g_static_mutex_lock (&tdata->structmutex); select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tdata->clist)); templist = gtk_tree_selection_get_selected_rows(select, &model); for (filelist = templist ; filelist != NULL; filelist = g_list_next(filelist)) { gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)filelist->data); gtk_tree_model_get(model, &iter, 0, &tempfle, -1); tempfle->transfer_action = transfer_action; } g_list_foreach (templist, (GFunc) gtk_tree_path_free, NULL); g_list_free (templist); g_static_mutex_unlock (&tdata->structmutex); }
/** * uca_camera_trigger: * @camera: A #UcaCamera object * @error: Location to store a #UcaCameraError error or %NULL * * Trigger from software if supported by camera. * * You must have called uca_camera_start_recording() before, otherwise you will * get a #UCA_CAMERA_ERROR_NOT_RECORDING error. */ void uca_camera_trigger (UcaCamera *camera, GError **error) { UcaCameraClass *klass; static GStaticMutex mutex = G_STATIC_MUTEX_INIT; g_return_if_fail (UCA_IS_CAMERA (camera)); klass = UCA_CAMERA_GET_CLASS (camera); g_return_if_fail (klass != NULL); g_return_if_fail (klass->trigger != NULL); g_static_mutex_lock (&mutex); if (!camera->priv->is_recording) g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, "Camera is not recording"); else { (*klass->trigger) (camera, error); } g_static_mutex_unlock (&mutex); }
/* * When this is called, it is assumed that the output thread is currently * not running (since this is the function that wakes it up), thus we can * access the length of the output queue without acquiring a lock. Memory * barriers are covered by the use of the self->lock mutex, since * push_notify is registered under the protection of self->lock and after * that the length of the output queue will not change (since parallel_push * is only registered if it has less than enough items). * * NOTE: self->lock must have been acquired before calling this function. */ void log_queue_push_notify(LogQueue *self) { if (self->parallel_push_notify) { /* make sure the callback can call log_queue_check_items() again */ GDestroyNotify destroy = self->parallel_push_data_destroy; gpointer user_data = self->parallel_push_data; LogQueuePushNotifyFunc func = self->parallel_push_notify; self->parallel_push_data = NULL; self->parallel_push_data_destroy = NULL; self->parallel_push_notify = NULL; g_static_mutex_unlock(&self->lock); func(user_data); if (destroy && user_data) destroy(user_data); g_static_mutex_lock(&self->lock); } }
static gboolean restart_resolve (void) { static GTimeVal last_reload = { 0, 0 }; static GStaticMutex mutex = G_STATIC_MUTEX_INIT; GTimeVal now; gboolean ret; g_static_mutex_lock (&mutex); g_get_current_time (&now); if ((now.tv_sec - last_reload.tv_sec) > RELOAD_TIMEVAL) { last_reload.tv_sec = now.tv_sec; ret = (res_ninit (&_res) == 0); } else { ret = FALSE; } g_static_mutex_unlock (&mutex); return ret; }
void _mate_vfs_async_job_callback_valid (guint callback_id, gboolean *valid, gboolean *cancelled) { MateVFSNotifyResult *notify_result; g_static_mutex_lock (&async_job_callback_map_lock); if (async_job_callback_map == NULL) { g_assert (async_job_map_shutting_down); *valid = FALSE; *cancelled = FALSE; } notify_result = (MateVFSNotifyResult *) g_hash_table_lookup (async_job_callback_map, GUINT_TO_POINTER (callback_id)); *valid = notify_result != NULL; *cancelled = notify_result != NULL && notify_result->cancelled; g_static_mutex_unlock (&async_job_callback_map_lock); }
event_handle_t * event_create( event_id_t data, event_type_t type, event_fn_t fn, void *arg) { event_handle_t *handle; g_static_mutex_lock(&event_mutex); /* sanity-checking */ if ((type == EV_READFD) || (type == EV_WRITEFD)) { /* make sure we aren't given a high fd that will overflow a fd_set */ if (data >= (int)FD_SETSIZE) { error(_("event_register: Invalid file descriptor %jd"), data); /*NOTREACHED*/ } } else if (type == EV_TIME) { if (data <= 0) { error(_("event_register: interval for EV_TIME must be greater than 0; got %jd"), data); } } handle = g_new0(event_handle_t, 1); handle->fn = fn; handle->arg = arg; handle->type = type; handle->data = data; handle->is_dead = FALSE; event_debug(1, _("event: register: %p->data=%jd, type=%s\n"), handle, handle->data, event_type2str(handle->type)); g_static_mutex_unlock(&event_mutex); return handle; }
static void *gtk_thread_func(void *data) { GAsyncQueue *queue = data; int argc = 0; char **argv = NULL; bool again; ALLEGRO_DEBUG("Calling gtk_init_check.\n"); if (gtk_init_check(&argc, &argv)) { g_async_queue_push(queue, ACK_OK); } else { ALLEGRO_ERROR("GTK initialisation failed.\n"); g_async_queue_push(queue, ACK_ERROR); return NULL; } do { ALLEGRO_INFO("Entering GTK main loop.\n"); gtk_main(); /* Re-enter the main loop if a new window was created soon after the last * one was destroyed, which caused us to drop out of the GTK main loop. */ g_static_mutex_lock(>k_lock); if (window_counter == 0) { gtk_thread = NULL; again = false; } else { again = true; } g_static_mutex_unlock(>k_lock); } while (again); ALLEGRO_INFO("GTK stopped.\n"); return NULL; }
static bool ensure_gtk_thread(void) { bool ok = true; #if !GLIB_CHECK_VERSION(2, 32, 0) if (!g_thread_supported()) g_thread_init(NULL); #endif g_static_mutex_lock(>k_lock); if (!gtk_thread) { GAsyncQueue *queue = g_async_queue_new(); #if GLIB_CHECK_VERSION(2, 32, 0) gtk_thread = g_thread_new("gtk thread", gtk_thread_func, queue); #else bool joinable = FALSE; gtk_thread = g_thread_create(gtk_thread_func, queue, joinable, NULL); #endif if (!gtk_thread) { ok = false; } else { ok = (g_async_queue_pop(queue) == ACK_OK); } g_async_queue_unref(queue); } if (ok) { ++window_counter; ALLEGRO_DEBUG("++window_counter = %d\n", window_counter); } g_static_mutex_unlock(>k_lock); return ok; }
/** * ufo_op_gradient_directions: * @arg: A #UfoBuffer * @magnitudes: A #UfoBuffer * @out: A #UfoBuffer * @resources: #UfoResources object * @command_queue: A valid cl_command_queue * * Compute magnitude of gradients * * Returns: (transfer full): Event of the add operation */ gpointer ufo_op_gradient_directions (UfoBuffer *arg, UfoBuffer *magnitudes, UfoBuffer *out, UfoResources *resources, gpointer command_queue) { UfoRequisition arg_requisition; cl_event event; GError *error = NULL; static GStaticMutex mutex = G_STATIC_MUTEX_INIT; ufo_buffer_get_requisition (arg, &arg_requisition); ufo_buffer_resize (out, &arg_requisition); cl_mem d_arg = ufo_buffer_get_device_image (arg, command_queue); cl_mem d_magnitudes = ufo_buffer_get_device_image (magnitudes, command_queue); cl_mem d_out = ufo_buffer_get_device_image (out, command_queue); cl_kernel kernel = ufo_resources_get_cached_kernel (resources, OPS_FILENAME, "operation_gradient_direction", &error); if (error) { g_error ("%s\n", error->message); } g_static_mutex_lock (&mutex); UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (kernel, 0, sizeof(void *), (void *) &d_arg)); UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (kernel, 1, sizeof(void *), (void *) &d_magnitudes)); UFO_RESOURCES_CHECK_CLERR (clSetKernelArg (kernel, 2, sizeof(void *), (void *) &d_out)); UFO_RESOURCES_CHECK_CLERR (clEnqueueNDRangeKernel (command_queue, kernel, arg_requisition.n_dims, NULL, arg_requisition.dims, NULL, 0, NULL, &event)); g_static_mutex_unlock (&mutex); return event; }
void gftpui_common_skip_file_transfer (gftp_transfer * tdata, gftp_file * curfle) { g_static_mutex_lock (&tdata->structmutex); if (tdata->started && !(curfle->transfer_action & GFTP_TRANS_ACTION_SKIP)) { curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; if (tdata->curfle != NULL && curfle == tdata->curfle->data) { gftpui_cancel_file_transfer (tdata); tdata->skip_file = 1; } else if (!curfle->transfer_done) tdata->total_bytes -= curfle->size; } g_static_mutex_unlock (&tdata->structmutex); if (curfle != NULL) tdata->fromreq->logging_function (gftp_logging_misc, tdata->fromreq, _("Skipping file %s on host %s\n"), curfle->file, tdata->toreq->hostname); }
// If tracing is enabled globally or for the current thread, print a // message describing a transaction. The message string consists of a // sring identifying the current thread as well as possible (using the // name if available in the thread_names hash, and the thread object // address in any case), followed by a space, followed by the // transaction message, followed by a newline. static void maybe_trace (ECLock *self, const char *transaction) { g_static_mutex_lock (self->trace_lock); { if ( self->trace_on || my_g_hash_table_entry_exists (self->traced_threads, g_thread_self ()) ) { GString *message = g_string_new ("Thread "); GString *thread_name = g_hash_table_lookup (self->thread_names, g_thread_self ()); if ( thread_name != NULL ) { g_string_append_printf (message, "named '%s' ", thread_name->str); } g_string_append_printf (message, "at location %p ", g_thread_self ()); g_string_append_printf (message, "%s\n", transaction); g_debug (message->str); my_g_string_free (message); } } g_static_mutex_unlock (self->trace_lock); }