static void set_send_status (struct _send_info *info, const gchar *desc, gint pc) { g_static_mutex_lock (&status_lock); g_free (info->what); info->what = g_strdup (desc); info->pc = pc; g_static_mutex_unlock (&status_lock); }
/** * 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 StdLoggerDestroy(gpointer data) { #if defined(_WIN32) StdLogger *sdata = data; g_static_mutex_lock(&gConsoleLock); if (sdata->attached && --gRefCount == 0) { FreeConsole(); } g_static_mutex_unlock(&gConsoleLock); #endif g_free(data); }
ArvInterface * arv_fake_interface_get_instance (void) { g_static_mutex_lock (&fake_interface_mutex); if (fake_interface == NULL) fake_interface = g_object_new (ARV_TYPE_FAKE_INTERFACE, NULL); g_static_mutex_unlock (&fake_interface_mutex); return ARV_INTERFACE (fake_interface); }
void target_pool_delete(struct target_pool *pool) { g_return_if_fail(pool!=NULL); g_static_mutex_lock(&pool->mutex); if(pool->freer_data_num==0) { target_pool_really_delete(pool); return; /* don't unlock the mutex */ } else { pool->deleted=true; } g_static_mutex_unlock(&pool->mutex); }
/** * g_static_rw_lock_writer_unlock: * @lock: a #GStaticRWLock to unlock after writing. * * Unlocks @lock. If a thread is waiting to lock @lock for writing and * all locks for reading have been unlocked, the waiting thread is * woken up and can lock @lock for writing. If no thread is waiting to * lock @lock for writing, and some thread or threads are waiting to * lock @lock for reading, the waiting threads are woken up and can * lock @lock for reading. * * Deprectated: 2.32: Use g_rw_lock_writer_unlock() instead */ void g_static_rw_lock_writer_unlock (GStaticRWLock* lock) { g_return_if_fail (lock); if (!g_threads_got_initialized) return; g_static_mutex_lock (&lock->mutex); lock->have_writer = FALSE; g_static_rw_lock_signal (lock); g_static_mutex_unlock (&lock->mutex); }
void db_close_table(void) { if (tablep) sqlite3_free_table(tablep); else g_print("ERROR: TABLE CLOSED TWICE!\n"); tablep = NULL; #if (GTKVER == 3) G_UNLOCK(table_mutex); #else g_static_mutex_unlock(&table_mutex); #endif }
static gboolean log_writer_suppress_timeout(gpointer pt) { LogWriter *self = (LogWriter *) pt; main_loop_assert_main_thread(); g_static_mutex_lock(&self->suppress_lock); log_writer_emit_suppress_summary(self); g_static_mutex_unlock(&self->suppress_lock); return FALSE; }
static gboolean empathy_audio_sink_volume_idle_updated (gpointer user_data) { EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (user_data); g_static_mutex_lock (&self->priv->volume_mutex); self->priv->volume_idle_id = 0; g_static_mutex_unlock (&self->priv->volume_mutex); g_object_notify (G_OBJECT (self), "volume"); return FALSE; }
void afinter_message_posted(LogMessage *msg) { g_static_mutex_lock(&internal_msg_lock); if (!internal_msg_queue) { internal_msg_queue = g_queue_new(); } g_queue_push_tail(internal_msg_queue, msg); if (current_internal_source) iv_event_post(¤t_internal_source->post); g_static_mutex_unlock(&internal_msg_lock); }
static void insert_result_common (struct rspamd_task *task, const gchar *symbol, double flag, GList * opts, gboolean single) { struct metric *metric; GList *cur, *metric_list; /* Avoid concurrenting inserting of results */ #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) g_static_mutex_lock (&result_mtx); #else G_LOCK (result_mtx); #endif metric_list = g_hash_table_lookup (task->cfg->metrics_symbols, symbol); if (metric_list) { cur = metric_list; while (cur) { metric = cur->data; insert_metric_result (task, metric, symbol, flag, opts, single); cur = g_list_next (cur); } } else { /* Insert symbol to default metric */ insert_metric_result (task, task->cfg->default_metric, symbol, flag, opts, single); } /* Process cache item */ if (task->cfg->cache) { rspamd_symbols_cache_inc_frequency (task->cfg->cache, symbol); } if (opts != NULL) { /* XXX: it is not wise to destroy them here */ g_list_free (opts); } #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) g_static_mutex_unlock (&result_mtx); #else G_UNLOCK (result_mtx); #endif }
/* * log_tags_get_by_name * * Lookup a tag id by it's name. If the tag is seen for the first time * the next tag id is assigned and the tag is added to the list. * * The function returns the tag id associated with the name. * * @name: the name of the tag * */ LogTagId log_tags_get_by_name(const gchar *name) { /* If log_tags_hash() is NULL, this unit is already deinitialized but other thread may refer the tag structure. If name is empty, it is an extremal element. In both cases the return value is 0. */ guint id; g_assert(log_tags_hash != NULL); g_static_mutex_lock(&log_tags_lock); id = GPOINTER_TO_UINT(g_hash_table_lookup(log_tags_hash, name)) - 1; if (id == 0xffffffff) { if (log_tags_num < LOG_TAGS_MAX - 1) { id = log_tags_num++; if (id == log_tags_list_size) { log_tags_list_size *= 2; log_tags_list = g_renew(LogTag, log_tags_list, log_tags_list_size); } log_tags_list[id].id = id; log_tags_list[id].name = g_strdup(name); log_tags_list[id].counter = NULL; /* NOTE: stats-level may not be set for calls that happen during * config file parsing, those get fixed up by * log_tags_reinit_stats() below */ stats_lock(); StatsClusterKey sc_key; stats_cluster_logpipe_key_set(&sc_key, SCS_TAG, name, NULL ); stats_register_counter(3, &sc_key, SC_TYPE_PROCESSED, &log_tags_list[id].counter); stats_unlock(); g_hash_table_insert(log_tags_hash, log_tags_list[id].name, GUINT_TO_POINTER(log_tags_list[id].id + 1)); } else id = 0; } g_static_mutex_unlock(&log_tags_lock); return id; }
static void remove_old_files (TnyFsStreamCache *self, gint64 required_size) { /* 1. we obtain a list of non active files * 2. we sort the list (first uncomplete, then old) * 3. we get items in list and remove them until we have the required size */ GList *cached_files_list; TnyFsStreamCachePriv *priv = TNY_FS_STREAM_CACHE_GET_PRIVATE (self); gint64 available_size; /* 1. we obtain a list of non active files */ cached_files_list = NULL; g_static_mutex_lock (priv->cache_lock); g_hash_table_foreach (priv->cached_files, (GHFunc) get_inactive_files_list, &cached_files_list); g_static_mutex_unlock (priv->cache_lock); /* 2. we sort the list (first uncomplete, then old) */ cached_files_list = g_list_sort (cached_files_list, (GCompareFunc) remove_priority); /* 3. we get items in list and remove them until we have the required size */ available_size = get_free_space (self); while (available_size < required_size) { TnyCachedFile *cached_file = (TnyCachedFile *) cached_files_list->data; available_size += tny_cached_file_get_expected_size (cached_file); g_static_mutex_lock (priv->cache_lock); g_hash_table_remove (priv->cached_files, tny_cached_file_get_id (cached_file)); g_static_mutex_unlock (priv->cache_lock); tny_cached_file_remove (cached_file); cached_files_list = g_list_delete_link (cached_files_list, cached_files_list); g_object_unref (cached_file); } g_list_foreach (cached_files_list, (GFunc) g_object_unref, NULL); g_list_free (cached_files_list); }
/** * g_static_rw_lock_reader_unlock: * @lock: a #GStaticRWLock to unlock after reading * * Unlocks @lock. If a thread waits to lock @lock for writing and all * locks for reading have been unlocked, the waiting thread is woken up * and can lock @lock for writing. * * Deprectated: 2.32: Use g_rw_lock_reader_unlock() instead */ void g_static_rw_lock_reader_unlock (GStaticRWLock* lock) { g_return_if_fail (lock); if (!g_threads_got_initialized) return; g_static_mutex_lock (&lock->mutex); lock->read_counter--; if (lock->read_counter == 0) g_static_rw_lock_signal (lock); g_static_mutex_unlock (&lock->mutex); }
/* set initial values for the next level */ static void wordsgame_next_level() { #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_lock (&items_lock); #else g_static_mutex_lock (&items_lock); #endif wordsgame_next_level_unlocked(); #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_unlock (&items_lock); #else g_static_mutex_unlock (&items_lock); #endif }
gboolean linphone_gtk_check_logs(){ GList *elem; g_static_mutex_lock(&log_mutex); for(elem=log_queue;elem!=NULL;elem=elem->next){ LinphoneGtkLog *lgl=(LinphoneGtkLog*)elem->data; linphone_gtk_display_log(lgl->lev,lgl->msg); g_free(lgl->msg); g_free(lgl); } if (log_queue) g_list_free(log_queue); log_queue=NULL; g_static_mutex_unlock(&log_mutex); return TRUE; }
void _backlog_all(LogQueue *s) { LogQueueDisk *self = (LogQueueDisk *) s; g_static_mutex_lock(&self->super.lock); if (self->rewind_backlog) { self->rewind_backlog(self, -1); } g_static_mutex_unlock(&self->super.lock); }
static void _rewind_backlog(LogQueue *s, guint rewind_count) { LogQueueDisk *self = (LogQueueDisk *) s; g_static_mutex_lock(&self->super.lock); if (self->rewind_backlog) { self->rewind_backlog (self, rewind_count); } g_static_mutex_unlock(&self->super.lock); }
static void _ack_backlog(LogQueue *s, gint num_msg_to_ack) { LogQueueDisk *self = (LogQueueDisk *) s; g_static_mutex_lock(&self->super.lock); if (self->ack_backlog) { self->ack_backlog(self, num_msg_to_ack); } g_static_mutex_unlock(&self->super.lock); }
/** * gst_tag_setter_set_tag_merge_mode: * @setter: a #GstTagSetter * @mode: The mode with which tags are added * * Sets the given merge mode that is used for adding tags from events to tags * specified by this interface. The default is #GST_TAG_MERGE_KEEP, which keeps * the tags set with this interface and discards tags from events. */ void gst_tag_setter_set_tag_merge_mode (GstTagSetter * setter, GstTagMergeMode mode) { GstTagData *data; g_return_if_fail (GST_IS_TAG_SETTER (setter)); g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); data = gst_tag_setter_get_data (setter); g_static_mutex_lock (&data->lock); data->mode = mode; g_static_mutex_unlock (&data->lock); }
/* * log_tag_get_by_id * * Lookup a tag name by it's id. If the id is invalid * NULL is returned, otherwise a gchar * is returned * pointing to the name of the tag. * * The returned pointer should not be freed. * * @id: the tag id to lookup * */ const gchar * log_tags_get_by_id(LogTagId id) { gchar *name = NULL; g_static_mutex_lock(&log_tags_lock); if (id < log_tags_num) name = log_tags_list[id].name; g_static_mutex_unlock(&log_tags_lock); return name; }
const char * I18n_GetString(const char *domain, const char *msgid) { const char *idp; const char *strp; char idBuf[MSG_MAX_ID]; size_t len; GHashTable *source = NULL; MsgCatalog *catalog; MsgState *state = MsgGetState(); /* All message strings must be prefixed by the message ID. */ ASSERT(domain != NULL); ASSERT(msgid != NULL); ASSERT(MsgHasMsgID(msgid)); /* * Find the beginning of the ID (idp) and the string (strp). * The string should have the correct MSG_MAGIC(...)... form. */ idp = msgid + MSG_MAGIC_LEN + 1; strp = strchr(idp, ')') + 1; len = strp - idp - 1; ASSERT(len <= MSG_MAX_ID - 1); memcpy(idBuf, idp, len); idBuf[len] = '\0'; g_static_mutex_lock(&state->lock); catalog = MsgGetCatalog(domain); if (catalog != NULL) { source = catalog->utf8; } if (source != NULL) { const void *retval = NULL; retval = g_hash_table_lookup(source, idBuf); if (NULL != retval) { strp = retval; } } g_static_mutex_unlock(&state->lock); return strp; }
static gint64 get_free_space (TnyFsStreamCache *self) { TnyFsStreamCachePriv *priv; guint64 files_size = 0; priv = TNY_FS_STREAM_CACHE_GET_PRIVATE (self); g_static_mutex_lock (priv->cache_lock); g_hash_table_foreach (priv->cached_files, (GHFunc) count_files_size, &files_size); g_static_mutex_unlock (priv->cache_lock); /* if available size < 0 it means we shrinked cache and we need to drop files */ return priv->max_size - files_size; }
static void log_writer_work_finished(gpointer s) { LogWriter *self = (LogWriter *) s; main_loop_assert_main_thread(); self->flush_waiting_for_timeout = FALSE; 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); if (self->proto) log_proto_free(self->proto); self->proto = self->pending_proto; self->pending_proto = NULL; self->pending_proto_present = FALSE; g_cond_signal(self->pending_proto_cond); g_static_mutex_unlock(&self->pending_proto_lock); } if (!self->work_result) { log_writer_broken(self, NC_WRITE_ERROR); if (self->proto) { log_writer_suspend(self); msg_notice("Suspending write operation because of an I/O error", evt_tag_int("fd", log_proto_get_fd(self->proto)), evt_tag_int("time_reopen", self->options->time_reopen), NULL); } goto exit; } if ((self->super.flags & PIF_INITIALIZED) && self->proto) { /* reenable polling the source, but only if we're still initialized */ log_writer_start_watches(self); } exit: log_pipe_unref(&self->super); }
NVHandle nv_registry_alloc_handle(NVRegistry *self, const gchar *name) { gpointer p; NVHandleDesc stored; gsize len; NVHandle res = 0; g_static_mutex_lock(&nv_registry_lock); p = g_hash_table_lookup(self->name_map, name); if (p) { res = GPOINTER_TO_UINT(p); goto exit; } len = strlen(name); if (len == 0) { msg_error("Name-value pairs cannot have a zero-length name", evt_tag_str("value", name), NULL); goto exit; } else if (len > 255) { msg_error("Value names cannot be longer than 255 characters, this value will always expand to the emptry string", evt_tag_str("value", name), NULL); goto exit; } else if (self->names->len >= 65535) { msg_error("Hard wired limit of 65535 name-value pairs have been reached, all further name-value pair will expand to nothing", evt_tag_str("value", name), NULL); goto exit; } /* flags (2 bytes) || length (1 byte) || name (len bytes) || NUL */ /* memory layout: flags || length || name (NUL terminated) */ stored.flags = 0; stored.name_len = len; stored.name = g_strdup(name); g_array_append_val(self->names, stored); g_hash_table_insert(self->name_map, stored.name, GUINT_TO_POINTER(self->names->len)); res = self->names->len; exit: g_static_mutex_unlock(&nv_registry_lock); return res; }
/** * gst_query_type_iterate_definitions: * * Get a #GstIterator of all the registered query types. The definitions * iterated over are read only. * * Returns: A #GstIterator of #GstQueryTypeDefinition. */ GstIterator * gst_query_type_iterate_definitions (void) { GstIterator *result; g_static_mutex_lock (&mutex); /* FIXME: register a boxed type for GstQueryTypeDefinition */ result = gst_iterator_new_list (G_TYPE_POINTER, g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL, NULL); g_static_mutex_unlock (&mutex); return result; }
unsigned token_count (void) { unsigned N; if (token_table == NULL) return 0; g_static_mutex_lock (&token_mutex); N = g_hash_table_size (token_table); g_static_mutex_unlock (&token_mutex); return N; }
static void FileLoggerLog(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer data) { FileLogger *logger = data; gsize written; g_static_mutex_lock(&logger->lock); if (logger->error) { goto exit; } if (logger->file == NULL) { if (logger->file == NULL) { logger->file = FileLoggerOpen(data); } if (logger->file == NULL) { logger->error = TRUE; goto exit; } } if (!FileLoggerIsValid(logger)) { logger->error = TRUE; goto exit; } /* Write the log file and do log rotation accounting. */ if (g_io_channel_write_chars(logger->file, message, -1, &written, NULL) == G_IO_STATUS_NORMAL) { if (logger->maxSize > 0) { logger->logSize += (gint) written; if (logger->logSize >= logger->maxSize) { g_io_channel_unref(logger->file); logger->append = FALSE; logger->file = FileLoggerOpen(logger); } else { g_io_channel_flush(logger->file, NULL); } } else { g_io_channel_flush(logger->file, NULL); } } exit: g_static_mutex_unlock(&logger->lock); }
static gpointer queue_worker(gpointer data) { GAsyncQueue *queue = data; RSIoJob *job; while (1) { if (pause_queue) g_usleep(1000); else { g_static_mutex_lock(&count_lock); job = g_async_queue_try_pop(queue); if (job) queue_active_count++; g_static_mutex_unlock(&count_lock); /* If we somehow got NULL, continue. I'm not sure this will ever happen, but this is better than random segfaults :) */ if (job) { rs_io_job_execute(job); rs_io_job_do_callback(job); g_static_mutex_lock(&count_lock); queue_active_count--; g_static_mutex_unlock(&count_lock); } else { /* Sleep 1 ms */ g_usleep(1000); } } } return NULL; }
/** * uca_camera_start_readout: * @camera: A #UcaCamera object * @error: Location to store a #UcaCameraError error or %NULL * * Initiate readout mode for cameras that support * #UcaCamera:has-camram-recording after calling * uca_camera_stop_recording(). Frames have to be picked up with * ufo_camera_grab(). */ void uca_camera_start_readout (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->start_readout != NULL); g_static_mutex_lock (&mutex); if (camera->priv->is_recording) { g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_RECORDING, "Camera is still recording"); } else { GError *tmp_error = NULL; g_static_mutex_lock (&access_lock); (*klass->start_readout) (camera, &tmp_error); g_static_mutex_unlock (&access_lock); if (tmp_error == NULL) { camera->priv->is_readout = TRUE; /* TODO: we should depend on GLib 2.26 and use g_object_notify_by_pspec */ g_object_notify (G_OBJECT (camera), "is-readout"); } else g_propagate_error (error, tmp_error); } g_static_mutex_unlock (&mutex); }