static const gchar * iter_to_string (GtkTreeIter *iter) { #ifdef G_THREADS_ENABLED static GPrivate gtmits_buffer_key = G_PRIVATE_INIT(g_free); gchar *string; string = g_private_get (>mits_buffer_key); if (string == NULL) { string = g_malloc(ITER_STRING_LEN + 1); g_private_set (>mits_buffer_key, string); } #else static char string[ITER_STRING_LEN + 1]; #endif if (iter) snprintf(string, ITER_STRING_LEN, "[stamp:%x data:%p (%s), %p, %d]", iter->stamp, iter->user_data, gncOwnerGetName ((GncOwner *) iter->user_data), iter->user_data2, GPOINTER_TO_INT(iter->user_data3)); else strcpy(string, "(null)"); return string; }
/** * gidispatch_set_retained_registry: * @regi: Function to call whenever the Glk library assumes ownership of an * array. * @unregi: Function to call whenever the Glk library releases ownership of an * array. * * A few Glk functions take an array and hold onto it. * The memory is “owned” by the library until some future Glk call releases it. * While the library retains the array, your program should not read, write, * move, or deallocate it. When the library releases it, the contents are in * their final form, and you can copy them out (if appropriate) and dispose of * the memory as you wish. * * To allow this, the library implements gidispatch_set_retained_registry(). * * Again, you pass in two function pointers: * |[<!--language="C"--> * gidispatch_rock_t my_vm_reg_array(void *array, glui32 len, char *typecode); * void my_vm_unreg_array(void *array, glui32 len, char *typecode, gidispatch_rock_t objrock); * ]| * * Whenever a Glk function retains an array, it will call * `my_vm_reg_array<!---->()`. * This occurs only if you pass an array to an argument with the `"#!"` prefix. * * <note><para> * But not in every such case. Wait for the * <function>my_vm_reg_array()</function> call to confirm it. * </para></note> * * The library passes the array and its length, exactly as you put them in the * #gluniversal_t array. It also passes the string which describes the argument. * * <note><para> * Currently, the only calls that retain arrays are glk_request_line_event(), * glk_stream_open_memory(), glk_request_line_event_uni(), and * glk_stream_open_memory_uni(). The first two of these use arrays of * characters, so the string is <code>"&+#!Cn"</code>. The latter two use * arrays of #glui32, so the string is <code>"&+#!Iu"</code>. * </para></note> * * You can return any value in the #gidispatch_rock_t object; the library will * stash this away with the array. * * When a Glk function releases a retained array, it will call * `my_vm_unreg_array<!---->()`. * It passes back the same @array, @len, and @typecode parameters, as well as * the #gidispatch_rock_t you returned from `my_vm_reg_array<!---->()`. * * With these callbacks, you can maintain a collection of retained arrays. You * can use this to copy data from C arrays to your own data structures, or keep * relocatable memory locked, or prevent a garbage-collection system from * deallocating an array while Glk is writing to it. */ void gidispatch_set_retained_registry(gidispatch_rock_t (*regi)(void *array, glui32 len, char *typecode), void (*unregi)(void *array, glui32 len, char *typecode, gidispatch_rock_t objrock)) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); glk_data->register_arr = regi; glk_data->unregister_arr = unregi; }
const char * guid_to_string(const GncGUID * guid) { #ifdef G_THREADS_ENABLED #ifndef HAVE_GLIB_2_32 static GStaticPrivate guid_buffer_key = G_STATIC_PRIVATE_INIT; gchar *string; string = static_cast<gchar*>(g_static_private_get (&guid_buffer_key)); if (string == NULL) { string = static_cast<gchar*>(malloc(GUID_ENCODING_LENGTH + 1)); g_static_private_set (&guid_buffer_key, string, g_free); } #else static GPrivate guid_buffer_key = G_PRIVATE_INIT(g_free); gchar *string; string = static_cast<char*>(g_private_get (&guid_buffer_key)); if (string == NULL) { string = static_cast<char*>(malloc(GUID_ENCODING_LENGTH + 1)); g_private_set (&guid_buffer_key, string); } #endif #else static char string[64]; #endif encode_md5_data(guid->data, string); string[GUID_ENCODING_LENGTH] = '\0'; return string; }
/** * g_static_private_get: * @private_key: a #GStaticPrivate * * Works like g_private_get() only for a #GStaticPrivate. * * This function works even if g_thread_init() has not yet been called. * * Returns: the corresponding pointer */ gpointer g_static_private_get (GStaticPrivate *private_key) { GArray *array; gpointer ret = NULL; array = g_private_get (&static_private_private); if (array && private_key->index != 0 && private_key->index <= array->len) { GStaticPrivateNode *node; node = &g_array_index (array, GStaticPrivateNode, private_key->index - 1); /* Deal with the possibility that the GStaticPrivate which used * to have this index got freed and the index got allocated to * a new one. In this case, the data in the node is stale, so * free it and return NULL. */ if (G_UNLIKELY (node->owner != private_key)) { if (node->destroy) node->destroy (node->data); node->destroy = NULL; node->data = NULL; node->owner = NULL; } ret = node->data; } return ret; }
SchroExecDomain schro_async_get_exec_domain (void) { void *domain; domain = g_private_get (domain_key); return (int) (unsigned long) domain; }
osync_bool osync_trace_is_enabled(void) { if (!trace_disabled || !g_private_get(trace_disabled)) return TRUE; return FALSE; }
static int trg_http_perform_inner(TrgClient * tc, gchar * reqstr, trg_response * response, gboolean recurse) { TrgClientPrivate *priv = tc->priv; TrgPrefs *prefs = trg_client_get_prefs(tc); gpointer threadLocalStorage = g_private_get(priv->tlsKey); trg_tls *tls; long httpCode = 0; gchar *session_id; struct curl_slist *headers = NULL; if (!threadLocalStorage) { tls = trg_tls_new(tc); g_private_set(priv->tlsKey, tls); } else { tls = (trg_tls *) threadLocalStorage; } g_mutex_lock(priv->configMutex); if (priv->configSerial > tls->serial) trg_tls_update(tc, tls, priv->configSerial); session_id = trg_client_get_session_id(tc); if (session_id) { headers = curl_slist_append(NULL, session_id); curl_easy_setopt(tls->curl, CURLOPT_HTTPHEADER, headers); } curl_easy_setopt(tls->curl, CURLOPT_TIMEOUT, (long) trg_prefs_get_int(prefs, TRG_PREFS_KEY_TIMEOUT, TRG_PREFS_CONNECTION)); g_mutex_unlock(priv->configMutex); response->size = 0; response->raw = NULL; curl_easy_setopt(tls->curl, CURLOPT_POSTFIELDS, reqstr); curl_easy_setopt(tls->curl, CURLOPT_WRITEDATA, (void *) response); response->status = curl_easy_perform(tls->curl); if (session_id) { g_free(session_id); curl_slist_free_all(headers); } curl_easy_getinfo(tls->curl, CURLINFO_RESPONSE_CODE, &httpCode); if (response->status == CURLE_OK) { if (httpCode == HTTP_CONFLICT && recurse == TRUE) return trg_http_perform_inner(tc, reqstr, response, FALSE); else if (httpCode != HTTP_OK) response->status = (-httpCode) - 100; } return response->status; }
/** * mate_vfs_is_primary_thread: * * Check if the current thread is the thread with the main glib event loop. * * Return value: %TRUE if the current thread is the thread with the * main glib event loop. */ gboolean mate_vfs_is_primary_thread (void) { if (g_thread_supported()) { return GPOINTER_TO_UINT(g_private_get (private_is_primary_thread)) == 1; } else { return TRUE; } }
void gst_srtp_init_event_reporter (void) { struct GstSrtpEventReporterData *dat = g_private_get (¤t_callback); if (!dat) { dat = g_slice_new (struct GstSrtpEventReporterData); g_private_set (¤t_callback, dat); }
/** * log4g_thread_get_instance: * * Retrieve a Log4gThread object. * * If one does not exist a new one will be created. * * Returns: A Log4gThread object. */ static Log4gThread * log4g_thread_get_instance(void) { Log4gThread *self = (Log4gThread *)g_private_get(&priv); if (!self) { self = g_object_new(LOG4G_TYPE_THREAD, NULL); } return self; }
/* preload_init must be called before this so the worker gets created */ static PreloadWorker* _shadowtorpreload_getWorker() { /* get current thread's private worker object */ PreloadWorker* worker = g_private_get(&threadPreloadWorkerKey); if(!worker) { worker = g_new0(PreloadWorker, 1); g_private_set(&threadPreloadWorkerKey, worker); } g_assert(worker); return worker; }
void vips__buffer_shutdown( void ) { VipsBufferThread *buffer_thread; if( (buffer_thread = g_private_get( buffer_thread_key )) ) { buffer_thread_free( buffer_thread ); g_private_set( buffer_thread_key, NULL ); } }
/** * g_cancellable_push_current: * @cancellable: a #GCancellable object * * Pushes @cancellable onto the cancellable stack. The current * cancellable can then be received using g_cancellable_get_current(). * * This is useful when implementing cancellable operations in * code that does not allow you to pass down the cancellable object. * * This is typically called automatically by e.g. #GFile operations, * so you rarely have to call this yourself. **/ void g_cancellable_push_current (GCancellable *cancellable) { GSList *l; g_return_if_fail (cancellable != NULL); l = g_private_get (¤t_cancellable); l = g_slist_prepend (l, cancellable); g_private_set (¤t_cancellable, l); }
/** * glk_exit: * * If you want to shut down your program in the middle of your `glk_main()` * function, you can call glk_exit(). * * This function does not return. * * If you print some text to a window and then shut down your program, you can * assume that the player will be able to read it. Most likely the Glk library * will give a “`Hit any key to exit`” prompt. * (There are other possiblities, however. * A terminal-window version of Glk might simply exit and leave the last screen * state visible in the terminal window.) * * <note><para> * You should only shut down your program with glk_exit() or by returning from * your <function>glk_main()</function> function. If you call the ANSI * <function>exit()</function> function, bad things may happen. Some versions of * the Glk library may be designed for multiple sessions, for example, and you * would be cutting off all the sessions instead of just yours. You would * probably also prevent final text from being visible to the player. * </para></note> * * > # Chimara # * > If there are any windows open at the time glk_exit() is called, then * > Chimara will leave them open. * > This way, the final text remains visible. * > Note that bad things most definitely <emphasis>will</emphasis> happen if * > you use the ANSI `exit()`. */ void glk_exit(void) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); shutdown_glk_pre(); /* Find the biggest text buffer window */ winid_t win, largewin = NULL; glui32 largearea = 0; for(win = glk_window_iterate(NULL, NULL); win; win = glk_window_iterate(win, NULL)) { if(win->type == wintype_TextBuffer) { glui32 w, h; if(!largewin) { largewin = win; glk_window_get_size(largewin, &w, &h); largearea = w * h; } else { glk_window_get_size(win, &w, &h); if(w * h > largearea) { largewin = win; largearea = w * h; } } } } if(largewin) { glk_set_window(largewin); glk_set_style(style_Alert); glk_put_string("\n"); glk_put_string(glk_data->final_message); glk_put_string("\n"); flush_window_buffer(largewin); } /* Wait for a keypress if any text grid or buffer windows are open */ gboolean should_wait = FALSE; g_mutex_lock(&glk_data->shutdown_lock); for(win = glk_window_iterate(NULL, NULL); win; win = glk_window_iterate(win, NULL)) { if(win->type == wintype_TextGrid || win->type == wintype_TextBuffer) { g_signal_handler_unblock(win->widget, win->shutdown_keypress_handler); should_wait = TRUE; } } if (should_wait) g_cond_wait(&glk_data->shutdown_key_pressed, &glk_data->shutdown_lock); g_mutex_unlock(&glk_data->shutdown_lock); shutdown_glk_post(); gdk_threads_add_idle((GSourceFunc)emit_stopped_signal, glk_data->self); g_thread_exit(NULL); }
/** * add a event to event base of current thread add by vinchen/CFR * * the event is added to current event-threads to handle it * * @see network_mysqld_con_handle() */ void chassis_event_add_ex(chassis *chas, struct event *ev) { struct event_base *event_base; event_base = g_private_get(tls_event_base_key); g_assert(event_base); /* the thread-local event-base has to be initialized */ event_base_set(event_base, ev); event_add(ev, NULL); }
/** * g_cancellable_get_current: * * Gets the top cancellable from the stack. * * Returns: (transfer none): a #GCancellable from the top of the stack, or %NULL * if the stack is empty. **/ GCancellable * g_cancellable_get_current (void) { GSList *l; l = g_private_get (¤t_cancellable); if (l == NULL) return NULL; return G_CANCELLABLE (l->data); }
/** * giblorb_get_resource_map: * * This function returns the current resource map being used. Returns %NULL * if giblorb_set_resource_map() has not been called yet. * * Returns: a resource map, or %NULL. */ giblorb_map_t* giblorb_get_resource_map() { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); if(glk_data->resource_map == NULL) { WARNING("Resource map not set yet.\n"); } return glk_data->resource_map; }
/* Get the buffer cache. */ static VipsBufferCache * buffer_cache_get( void ) { VipsBufferCache *cache; if( !(cache = g_private_get( thread_buffer_cache_key )) ) { cache = buffer_cache_new(); g_private_set( thread_buffer_cache_key, cache ); } return( cache ); }
/* Internal function: check if the Glk program has been interrupted. */ void check_for_abort(void) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); g_mutex_lock(&glk_data->abort_lock); if(glk_data->abort_signalled) { g_mutex_unlock(&glk_data->abort_lock); abort_glk(); } g_mutex_unlock(&glk_data->abort_lock); }
static GMainContext * get_rust_thread_context () { GMainContext *context; context = g_private_get (&rust_thread_context); if (context == NULL) { context = g_main_context_new (); g_private_set (&rust_thread_context, context); } return context; }
/** * g_cancellable_pop_current: * @cancellable: a #GCancellable object * * Pops @cancellable off the cancellable stack (verifying that @cancellable * is on the top of the stack). **/ void g_cancellable_pop_current (GCancellable *cancellable) { GSList *l; l = g_private_get (¤t_cancellable); g_return_if_fail (l != NULL); g_return_if_fail (l->data == cancellable); l = g_slist_delete_link (l, l); g_private_set (¤t_cancellable, l); }
/* Internal function: do any Glk-thread cleanup for shutting down the Glk library. */ void shutdown_glk_post(void) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); /* Free all opaque objects; can't iterate normally, because the objects are being removed from the global iteration lists */ if(glk_data->root_window) glk_window_close(glk_data->root_window->data, NULL); g_assert(glk_data->root_window == NULL); strid_t str; while( (str = glk_stream_iterate(NULL, NULL)) ) glk_stream_close(str, NULL); frefid_t fref; while( (fref = glk_fileref_iterate(NULL, NULL)) ) glk_fileref_destroy(fref); schanid_t sch; while( (sch = glk_schannel_iterate(NULL, NULL)) ) glk_schannel_destroy(sch); /* Empty the event queue */ g_mutex_lock(&glk_data->event_lock); g_queue_foreach(glk_data->event_queue, (GFunc)g_free, NULL); g_queue_clear(glk_data->event_queue); g_mutex_unlock(&glk_data->event_lock); /* Reset the abort signaling mechanism */ g_mutex_lock(&glk_data->abort_lock); glk_data->abort_signalled = FALSE; g_mutex_unlock(&glk_data->abort_lock); /* Reset arrangement mechanism */ g_mutex_lock(&glk_data->arrange_lock); glk_data->needs_rearrange = FALSE; glk_data->ignore_next_arrange_event = FALSE; g_mutex_unlock(&glk_data->arrange_lock); /* Unref input queues (they are not destroyed because the main thread stil holds a ref */ g_async_queue_unref(glk_data->char_input_queue); g_async_queue_unref(glk_data->line_input_queue); /* Reset other stuff */ glk_data->interrupt_handler = NULL; g_free(glk_data->current_dir); glk_data->current_dir = NULL; /* Remove the dispatch callbacks */ glk_data->register_obj = NULL; glk_data->unregister_obj = NULL; glk_data->register_arr = NULL; glk_data->unregister_arr = NULL; }
static VipsBufferThread * buffer_thread_get( void ) { VipsBufferThread *buffer_thread; if( !(buffer_thread = g_private_get( buffer_thread_key )) ) { buffer_thread = buffer_thread_new(); g_private_set( buffer_thread_key, buffer_thread ); } g_assert( buffer_thread->thread == g_thread_self() ); return( buffer_thread ); }
static trg_tls *get_tls(TrgClient *tc) { TrgClientPrivate *priv = tc->priv; gpointer threadLocalStorage = g_private_get(&priv->tlsKey); trg_tls *tls; if (!threadLocalStorage) { tls = trg_tls_new(tc); g_private_set(&priv->tlsKey, tls); } else { tls = (trg_tls *) threadLocalStorage; } return tls; }
/* Internal function: shut down all requests and anything not necessary while showing the last displayed configuration of windows. */ void shutdown_glk_pre(void) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); /* Stop any timers */ glk_request_timer_events(0); /* Cancel any pending input requests and flush all window buffers */ winid_t win; for(win = glk_window_iterate(NULL, NULL); win; win = glk_window_iterate(win, NULL)) { switch(win->input_request_type) { case INPUT_REQUEST_CHARACTER: case INPUT_REQUEST_CHARACTER_UNICODE: glk_cancel_char_event(win); break; case INPUT_REQUEST_LINE: case INPUT_REQUEST_LINE_UNICODE: glk_cancel_line_event(win, NULL); break; case INPUT_REQUEST_NONE: default: ; /* TODO: Handle mouse and hyperlink requests */ } flush_window_buffer(win); } /* Close any open resource files */ if(glk_data->resource_map != NULL) { giblorb_destroy_map(glk_data->resource_map); glk_data->resource_map = NULL; glk_stream_close(glk_data->resource_file, NULL); } /* Empty the input queues */ while(g_async_queue_try_pop(glk_data->char_input_queue)) ; while(g_async_queue_try_pop(glk_data->line_input_queue)) ; /* Wait for any pending window rearrange */ g_mutex_lock(&glk_data->arrange_lock); if(glk_data->needs_rearrange) g_cond_wait(&glk_data->rearranged, &glk_data->arrange_lock); g_mutex_unlock(&glk_data->arrange_lock); }
/* Internal function: abort this Glk program, freeing resources and calling the user's interrupt handler. */ static void abort_glk(void) { ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); if(glk_data->interrupt_handler) (*(glk_data->interrupt_handler))(); shutdown_glk_pre(); shutdown_glk_post(); /* If program is terminated by g_thread_exit() instead of returning from the glk_main() function, then the line in glk_exit() where the "stopped" signal is emitted will not be reached. So we have to emit it here. */ if(!glk_data->in_startup) g_signal_emit_by_name(glk_data->self, "stopped"); g_thread_exit(NULL); }
static magic_t get_private_magic(void) { magic_t m; m = (magic_t)g_private_get(private_key); if (m == NULL) { m = magic_open(MAGIC_MIME_TYPE); magic_load(m, NULL); g_private_set(private_key, (gpointer)m); } return m; }
static GObject * constructor(GType type, guint n, GObjectConstructParam *params) { GObject *self = g_private_get(&priv); if (!self) { self = G_OBJECT_CLASS(log4g_thread_parent_class)-> constructor(type, n, params); if (!self) { return NULL; } g_private_set(&priv, self); } else { g_object_ref(self); } return self; }
static void srtp_event_reporter (srtp_event_data_t * data) { struct GstSrtpEventReporterData *dat = g_private_get (¤t_callback); if (!dat) return; switch (data->event) { case event_key_soft_limit: dat->soft_limit_reached = TRUE; break; default: break; } }
static void invalidate_local_connection (const char *dbus_id, GError **error) { ThreadLocalConnections *local; _g_daemon_vfs_invalidate_dbus_id (dbus_id); local = g_private_get (&local_connections); if (local) g_hash_table_remove (local->connections, dbus_id); g_set_error_literal (error, G_VFS_ERROR, G_VFS_ERROR_RETRY, "Cache invalid, retry (internally handled)"); }