static void _osync_trace_init() { const char *noprivacy; const char *error; trace = g_getenv("OSYNC_TRACE"); if (!trace) return; noprivacy = g_getenv("OSYNC_NOPRIVACY"); if (!trace_sensitive) trace_sensitive = g_private_new(NULL); if (noprivacy) g_private_set(trace_sensitive, GINT_TO_POINTER(1)); else g_private_set(trace_sensitive, GINT_TO_POINTER(0)); error = g_getenv("OSYNC_PRINTERROR"); if (!print_stderr) print_stderr = g_private_new(NULL); if (error) g_private_set(print_stderr, GINT_TO_POINTER(1)); else g_private_set(print_stderr, GINT_TO_POINTER(0)); if (!g_file_test(trace, G_FILE_TEST_IS_DIR)) { printf("OSYNC_TRACE argument is no directory\n"); return; } }
/** * gst_gl_context_activate: * @context: a #GstGLContext * @activate: %TRUE to activate, %FALSE to deactivate * * (De)activate the OpenGL context represented by this @context. * * In OpenGL terms, calls eglMakeCurrent or similar with this context and the * currently set window. See gst_gl_context_set_window() for details. * * Returns: Whether the activation succeeded * * Since: 1.4 */ gboolean gst_gl_context_activate (GstGLContext * context, gboolean activate) { GstGLContextClass *context_class; gboolean result; g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE); context_class = GST_GL_CONTEXT_GET_CLASS (context); g_return_val_if_fail (context_class->activate != NULL, FALSE); GST_DEBUG_OBJECT (context, "activate:%d", activate); GST_OBJECT_LOCK (context); result = context_class->activate (context, activate); if (result && activate) { context->priv->active_thread = g_thread_self (); g_private_set (¤t_context_key, context); } else { context->priv->active_thread = NULL; g_private_set (¤t_context_key, NULL); } GST_OBJECT_UNLOCK (context); return result; }
void osync_trace_enable(void) { if (!trace_disabled) trace_disabled = g_private_new (NULL); if (!trace) g_private_set(trace_disabled, GINT_TO_POINTER(1)); else g_private_set(trace_disabled, GINT_TO_POINTER(0)); }
extern void TLSSetValue(TLSItem pItem, size_t value) { size_t *pNew = (size_t *) malloc(sizeof(size_t)); *pNew = value; g_private_set(pItem, (gpointer) pNew); }
static void TLSSetValue(TLSItem pItem, int value) { int *pNew = (int *) malloc(sizeof(int)); *pNew = value; g_private_set(pItem, (gpointer) pNew); }
void rb_threads_init (void) { GMutex *m; private_is_primary_thread = g_private_new (NULL); g_private_set (private_is_primary_thread, GUINT_TO_POINTER (1)); g_static_rec_mutex_init (&rb_gdk_mutex); gdk_threads_set_lock_functions (_threads_enter, _threads_leave); gdk_threads_init (); m = g_mutex_new (); g_mutex_lock (m); mutex_recurses = g_mutex_trylock (m); if (mutex_recurses) g_mutex_unlock (m); g_mutex_unlock (m); g_mutex_free (m); rb_debug ("GMutex %s recursive", mutex_recurses ? "is" : "isn't"); /* purge useless thread-pool threads occasionally */ g_timeout_add_seconds (30, purge_useless_threads, NULL); }
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; }
gpointer g_thread_proxy (gpointer data) { GRealThread* thread = data; g_assert (data); /* This has to happen before G_LOCK, as that might call g_thread_self */ g_private_set (&g_thread_specific_private, data); /* The lock makes sure that g_thread_new_internal() has a chance to * setup 'func' and 'data' before we make the call. */ G_LOCK (g_thread_new); G_UNLOCK (g_thread_new); if (thread->name) { g_system_thread_set_name (thread->name); g_free (thread->name); thread->name = NULL; } thread->retval = thread->thread.func (thread->thread.data); return NULL; }
void libMary_threadLocalInit () { #ifdef LIBMARY_MT_SAFE _libMary_main_tlocal = new (std::nothrow) LibMary_ThreadLocal; assert (_libMary_main_tlocal); #ifdef LIBMARY_PTHREAD { int const res = pthread_key_create (&_libMary_tlocal_key, tlocal_destructor); assert (res == 0); } { int const res = pthread_setspecific (_libMary_tlocal_key, _libMary_main_tlocal); assert (res == 0); } #else #ifdef LIBMARY__OLD_GTHREAD_API _libMary_tlocal_gprivate_dtor = g_private_new (tlocal_destructor); #ifndef LIBMARY_TLOCAL _libMary_tlocal_gprivate = g_private_new (NULL /* notify */); #endif #endif g_private_set (LIBMARY__TLOCAL_GPRIVATE, _libMary_main_tlocal); #endif #else _libMary_tlocal = new (std::nothrow) LibMary_ThreadLocal; assert (_libMary_tlocal); #endif }
static void tlocal_destructor (_libMary_VoidPtr const _tlocal) { logD_ (_func, "tlocal ", (UintPtr) _tlocal); #ifndef LIBMARY_TLOCAL #ifndef LIBMARY_PTHREAD // All gprivates are reset to NULL by glib/pthreads before tlocal_destructor() // is called. We restore the right value for tlocal gprivate, which is safe // since it doesn't have an associated destructor callback. g_private_set (LIBMARY__TLOCAL_GPRIVATE, _tlocal); #endif #endif // Exception dtors may call arbitrary code, so we're // clearing exceptions first. exc_none (); if (LibMary_ThreadLocal * const tlocal = static_cast <LibMary_ThreadLocal*> (_tlocal)) delete tlocal; #ifdef LIBMARY_TLOCAL _libMary_tlocal = NULL; #endif }
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; }
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; }
static void log4g_thread_class_init(Log4gThreadClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); g_private_set(&priv, NULL); object_class->constructor = constructor; object_class->finalize = finalize; g_type_class_add_private(klass, sizeof(struct Private)); }
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); }
static void g_enumerable_thread_add (GRealThread *thread) { G_LOCK (g_thread); g_thread_all_threads = g_slist_prepend (g_thread_all_threads, thread); G_UNLOCK (g_thread); g_private_set (&enumerable_thread_private, thread); }
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 ); } }
/* 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; }
/** * 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); }
static void mate_vfs_thread_init (void) { private_is_primary_thread = g_private_new (NULL); g_private_set (private_is_primary_thread, GUINT_TO_POINTER (1)); _mate_vfs_module_callback_private_init (); _mate_vfs_async_job_map_init (); _mate_vfs_job_queue_init (); }
/* 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 ); }
/** * 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); }
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; }
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; }
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 ); }
void worker_free(Worker* worker) { MAGIC_ASSERT(worker); /* calls the destroy functions we specified in g_hash_table_new_full */ g_hash_table_destroy(worker->privatePrograms); if(worker->serialEventQueue) { eventqueue_free(worker->serialEventQueue); } MAGIC_CLEAR(worker); g_private_set(&workerKey, NULL); g_free(worker); }
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; }
/* This usually happens automatically when a thread shuts down, see * vips__thread_profile_init() where we set a GDestroyNotify, but will not * happen for the main thread. * * Shut down any stats on the main thread with this, see vips_shutdown() */ void vips__thread_profile_detach( void ) { VipsThreadProfile *profile; VIPS_DEBUG_MSG( "vips__thread_profile_detach:\n" ); if( (profile = vips_thread_profile_get()) ) { if( vips__thread_profile ) vips_thread_profile_save( profile ); vips_thread_profile_free( profile ); g_private_set( vips_thread_profile_key, NULL ); } }
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; }
/** * g_static_private_set: * @private_key: a #GStaticPrivate * @data: the new pointer * @notify: a function to be called with the pointer whenever the * current thread ends or sets this pointer again * * Sets the pointer keyed to @private_key for the current thread and * the function @notify to be called with that pointer (%NULL or * non-%NULL), whenever the pointer is set again or whenever the * current thread ends. * * This function works even if g_thread_init() has not yet been called. * If g_thread_init() is called later, the @data keyed to @private_key * will be inherited only by the main thread, i.e. the one that called * g_thread_init(). * * @notify is used quite differently from @destructor in g_private_new(). */ void g_static_private_set (GStaticPrivate *private_key, gpointer data, GDestroyNotify notify) { GArray *array; static guint next_index = 0; GStaticPrivateNode *node; if (!private_key->index) { G_LOCK (g_thread); if (!private_key->index) { if (g_thread_free_indices) { private_key->index = GPOINTER_TO_UINT (g_thread_free_indices->data); g_thread_free_indices = g_slist_delete_link (g_thread_free_indices, g_thread_free_indices); } else private_key->index = ++next_index; } G_UNLOCK (g_thread); } array = g_private_get (&static_private_private); if (!array) { array = g_array_new (FALSE, TRUE, sizeof (GStaticPrivateNode)); g_private_set (&static_private_private, array); } if (private_key->index > array->len) g_array_set_size (array, private_key->index); node = &g_array_index (array, GStaticPrivateNode, private_key->index - 1); if (node->destroy) node->destroy (node->data); node->data = data; node->destroy = notify; node->owner = private_key; }
/* Get the buffer cache. */ static im_buffer_cache_t * buffer_cache_get( void ) { im_buffer_cache_t *cache; #ifdef HAVE_THREADS if( !(cache = g_private_get( thread_buffer_cache_key )) ) { cache = buffer_cache_new(); g_private_set( thread_buffer_cache_key, cache ); } #else /*!HAVE_THREADS*/ if( !thread_buffer_cache ) thread_buffer_cache = buffer_cache_new(); cache = thread_buffer_cache; #endif /*HAVE_THREADS*/ return( cache ); }