/* Init the buffer cache system. This is called during vips_init. */ void vips__buffer_init( void ) { #ifdef HAVE_PRIVATE_INIT static GPrivate private = G_PRIVATE_INIT( (GDestroyNotify) buffer_thread_destroy_notify ); buffer_thread_key = &private; #else if( !buffer_thread_key ) buffer_thread_key = g_private_new( (GDestroyNotify) buffer_thread_destroy_notify ); #endif if( buffer_cache_max_reserve < 1 ) printf( "vips__buffer_init: buffer reserve disabled\n" ); #ifdef DEBUG printf( "vips__buffer_init: DEBUG enabled\n" ); #endif /*DEBUG*/ #ifdef DEBUG_CREATE printf( "vips__buffer_init: DEBUG_CREATE enabled\n" ); #endif /*DEBUG_CREATE*/ }
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; }
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; }
/** * g_private_new: * @notify: a #GDestroyNotify * * Creates a new #GPrivate. * * Deprecated:2.32: dynamic allocation of #GPrivate is a bad idea. Use * static storage and G_PRIVATE_INIT() instead. * * Returns: a newly allocated #GPrivate (which can never be destroyed) */ GPrivate * g_private_new (GDestroyNotify notify) { GPrivate tmp = G_PRIVATE_INIT (notify); GPrivate *key; key = g_slice_new (GPrivate); *key = tmp; return key; }
cSession::cSession() : m_ref_cnt( 0 ), m_did( SAHPI_UNSPECIFIED_DOMAIN_ID ), m_sid( 0 ), m_remote_sid( 0 ) { #if GLIB_CHECK_VERSION (2, 32, 0) m_sockets = G_PRIVATE_INIT (g_free); #else wrap_g_static_private_init( &m_sockets ); #endif }
/* Init the buffer cache system. */ void vips__buffer_init( void ) { #ifdef HAVE_PRIVATE_INIT static GPrivate private = G_PRIVATE_INIT( (GDestroyNotify) buffer_cache_free ); thread_buffer_cache_key = &private; #else if( !thread_buffer_cache_key ) thread_buffer_cache_key = g_private_new( (GDestroyNotify) buffer_cache_free ); #endif }
static void vips__thread_profile_init( void ) { #ifdef HAVE_PRIVATE_INIT static GPrivate private = G_PRIVATE_INIT( (GDestroyNotify) vips__thread_profile_init_cb ); vips_thread_profile_key = &private; #else if( !vips_thread_profile_key ) vips_thread_profile_key = g_private_new( (GDestroyNotify) vips__thread_profile_init_cb ); #endif }
/* Init the buffer cache system. */ void vips__buffer_init( void ) { #ifdef HAVE_PRIVATE_INIT static GPrivate private = G_PRIVATE_INIT( (GDestroyNotify) vips__buffer_init_cb ); buffer_thread_key = &private; #else if( !buffer_thread_key ) buffer_thread_key = g_private_new( (GDestroyNotify) vips__buffer_init_cb ); #endif if( buffer_cache_max_reserve < 1 ) printf( "vips__buffer_init: buffer reserve disabled\n" ); }
* The error domain of the GLib thread subsystem. **/ GQuark g_thread_error_quark (void) { return g_quark_from_static_string ("g_thread_error"); } /* Local Data {{{1 -------------------------------------------------------- */ static GMutex g_once_mutex; static GCond g_once_cond; static GSList *g_once_init_list = NULL; static void g_thread_cleanup (gpointer data); static GPrivate g_thread_specific_private = G_PRIVATE_INIT (g_thread_cleanup); G_LOCK_DEFINE_STATIC (g_thread_new); /* GOnce {{{1 ------------------------------------------------------------- */ /** * GOnce: * @status: the status of the #GOnce * @retval: the value returned by the call to the function, if @status * is %G_ONCE_STATUS_READY * * A #GOnce struct controls a one-time initialization function. Any * one-time initialization function must have its own unique #GOnce * struct. *
void bt_request_processor(void *job_params, void *pool_params) { static GPrivate redis_key = G_PRIVATE_INIT(bt_free_redis); /* Data to be sent to the client. */ bt_response_buffer_t *resp_buffer = NULL; /* Basic request data. */ bt_req_t request; /* Message to be sent to the client in case of error. */ char *error = NULL; /* Cast parameters to their correct types. */ bt_job_params_t *params = (bt_job_params_t *) job_params; bt_config_t *config = (bt_config_t *) pool_params; /* Fills object with data in buffer. */ bt_read_request_data(params->buff, &request); int redis_timeout = config->redis_timeout * 1000; redisContext *redis = g_private_get(&redis_key); /* Connects to the Redis instance where the data should be stored. */ if (!redis) { redis_connect: redis = bt_redis_connect(config->redis_socket_path, config->redis_host, config->redis_port, redis_timeout, config->redis_db); /* Cannot connect, answer this request with an error. */ if (!redis) { error = "Tracker temporarily unavailable: data storage is not working"; request.action = BT_ACTION_ERROR; } /* Stores the new redis context in thread local storage. */ g_private_replace(&redis_key, redis); } else { if (!bt_redis_ping(redis)) { goto redis_connect; } } /* Dispatches the request to the appropriate handler function. */ switch (request.action) { case BT_ACTION_CONNECT: resp_buffer = bt_handle_connection(&request, config, params->buflen, redis); break; case BT_ACTION_ANNOUNCE: resp_buffer = bt_handle_announce(&request, config, params->buff, params->buflen, params->from_addr, redis); break; case BT_ACTION_SCRAPE: resp_buffer = bt_handle_scrape(&request, config, params->buff, params->buflen, redis); break; case BT_ACTION_ERROR: resp_buffer = bt_send_error(&request, error); break; } if (resp_buffer != NULL) { syslog(LOG_DEBUG, "Sending response back to the client"); if (sendto(params->sock, resp_buffer->data, resp_buffer->length, 0, (struct sockaddr *) params->from_addr, params->from_addr_len) == -1) { syslog(LOG_ERR, "Error in sendto()"); } /* Destroys response data. */ free(resp_buffer->data); free(resp_buffer); } /* Frees the cloned input buffer. */ free(params->buff); free(params); }
#endif #define GLIB_DISABLE_DEPRECATION_WARNINGS #include "gstsrtp.h" #include <glib.h> #include <gst/rtp/gstrtcpbuffer.h> #include "gstsrtpenc.h" #include "gstsrtpdec.h" static void free_reporter_data (gpointer data); GPrivate current_callback = G_PRIVATE_INIT (free_reporter_data); struct GstSrtpEventReporterData { gboolean soft_limit_reached; }; static void free_reporter_data (gpointer data) { g_slice_free (struct GstSrtpEventReporterData, data); } static void srtp_event_reporter (srtp_event_data_t * data)
Random* random; Program* cached_plugin; Host* cached_node; Process* cached_process; Event* cached_event; GHashTable* privatePrograms; MAGIC_DECLARE; }; /* holds a thread-private key that each thread references to get a private * instance of a worker object */ static GPrivate workerKey = G_PRIVATE_INIT((GDestroyNotify)worker_free); static Worker* _worker_getPrivate() { /* get current thread's private worker object */ Worker* worker = g_private_get(&workerKey); MAGIC_ASSERT(worker); return worker; } gboolean worker_isAlive() { return g_private_get(&workerKey) != NULL; } Worker* worker_new(Slave* slave) { /* make sure this isnt called twice on the same thread! */ utility_assert(!worker_isAlive());
if (!p->mandatory) continue; return NEWERROR(400, "Missing field [%s]", p->name); } if (!json_object_is_type(o, p->type)) return NEWERROR(400, "Invalid type for field [%s]", p->name); *(p->out) = o; } return NULL; } /* -------------------------------------------------------------------------- */ static void _free0 (gpointer p) { if (p) g_free(p); } static GPrivate th_local_key_reqid = G_PRIVATE_INIT(_free0); const char * oio_ext_get_reqid (void) { return g_private_get(&th_local_key_reqid); } void oio_ext_set_reqid (const char *reqid) { g_private_replace (&th_local_key_reqid, g_strdup (reqid)); } void oio_ext_set_random_reqid (void)
*/ #include "GstJniUtils.h" #include <glib.h> extern "C" JavaVM* g_pJVM; void DetachThread(gpointer data) { void *env = NULL; if (g_pJVM && g_pJVM->GetEnv(&env, JNI_VERSION_1_2) != JNI_EDETACHED) g_pJVM->DetachCurrentThread(); } static GPrivate g_Private = G_PRIVATE_INIT(DetachThread); jboolean GstGetEnv(JNIEnv **env) { if (g_pJVM->GetEnv((void**)env, JNI_VERSION_1_2) == JNI_OK) return true; else { JNIEnv *private_env = (JNIEnv*)g_private_get(&g_Private); if (!private_env) { if (g_pJVM->AttachCurrentThreadAsDaemon((void**)&private_env, NULL) == 0) g_private_set(&g_Private, private_env); else return false; }
#include <gtk/gtk.h> #include "glk.h" #include "abort.h" #include "chimara-glk.h" #include "chimara-glk-private.h" #include "gi_blorb.h" #include "window.h" G_GNUC_INTERNAL GPrivate glk_data_key = G_PRIVATE_INIT(NULL); static gboolean emit_stopped_signal(ChimaraGlk *glk) { g_signal_emit_by_name(glk, "stopped"); return G_SOURCE_REMOVE; } /** * 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
#include <gio/gio.h> #include "gvfsdaemondbus.h" #include <gvfsdaemonprotocol.h> #include <gdaemonvfs.h> #include <gvfsdbus.h> /* Extra vfs-specific data for GDBusConnections */ typedef struct { char *async_dbus_id; } VfsConnectionData; typedef struct _ThreadLocalConnections ThreadLocalConnections; static void free_local_connections (ThreadLocalConnections *local); static GPrivate local_connections = G_PRIVATE_INIT((GDestroyNotify)free_local_connections); /* dbus id -> async connection */ static GHashTable *async_map = NULL; G_LOCK_DEFINE_STATIC(async_map); GQuark _g_vfs_error_quark (void) { return g_quark_from_static_string ("g-vfs-error-quark"); } static void connection_data_free (gpointer p) {
}; typedef struct _PreloadWorker PreloadWorker; struct _PreloadWorker { GModule* handle; TorInterposeFuncs tor; ShadowTorInterposeFuncs shadowtor; }; /* * the key used to store each threads version of their searched function library. * the use this key to retrieve this library when intercepting functions from tor. * The PrelaodWorker we store here will be freed using g_free automatically when * the thread exits. */ static GPrivate threadPreloadWorkerKey = G_PRIVATE_INIT(g_free); /* 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; } /* forward declarations */ static void _shadowtorpreload_cryptoSetup(int);
GMutex lock; GMutex pluginInitLock; gint rawFrequencyKHz; guint numEventsCurrentInterval; guint numNodesWithEventsCurrentInterval; /* id generation counters, must be protected for thread safety */ volatile gint workerIDCounter; MAGIC_DECLARE; }; /* holds a thread-private key that each thread references to get a private * instance of a worker object */ static GPrivate workerKey = G_PRIVATE_INIT(worker_free); static GPrivate preloadKey = G_PRIVATE_INIT(g_free); Engine* engine_new(Configuration* config) { MAGIC_ASSERT(config); /* Don't do anything in this function that will cause a log message. The * global engine is still NULL since we are creating it now, and logging * here will cause an assertion error. */ Engine* engine = g_new0(Engine, 1); MAGIC_INIT(engine); engine->config = config; engine->random = random_new(config->randomSeed);
namespace M { #ifdef LIBMARY_MT_SAFE static void tlocal_destructor (_libMary_VoidPtr _tlocal); #ifdef LIBMARY_PTHREAD pthread_key_t _libMary_tlocal_key; #else #ifdef LIBMARY__OLD_GTHREAD_API #ifndef LIBMARY_TLOCAL GPrivate *_libMary_tlocal_gprivate = NULL; #endif GPrivate *_libMary_tlocal_gprivate_dtor = NULL; #else #ifndef LIBMARY_TLOCAL GPrivate _libMary_tlocal_gprivate; #endif GPrivate _libMary_tlocal_gprivate_dtor = G_PRIVATE_INIT (tlocal_destructor); #endif #endif #ifdef LIBMARY_TLOCAL LIBMARY_TLOCAL LibMary_ThreadLocal *_libMary_tlocal = NULL; #endif static LibMary_ThreadLocal *_libMary_main_tlocal = NULL; #else LibMary_ThreadLocal *_libMary_tlocal = NULL; #endif LibMary_ThreadLocal::LibMary_ThreadLocal () : deletion_ctx (NULL), deletion_queue (NULL), deletion_queue_processing (false), state_mutex_counter (0), exc (NULL), exc_free_stack_size (0), last_coderef_container_shadow (NULL), time_seconds (0), time_microseconds (0), unixtime (0), time_log_frac (0), saved_unixtime (0), saved_monotime (0) #ifdef LIBMARY_PLATFORM_WIN32 , prv_win_time_dw (0), win_time_offs (0) #endif #ifndef LIBMARY_GLIB , rand_initialized (false), rand_state (0) #endif { exc_buffer = grab (new (std::nothrow) ExceptionBuffer (LIBMARY__EXCEPTION_BUFFER_SIZE)); memset (&localtime, 0, sizeof (localtime)); memset (timezone_str, ' ', sizeof (timezone_str)); strerr_buf_size = 4096; strerr_buf = new (std::nothrow) char [strerr_buf_size]; assert (strerr_buf); } LibMary_ThreadLocal::~LibMary_ThreadLocal () { // Note: This dtor should not call any code which requires valid tlocal. // Exceptions cleanup while (!exc_block_stack.isEmpty() || !exc_free_stack.isEmpty()) { { IntrusiveList<ExceptionBuffer>::iterator iter (exc_block_stack); while (!iter.done()) { ExceptionBuffer * const exc_buf = iter.next (); delete exc_buf; } exc_block_stack.clear (); } { IntrusiveList<ExceptionBuffer>::iterator iter (exc_free_stack); while (!iter.done()) { ExceptionBuffer * const exc_buf = iter.next (); delete exc_buf; } exc_free_stack.clear (); } if (exc_buffer->getException()) exc_none (); else exc_buffer = NULL; } delete[] strerr_buf; } #ifdef LIBMARY_MT_SAFE 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 } #endif 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 } void libMary_releaseThreadLocalForMainThread () { // Exception dtors may call arbitrary code, so we're // clearing exceptions first. exc_none (); #if defined LIBMARY_MT_SAFE delete _libMary_main_tlocal; _libMary_main_tlocal = NULL; #else delete _libMary_tlocal; _libMary_tlocal = NULL; #endif } }
G_DEFINE_TYPE(Log4gThread, log4g_thread, G_TYPE_OBJECT) #define ASSIGN_PRIVATE(instance) \ (G_TYPE_INSTANCE_GET_PRIVATE(instance, LOG4G_TYPE_THREAD, \ struct Private)) #define GET_PRIVATE(instance) \ ((struct Private *)((Log4gThread *)instance)->priv) struct Private { gchar *name; }; /* Thread specific data. */ static GPrivate priv = G_PRIVATE_INIT(g_object_unref); /* Count the number of thread name requests. */ static gint counter = 0; static void log4g_thread_init(Log4gThread *self) { self->priv = ASSIGN_PRIVATE(self); } static GObject * constructor(GType type, guint n, GObjectConstructParam *params) { GObject *self = g_private_get(&priv); if (!self) {
thread_func (thread, user_data); g_slist_free_1 (node); } } static void g_enumerable_thread_remove (gpointer data) { GRealThread *thread = data; G_LOCK (g_thread); g_thread_all_threads = g_slist_remove (g_thread_all_threads, thread); G_UNLOCK (g_thread); } GPrivate enumerable_thread_private = G_PRIVATE_INIT (g_enumerable_thread_remove); 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); } static gpointer g_deprecated_thread_proxy (gpointer data) { GRealThread *real = data;
}; static void call_data_unref (RustCallData *call_data) { if (g_atomic_int_dec_and_test (&call_data->ref_count)) { g_cond_clear (&call_data->return_cond); g_source_unref (call_data->source); g_main_context_unref (call_data->context); g_slice_free (RustCallData, call_data); } } static GPrivate rust_thread_context = G_PRIVATE_INIT((GDestroyNotify) g_main_context_unref); /* These could be per-call and per-context mutexes. * The balance of reduced contention vs. extra init/cleanup calls, * as well as bookkeeping of the extra context data, * would need to be profiled. */ static GMutex call_mutex; static GMutex rust_context_mutex; static GCond rust_context_released_cond; static gboolean loop_callback (gpointer data) { RustCallData *call_data = data; g_mutex_lock (&call_mutex);
static void _local_free (gpointer p) { struct oio_ext_local_s *l = p; if (!l) return; oio_str_clean (&l->reqid); if (l->prng) { g_rand_free (l->prng); l->prng = NULL; } g_free (l); } static GPrivate th_local_key = G_PRIVATE_INIT(_local_free); static struct oio_ext_local_s * _local_get (void) { return g_private_get(&th_local_key); } static struct oio_ext_local_s * _local_ensure (void) { struct oio_ext_local_s *l = _local_get (); if (!l) { l = g_malloc0 (sizeof(*l)); g_private_replace (&th_local_key, l); }
void (* CFLog) (CFLogLevel level, CFStringRef format, ...); }; # endif #endif static void gum_do_init (void); static GumAddress * gum_address_copy (const GumAddress * address); static void gum_address_free (GumAddress * address); static gboolean gum_initialized = FALSE; static GSList * gum_early_destructors = NULL; static GSList * gum_final_destructors = NULL; static GPrivate gum_internal_thread_details_key = G_PRIVATE_INIT ( (GDestroyNotify) gum_internal_thread_details_free); static GumInterceptor * gum_cached_interceptor = NULL; G_DEFINE_BOXED_TYPE (GumAddress, gum_address, gum_address_copy, gum_address_free) void gum_init (void) { if (gum_initialized) return; gum_initialized = TRUE; gum_do_init (); }
static void _g_module_close (gpointer handle, gboolean is_unref); static gpointer _g_module_self (void); static gpointer _g_module_symbol (gpointer handle, const gchar *symbol_name); static gchar* _g_module_build_path (const gchar *directory, const gchar *module_name); static inline void g_module_set_error (const gchar *error); static inline GModule* g_module_find_by_handle (gpointer handle); static inline GModule* g_module_find_by_name (const gchar *name); /* --- variables --- */ static GModule *modules = NULL; static GModule *main_module = NULL; static GPrivate module_error_private = G_PRIVATE_INIT (g_free); static gboolean module_debug_initialized = FALSE; static guint module_debug_flags = 0; /* --- inline functions --- */ static inline GModule* g_module_find_by_handle (gpointer handle) { GModule *module; GModule *retval = NULL; if (main_module && main_module->handle == handle) retval = main_module; else for (module = modules; module; module = module->next)