/** * g_thread_pool_set_max_idle_time: * @interval: the maximum @interval (in milliseconds) * a thread can be idle * * This function will set the maximum @interval that a thread * waiting in the pool for new tasks can be idle for before * being stopped. This function is similar to calling * g_thread_pool_stop_unused_threads() on a regular timeout, * except this is done on a per thread basis. * * By setting @interval to 0, idle threads will not be stopped. * * This function makes use of g_async_queue_timed_pop () using * @interval. * * Since: 2.10 */ void g_thread_pool_set_max_idle_time (guint interval) { guint i; g_atomic_int_set (&max_idle_time, interval); i = g_atomic_int_get (&unused_threads); if (i > 0) { g_atomic_int_inc (&wakeup_thread_serial); g_async_queue_lock (unused_thread_queue); do { g_async_queue_push_unlocked (unused_thread_queue, wakeup_thread_marker); } while (--i); g_async_queue_unlock (unused_thread_queue); } }
/* Returns TRUE iff it holds the mutex lock */ gboolean prepare(GSource* source, gint* timeout) { assert(source == &curlSrc->source); D((stderr, "prepare: callPerform=%d, thread=%p\n", curlSrc->callPerform, curlSrc->selectThread)); *timeout = -1; if (g_atomic_int_dec_and_test(&curlSrc->gtkBlockAndWait)) { /* The select thread wants us to block */ D((stderr, "prepare: trying lock\n")); g_mutex_lock(curlSrc->mutex); D((stderr, "prepare: got lock\n")); return TRUE; } else { g_atomic_int_inc(&curlSrc->gtkBlockAndWait); } /* Usual behaviour: Nothing happened, so don't dispatch. */ if (!curlSrc->callPerform) return FALSE; /* Always dispatch if callPerform, i.e. 1st download just starting. */ D((stderr, "prepare: trying lock 2\n")); /* Problem: We can block up to GLIBCURL_TIMEOUT msecs here, until the select() call returns. However, under Win32 this does not appear to be a problem (don't know why) - it _does_ tend to block the GTK thread under Linux. */ g_mutex_lock(curlSrc->mutex); D((stderr, "prepare: got lock 2\n")); curlSrc->callPerform = FALSE; if (curlSrc->selectThread == NULL) { D((stderr, "prepare: starting select thread\n")); /* Note that the thread will stop soon because we hold mutex */ curlSrc->selectThread = g_thread_create(&selectThread, 0, FALSE, NULL); assert(curlSrc->selectThread != NULL); } return TRUE; }
static GtkWidget* createWindow(WebKitWebView** outWebView) { WebKitWebView *webView; GtkWidget *vbox; GtkWidget *window; GtkWidget *uriEntry; GtkWidget *statusbar; g_atomic_int_inc(&windowCount); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); gtk_widget_set_name(window, "GtkLauncher"); webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); uriEntry = gtk_entry_new(); #ifdef GTK_API_VERSION_2 vbox = gtk_vbox_new(FALSE, 0); #else vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #endif statusbar = createStatusbar(webView); gtk_box_pack_start(GTK_BOX(vbox), createToolbar(uriEntry, webView), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), createBrowser(window, uriEntry, statusbar, webView, vbox), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); g_signal_connect(window, "destroy", G_CALLBACK(destroyCb), NULL); if (outWebView) *outWebView = webView; return window; }
static gpointer test_threads_thread_func3 (gpointer data) { GstTocSetter *setter = GST_TOC_SETTER (data); GTimer *timer; timer = g_timer_new (); g_atomic_int_inc (&threads_running); while (g_atomic_int_get (&spin_and_wait)) g_usleep (0); GST_INFO ("Go!"); g_timer_start (timer); while (g_timer_elapsed (timer, NULL) < THREADS_TEST_SECONDS) { gst_toc_setter_reset (setter); } g_timer_destroy (timer); GST_INFO ("Done"); return NULL; }
void _gdk_mir_event_source_queue (GdkMirWindowReference *window_ref, const MirEvent *event) { GdkMirEventSource *source = window_ref->source; GdkMirQueuedEvent *queued_event; /* We are in the wrong thread right now. We absolutely cannot touch * the window. * * We can do pretty much anything we want with the source, though... */ queued_event = g_slice_new (GdkMirQueuedEvent); g_atomic_int_inc (&window_ref->ref_count); queued_event->window_ref = window_ref; queued_event->event = event; g_mutex_lock (&source->mir_event_lock); g_queue_push_tail (&source->mir_events, queued_event); g_mutex_unlock (&source->mir_event_lock); g_main_context_wakeup (NULL); }
static gboolean gst_mfx_window_wayland_render (GstMfxWindow * window, GstMfxSurface * surface, const GstMfxRectangle * src_rect, const GstMfxRectangle * dst_rect) { GstMfxWindowWaylandPrivate *const priv = GST_MFX_WINDOW_WAYLAND_GET_PRIVATE (window); GstMfxDisplayWaylandPrivate *const display_priv = GST_MFX_DISPLAY_WAYLAND_GET_PRIVATE (GST_MFX_WINDOW_DISPLAY (window)); struct wl_display *const display = GST_MFX_DISPLAY_HANDLE (GST_MFX_WINDOW_DISPLAY (window)); GstMfxPrimeBufferProxy *buffer_proxy; struct wl_buffer *buffer; FrameState *frame; guintptr fd = 0; guint32 drm_format = 0; gint offsets[3] = { 0 }, pitches[3] = { 0 }, num_planes = 0, i = 0; VaapiImage *vaapi_image; buffer_proxy = gst_mfx_prime_buffer_proxy_new_from_surface (surface); if (!buffer_proxy) return FALSE; fd = GST_MFX_PRIME_BUFFER_PROXY_HANDLE (buffer_proxy); vaapi_image = gst_mfx_prime_buffer_proxy_get_vaapi_image (buffer_proxy); num_planes = vaapi_image_get_plane_count (vaapi_image); if ((dst_rect->height != src_rect->height) || (dst_rect->width != src_rect->width)) { #ifdef USE_WESTON_4_0 if (priv->wp_viewport) { wp_viewport_set_destination (priv->wp_viewport, dst_rect->width, dst_rect->height); } #else if (priv->viewport) { wl_viewport_set_destination (priv->viewport, dst_rect->width, dst_rect->height); } #endif } for (i = 0; i < num_planes; i++) { offsets[i] = vaapi_image_get_offset (vaapi_image, i); pitches[i] = vaapi_image_get_pitch (vaapi_image, i); } if (GST_VIDEO_FORMAT_NV12 == vaapi_image_get_format (vaapi_image)) { drm_format = WL_DRM_FORMAT_NV12; } else if (GST_VIDEO_FORMAT_BGRA == vaapi_image_get_format (vaapi_image)) { drm_format = WL_DRM_FORMAT_ARGB8888; } if (!drm_format) goto error; if (!display_priv->drm) goto error; GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); buffer = wl_drm_create_prime_buffer (display_priv->drm, fd, src_rect->width, src_rect->height, drm_format, offsets[0], pitches[0], offsets[1], pitches[1], offsets[2], pitches[2]); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); if (!buffer) { GST_ERROR ("No wl_buffer created\n"); goto error; } frame = frame_state_new (window); if (!frame) goto error; g_atomic_pointer_set (&priv->last_frame, frame); g_atomic_int_inc (&priv->num_frames_pending); GST_MFX_DISPLAY_LOCK (GST_MFX_WINDOW_DISPLAY (window)); wl_surface_attach (priv->surface, buffer, 0, 0); wl_surface_damage (priv->surface, 0, 0, dst_rect->width, dst_rect->height); if (priv->opaque_region) { wl_surface_set_opaque_region (priv->surface, priv->opaque_region); wl_region_destroy (priv->opaque_region); priv->opaque_region = NULL; } wl_proxy_set_queue ((struct wl_proxy *) buffer, priv->event_queue); wl_buffer_add_listener (buffer, &frame_buffer_listener, frame); frame->callback = wl_surface_frame (priv->surface); wl_callback_add_listener (frame->callback, &frame_callback_listener, frame); wl_surface_commit (priv->surface); wl_display_flush (display); GST_MFX_DISPLAY_UNLOCK (GST_MFX_WINDOW_DISPLAY (window)); vaapi_image_unref (vaapi_image); gst_mfx_prime_buffer_proxy_unref (buffer_proxy); return TRUE; error: { vaapi_image_unref (vaapi_image); gst_mfx_prime_buffer_proxy_unref (buffer_proxy); return FALSE; } }
void seaf_repo_ref (SeafRepo *repo) { g_atomic_int_inc (&repo->ref_cnt); }
void init_mock_requester (GrlNetWc *self) { g_atomic_int_inc (&refcount); if (refcount > 1) { return; } char *config_filename = g_strdup (g_getenv (GRL_NET_MOCKED_VAR)); enable_mocking = FALSE; int i; if (config_filename == NULL) { return; } /* Read configuration file. */ GError *error = NULL; config = g_key_file_new (); GRL_DEBUG ("Loading mock responses from \"%s\"", config_filename); g_key_file_load_from_file (config, config_filename, G_KEY_FILE_NONE, &error); int version = 0; if (error) { GRL_WARNING ("Failed to load mock file \"%s\": %s", config_filename, error->message); g_clear_error (&error); } else { /* Check if we managed to load a file */ version = g_key_file_get_integer (config, "default", "version", &error); if (error || version < GRL_NET_MOCK_VERSION) { GRL_WARNING ("Unsupported mock version."); g_clear_error (&error); } else { enable_mocking = TRUE; } } if (!enable_mocking) { g_free (config_filename); g_clear_pointer (&config, g_key_file_unref); return; } char **parameter_names = g_key_file_get_string_list (config, "default", "ignored-parameters", NULL, NULL); /* Build regular expressions for ignored query parameters. */ if (parameter_names) { GString *pattern = g_string_new ("(?:^|\\&)"); if (parameter_names[0] && strcmp(parameter_names[0], "*") == 0) { g_string_append (pattern, "[^=&]+"); } else { g_string_append (pattern, "(?:"); for (i = 0; parameter_names[i]; ++i) { if (i) g_string_append (pattern, "|"); char *escaped = g_regex_escape_string (parameter_names[i], -1); g_string_append (pattern, escaped); g_free (escaped); } g_string_append (pattern, ")(?:=[^&]*)?"); } ignored_parameters = g_regex_new (pattern->str, G_REGEX_OPTIMIZE, 0, &error); if (error) { GRL_WARNING ("Failed to compile regular expression " "for ignored query parameters: %s", error->message); g_clear_error (&error); } g_strfreev (parameter_names); g_string_free (pattern, TRUE); } /* Find base path for mock data. */ GFile *file = g_file_new_for_commandline_arg (config_filename); GFile *parent = g_file_get_parent (file); base_path = g_file_get_path (parent); g_object_unref (parent); g_object_unref (file); g_free (config_filename); }
static Block6Data* block6_data_ref (Block6Data* _data6_) { g_atomic_int_inc (&_data6_->_ref_count_); return _data6_; }
/** * @brief load layout * @details load layout depending on which list * was pressed (depending on list_name) * * @param sidebar : load data from the sidebar_list * @param list_name : name of the list, which * was selected * * @return true : if layout was loaded successfully * false : if layout wasn't loaded successfully */ static Block4Data* block4_data_ref (Block4Data* _data4_) { g_atomic_int_inc (&_data4_->_ref_count_); return _data4_; }
gpointer serializer_ref (gpointer instance) { Serializer* self; self = instance; g_atomic_int_inc (&self->ref_count); return instance; }
gpointer vala_target_value_ref (gpointer instance) { ValaTargetValue* self; self = instance; g_atomic_int_inc (&self->ref_count); return instance; }
FmList *fm_list_ref (gpointer list) { g_atomic_int_inc (&FM_LIST (list)->n_ref); return FM_LIST (list); }
void YapServerDeadlockPriv::increment() { g_atomic_int_inc(&watchdogCount); }
static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin, char *addr, struct udp_listener *ul) { struct control_ng *c = (void *) obj; bencode_buffer_t bencbuf; bencode_item_t *dict, *resp; str cmd, cookie, data, reply, *to_send, callid; const char *errstr; struct iovec iov[3]; unsigned int iovlen; GString *log_str; struct control_ng_stats* cur = get_control_ng_stats(c,&sin->address); str_chr_str(&data, buf, ' '); if (!data.s || data.s == buf->s) { ilog(LOG_WARNING, "Received invalid data on NG port (no cookie) from %s: "STR_FORMAT, addr, STR_FMT(buf)); return; } bencode_buffer_init(&bencbuf); resp = bencode_dictionary(&bencbuf); cookie = *buf; cookie.len -= data.len; *data.s++ = '\0'; data.len--; errstr = "Invalid data (no payload)"; if (data.len <= 0) goto err_send; to_send = cookie_cache_lookup(&c->cookie_cache, &cookie); if (to_send) { ilog(LOG_INFO, "Detected command from %s as a duplicate", addr); resp = NULL; goto send_only; } dict = bencode_decode_expect_str(&bencbuf, &data, BENCODE_DICTIONARY); errstr = "Could not decode dictionary"; if (!dict) goto err_send; bencode_dictionary_get_str(dict, "command", &cmd); errstr = "Dictionary contains no key \"command\""; if (!cmd.s) goto err_send; bencode_dictionary_get_str(dict, "call-id", &callid); log_info_str(&callid); ilog(LOG_INFO, "Received command '"STR_FORMAT"' from %s", STR_FMT(&cmd), addr); if (get_log_level() >= LOG_DEBUG) { log_str = g_string_sized_new(256); g_string_append_printf(log_str, "Dump for '"STR_FORMAT"' from %s: ", STR_FMT(&cmd), addr); pretty_print(dict, log_str); ilog(LOG_DEBUG, "%.*s", (int) log_str->len, log_str->str); g_string_free(log_str, TRUE); } errstr = NULL; if (!str_cmp(&cmd, "ping")) { bencode_dictionary_add_string(resp, "result", "pong"); g_atomic_int_inc(&cur->ping); } else if (!str_cmp(&cmd, "offer")) { errstr = call_offer_ng(dict, c->callmaster, resp, addr, sin); g_atomic_int_inc(&cur->offer); } else if (!str_cmp(&cmd, "answer")) { errstr = call_answer_ng(dict, c->callmaster, resp); g_atomic_int_inc(&cur->answer); } else if (!str_cmp(&cmd, "delete")) { errstr = call_delete_ng(dict, c->callmaster, resp); g_atomic_int_inc(&cur->delete); }
static void mc_ctx_acquire(memcached_ctx* ctx) { assert(g_atomic_int_get(&ctx->refcount) > 0); g_atomic_int_inc(&ctx->refcount); }
static gboolean scan_one_metadata_object (OtPullData *pull_data, const guchar *csum, OstreeObjectType objtype, guint recursion_depth, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_variant GVariant *object = NULL; gs_free char *tmp_checksum = NULL; gboolean is_requested; gboolean is_stored; tmp_checksum = ostree_checksum_from_bytes (csum); object = ostree_object_name_serialize (tmp_checksum, objtype); if (g_hash_table_lookup (pull_data->scanned_metadata, object)) return TRUE; is_requested = g_hash_table_lookup (pull_data->requested_metadata, tmp_checksum) != NULL; if (!ostree_repo_has_object (pull_data->repo, objtype, tmp_checksum, &is_stored, cancellable, error)) goto out; if (!is_stored && !is_requested) { char *duped_checksum = g_strdup (tmp_checksum); g_hash_table_insert (pull_data->requested_metadata, duped_checksum, duped_checksum); if (objtype == OSTREE_OBJECT_TYPE_COMMIT) ot_waitable_queue_push (pull_data->metadata_objects_to_fetch, pull_worker_message_new (PULL_MSG_FETCH_DETACHED_METADATA, g_variant_ref (object))); else ot_waitable_queue_push (pull_data->metadata_objects_to_fetch, pull_worker_message_new (PULL_MSG_FETCH, g_variant_ref (object))); } else if (is_stored) { if (pull_data->transaction_resuming || is_requested) { switch (objtype) { case OSTREE_OBJECT_TYPE_COMMIT: if (!scan_commit_object (pull_data, tmp_checksum, recursion_depth, pull_data->cancellable, error)) goto out; break; case OSTREE_OBJECT_TYPE_DIR_META: break; case OSTREE_OBJECT_TYPE_DIR_TREE: if (!scan_dirtree_object (pull_data, tmp_checksum, recursion_depth, pull_data->cancellable, error)) goto out; break; case OSTREE_OBJECT_TYPE_FILE: g_assert_not_reached (); break; } } g_hash_table_insert (pull_data->scanned_metadata, g_variant_ref (object), object); g_atomic_int_inc (&pull_data->n_scanned_metadata); } ret = TRUE; out: return ret; }
void li_memcached_con_acquire(liMemcachedCon* con) { LI_FORCE_ASSERT(g_atomic_int_get(&con->refcount) > 0); g_atomic_int_inc(&con->refcount); }
FmPath *fm_path_ref (FmPath *path) { g_atomic_int_inc (&path->n_ref); return path; }
gpointer matenu_background_ref (gpointer instance) { MatenuBackground* self; self = instance; g_atomic_int_inc (&self->ref_count); return instance; }
static Block5Data* block5_data_ref (Block5Data* _data5_) { g_atomic_int_inc (&_data5_->_ref_count_); return _data5_; }
static InvocationClient * invocation_client_ref (InvocationClient *client) { g_atomic_int_inc (&client->refs); return client; }
GguGitLogEntry * ggu_git_log_entry_ref (GguGitLogEntry *entry) { g_atomic_int_inc (&entry->ref_count); return entry; }
static WriteData * write_data_ref (WriteData *write_data) { g_atomic_int_inc (&write_data->ref_count); return write_data; }
// the cache retains one reference, and the caller gets another one. the // entry must be unreffed when the caller is done with it. void _openslide_cache_put(struct _openslide_cache *cache, void *plane, int64_t x, int64_t y, void *data, int size_in_bytes, struct _openslide_cache_entry **_entry) { // always create cache entry for caller's reference struct _openslide_cache_entry *entry = g_slice_new(struct _openslide_cache_entry); // one ref for the caller g_atomic_int_set(&entry->refcount, 1); entry->data = data; entry->size = size_in_bytes; *_entry = entry; // lock g_mutex_lock(cache->mutex); // don't try to put anything in the cache that cannot possibly fit if (size_in_bytes > cache->capacity) { //g_debug("refused %p", entry); g_mutex_unlock(cache->mutex); _openslide_performance_warn_once(&cache->warned_overlarge_entry, "Rejecting overlarge cache entry of " "size %d bytes", size_in_bytes); return; } possibly_evict(cache, size_in_bytes); // already checks for size >= 0 // create key struct _openslide_cache_key *key = g_slice_new(struct _openslide_cache_key); key->plane = plane; key->x = x; key->y = y; // create value struct _openslide_cache_value *value = g_slice_new(struct _openslide_cache_value); value->key = key; value->cache = cache; value->entry = entry; // insert at head of queue g_queue_push_head(cache->list, value); value->link = g_queue_peek_head_link(cache->list); // insert into hash table g_hash_table_replace(cache->hashtable, key, value); // increase size cache->total_size += size_in_bytes; // another ref for the cache g_atomic_int_inc(&entry->refcount); // unlock g_mutex_unlock(cache->mutex); //g_debug("insert %p", entry); }
gpointer rygel_icon_info_ref (gpointer instance) { RygelIconInfo* self; self = instance; g_atomic_int_inc (&self->ref_count); return instance; }
gpointer hello_world_ref (gpointer instance) { HelloWorld* self; self = instance; g_atomic_int_inc (&self->ref_count); return instance; }
VFSFileMonitor* vfs_file_monitor_add( char* path, gboolean is_dir, VFSFileMonitorCallback cb, gpointer user_data ) { VFSFileMonitor * monitor; VFSFileMonitorCallbackEntry cb_ent; struct stat file_stat; // skip stat64 gchar* real_path = NULL; //printf( "vfs_file_monitor_add %s\n", path ); if ( ! monitor_hash ) return NULL; monitor = ( VFSFileMonitor* ) g_hash_table_lookup ( monitor_hash, path ); if ( ! monitor ) { monitor = g_slice_new0( VFSFileMonitor ); monitor->path = g_strdup( path ); monitor->callbacks = g_array_new ( FALSE, FALSE, sizeof( VFSFileMonitorCallbackEntry ) ); g_hash_table_insert ( monitor_hash, monitor->path, monitor ); /* NOTE: Since gamin, FAM and inotify don't follow symlinks, we need to do some special processing here. */ if ( lstat( path, &file_stat ) == 0 ) { const char* link_file = path; while( G_UNLIKELY( S_ISLNK(file_stat.st_mode) ) ) { char* link = g_file_read_link( link_file, NULL ); char* dirname = g_path_get_dirname( link_file ); real_path = vfs_file_resolve_path( dirname, link ); g_free( link ); g_free( dirname ); if( lstat( real_path, &file_stat ) == -1 ) break; link_file = real_path; } } #ifdef USE_INOTIFY /* Linux inotify */ monitor->wd = inotify_add_watch ( inotify_fd, real_path ? real_path : path, IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE | IN_MOVE_SELF | IN_UNMOUNT | IN_ATTRIB); if ( monitor->wd < 0 ) { g_warning ( "Failed to add monitor on '%s': %s", path, g_strerror ( errno ) ); return NULL; } #else /* Use FAM|gamin */ //MOD see NOTE1 in vfs-mime-type.c - what happens here if path doesn't exist? // inotify returns NULL - does fam? if ( is_dir ) { FAMMonitorDirectory( &fam, real_path ? real_path : path, &monitor->request, monitor ); } else { FAMMonitorFile( &fam, real_path ? real_path : path, &monitor->request, monitor ); } #endif g_free( real_path ); } if( G_LIKELY(monitor) ) { /* g_debug( "monitor installed: %s, %p", path, monitor ); */ if ( cb ) { /* Install a callback */ cb_ent.callback = cb; cb_ent.user_data = user_data; monitor->callbacks = g_array_append_val( monitor->callbacks, cb_ent ); } g_atomic_int_inc( &monitor->n_ref ); } return monitor; }
/* Adds a reference to a TMTag. @param tag Pointer to a TMTag structure @return the passed-in TMTag */ TMTag *tm_tag_ref(TMTag *tag) { g_atomic_int_inc(&tag->refcount); return tag; }
static Block1Data* block1_data_ref (Block1Data* _data1_) { g_atomic_int_inc (&_data1_->_ref_count_); return _data1_; }