ECLock * ec_lock_new (void) { // Make sure we have the GThread system up and running. if ( !g_thread_supported () ) { g_thread_init (NULL); } ECLock *self = g_new (ECLock, 1); self->state_mutex = g_mutex_new (); self->state_cv = g_cond_new (); self->state = EC_LOCK_STATE_UNLOCKED; self->lock = g_new (GStaticRWLock, 1); g_static_rw_lock_init (self->lock); self->trace_lock = g_new (GStaticMutex, 1); g_static_mutex_init (self->trace_lock); self->readers = g_hash_table_new (g_direct_hash, g_direct_equal); self->writer = NULL; self->trace_on = FALSE; self->traced_threads = g_hash_table_new (g_direct_hash, g_direct_equal); self->thread_names = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) my_g_string_free); self->ref_count_mutex = g_mutex_new (); self->reference_count = 1; self->free_lock = g_new (GStaticRWLock, 1); g_static_rw_lock_init (self->free_lock); self->destroyed = FALSE; return self; }
/** * pka_subscription_new: * * Creates a new instance of #PkaSubscription. * * Returns: the newly created instance. */ PkaSubscription* pka_subscription_new (void) { static gint id_seq = 0; PkaSubscription *subscription; #define INITIALIZE_TREE(_field, _free) \ G_STMT_START { \ subscription->_field = g_tree_new_full( \ (GCompareDataFunc)g_int_compare, \ subscription, \ (GDestroyNotify)g_free, \ (GDestroyNotify)_free); \ } G_STMT_END ENTRY; subscription = g_slice_new0(PkaSubscription); subscription->ref_count = 1; g_static_rw_lock_init(&subscription->rw_lock); subscription->id = g_atomic_int_exchange_and_add(&id_seq, 1); subscription->state = PKA_SUBSCRIPTION_MUTED; g_get_current_time(&subscription->created_at); INITIALIZE_TREE(channels, g_object_unref); INITIALIZE_TREE(sources, g_object_unref); INITIALIZE_TREE(manifests, pka_manifest_unref); RETURN(subscription); }
struct conscience_s * conscience_create(void) { struct conscience_s *conscience; conscience = g_malloc0(sizeof(struct conscience_s)); namespace_info_init (&conscience->ns_info); g_static_rw_lock_init(&(conscience->rwlock_srv)); conscience->srvtypes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) conscience_srvtype_destroy); if (!conscience->srvtypes) { conscience_destroy(conscience); return NULL; } conscience->default_srvtype = conscience_srvtype_create(conscience, "default"); if (!conscience->default_srvtype) { conscience_destroy(conscience); return NULL; } return conscience; }
static void fs_rtp_sub_stream_init (FsRtpSubStream *self) { self->priv = FS_RTP_SUB_STREAM_GET_PRIVATE (self); self->priv->receiving = TRUE; self->priv->mutex = g_mutex_new (); g_static_rw_lock_init (&self->priv->stopped_lock); }
PatternDB * pattern_db_new(void) { PatternDB *self = g_new0(PatternDB, 1); self->ruleset = pdb_rule_set_new(); _init_state(self); cached_g_current_time(&self->last_tick); g_static_rw_lock_init(&self->lock); return self; }
xr_server* xr_server_new(const char* cert, const char* privkey, int threads, GError** err) { xr_trace(XR_DEBUG_SERVER_TRACE, "(cert=%s, threads=%d, err=%p)", cert, threads, err); GError* local_err = NULL; g_return_val_if_fail(threads > 0 && threads < 1000, NULL); g_return_val_if_fail (err == NULL || *err == NULL, NULL); xr_init(); xr_server* server = g_new0(xr_server, 1); server->secure = !!cert; server->service = g_threaded_socket_service_new(threads); g_signal_connect(server->service, "run", (GCallback)_xr_server_service_run, server); if (cert) { gchar *cert_and_privkey = g_strconcat(cert, privkey, NULL); server->cert = g_tls_certificate_new_from_pem(cert_and_privkey, -1, &local_err); g_free(cert_and_privkey); if (local_err) { g_propagate_prefixed_error(err, local_err, "Certificate load failed: "); goto err0; } } server->sessions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)xr_servlet_free_fini); g_static_rw_lock_init(&server->sessions_lock); server->sessions_cleaner = g_thread_create((GThreadFunc)sessions_cleaner_func, server, TRUE, NULL); if (server->sessions_cleaner == NULL) goto err1; return server; err1: g_hash_table_destroy(server->sessions); g_static_rw_lock_free(&server->sessions_lock); if (server->cert) g_object_unref(server->cert); err0: g_object_unref(server->service); g_free(server); return NULL; }
static void pkg_window_init (PkgWindow *window) { PkgWindowPrivate *priv; GtkAccelGroup *accel_group; GtkWidget *vbox; GtkWidget *menu_bar; GtkWidget *perfkit_menu; GtkWidget *help_menu; GtkWidget *hpaned; GtkWidget *scroller; GtkTreeViewColumn *column; GtkCellRenderer *text; GtkCellRenderer *cpix; GtkTreeSelection *selection; ENTRY; priv = G_TYPE_INSTANCE_GET_PRIVATE(window, PKG_TYPE_WINDOW, PkgWindowPrivate); window->priv = priv; g_static_rw_lock_init(&priv->rw_lock); gtk_window_set_title(GTK_WINDOW(window), _("Perfkit")); gtk_window_set_default_size(GTK_WINDOW(window), 780, 550); accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show(vbox); menu_bar = gtk_menu_bar_new(); gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, TRUE, 0); gtk_widget_show(menu_bar); #define ADD_MENU(_n, _s) \ G_STMT_START { \ GtkWidget *_w; \ _w = gtk_menu_item_new_with_mnemonic((_s)); \ gtk_widget_show((_w)); \ gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), (_w)); \ _n = gtk_menu_new(); \ gtk_menu_item_set_submenu(GTK_MENU_ITEM(_w), _n); \ } G_STMT_END #define ADD_MENU_ITEM(_p, _s, _f) \ G_STMT_START { \ GtkWidget *_w; \ _w = gtk_menu_item_new_with_mnemonic(_s); \ gtk_widget_show((_w)); \ gtk_menu_shell_append(GTK_MENU_SHELL(_p), (_w)); \ g_signal_connect(_w, "activate", G_CALLBACK(_f), \ window); \ } G_STMT_END #define ADD_MENU_ITEM_STOCK(_p, _s, _f) \ G_STMT_START { \ GtkWidget *_w = gtk_image_menu_item_new_from_stock( \ (_s), accel_group); \ gtk_widget_show((_w)); \ gtk_menu_shell_append(GTK_MENU_SHELL(_p), (_w)); \ g_signal_connect(_w, "activate", G_CALLBACK(_f), \ window); \ } G_STMT_END #define ADD_SEPARATOR(_p) \ G_STMT_START { \ GtkWidget *_w = gtk_separator_menu_item_new(); \ gtk_widget_show((_w)); \ gtk_menu_shell_append(GTK_MENU_SHELL(_p), (_w)); \ } G_STMT_END ADD_MENU(perfkit_menu, _("_Perfkit")); ADD_MENU_ITEM(perfkit_menu, _("Connect to _Server"), gtk_false); ADD_SEPARATOR(perfkit_menu); ADD_MENU_ITEM_STOCK(perfkit_menu, GTK_STOCK_REFRESH, pkg_window_refresh_all); ADD_SEPARATOR(perfkit_menu); ADD_MENU_ITEM_STOCK(perfkit_menu, GTK_STOCK_QUIT, gtk_main_quit); ADD_MENU(help_menu, _("_Help")); ADD_MENU_ITEM_STOCK(help_menu, GTK_STOCK_ABOUT, gtk_false); hpaned = gtk_hpaned_new(); gtk_paned_set_position(GTK_PANED(hpaned), 275); gtk_box_pack_start(GTK_BOX(vbox), hpaned, TRUE, TRUE, 0); gtk_widget_show(hpaned); scroller = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroller), GTK_SHADOW_IN); gtk_paned_add1(GTK_PANED(hpaned), scroller); gtk_widget_show(scroller); priv->model = gtk_tree_store_new(5, PK_TYPE_CONNECTION, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); priv->treeview = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER(scroller), priv->treeview); gtk_tree_view_set_model(GTK_TREE_VIEW(priv->treeview), GTK_TREE_MODEL(priv->model)); gtk_tree_view_expand_all(GTK_TREE_VIEW(priv->treeview)); gtk_widget_show(priv->treeview); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->treeview)); g_signal_connect(selection, "changed", G_CALLBACK(pkg_window_selection_changed), window); column = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(column, _("Agents")); gtk_tree_view_append_column(GTK_TREE_VIEW(priv->treeview), column); cpix = gtk_cell_renderer_pixbuf_new(); g_object_set(cpix, "stock-size", GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); gtk_tree_view_column_pack_start(column, cpix, FALSE); gtk_tree_view_column_set_cell_data_func(column, cpix, pkg_window_pixbuf_data_func, window, NULL); text = gtk_cell_renderer_text_new(); g_object_set(text, "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_tree_view_column_pack_start(column, text, TRUE); gtk_tree_view_column_set_cell_data_func(column, text, pkg_window_label_data_func, window, NULL); priv->container = gtk_alignment_new(0.5f, 0.5f, 1.0f, 1.0f); gtk_paned_add2(GTK_PANED(hpaned), priv->container); gtk_widget_show(priv->container); EXIT; }