/** Initialize source port */ static int su_source_port_init(su_port_t *self, su_port_vtable_t const *vtable) { GSource *gs = (GSource *)((char *)self - offsetof(SuSource, ss_port)); self->sup_source = gs; g_static_mutex_init(self->sup_obtained); g_static_mutex_init(self->sup_mutex); return su_base_port_init(self, vtable); }
static void empathy_audio_sink_init (EmpathyGstAudioSink *self) { self->priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self); self->priv->echo_cancel = TRUE; g_static_mutex_init (&self->priv->volume_mutex); }
void stats_registry_init(void) { counter_hash = g_hash_table_new_full((GHashFunc) stats_cluster_hash, (GEqualFunc) stats_cluster_equal, NULL, (GDestroyNotify) stats_cluster_free); g_static_mutex_init(&stats_mutex); }
AFInetDestDriver * afinet_dd_new_instance(gint af, gint sock_type, gchar *host) { AFInetDestDriver *self = g_new0(AFInetDestDriver, 1); afsocket_dd_init_instance(&self->super, &self->sock_options.super, af, sock_type, host); self->super.super.super.super.init = afinet_dd_init; self->super.super.super.super.queue = afinet_dd_queue; self->super.super.super.super.free_fn = afinet_dd_free; self->super.setup_socket = afinet_dd_setup_socket; self->super.apply_transport = afinet_dd_apply_transport; if (sock_type == SOCK_STREAM) { self->sock_options.super.so_keepalive = TRUE; #if defined(TCP_KEEPTIME) && defined(TCP_KEEPIDLE) && defined(TCP_KEEPCNT) self->sock_options.tcp_keepalive_time = 60; self->sock_options.tcp_keepalive_intvl = 10; self->sock_options.tcp_keepalive_probes = 6; #endif } #if ENABLE_SPOOF_SOURCE g_static_mutex_init(&self->lnet_lock); #endif return self; }
GlibLogger * GlibUtils_CreateFileLogger(const char *path, gboolean append, guint maxSize, guint maxFiles) { FileLogger *data = NULL; g_return_val_if_fail(path != NULL, NULL); data = g_new0(FileLogger, 1); data->handler.addsTimestamp = FALSE; data->handler.shared = FALSE; data->handler.logfn = FileLoggerLog; data->handler.dtor = FileLoggerDestroy; data->path = g_filename_from_utf8(path, -1, NULL, NULL, NULL); if (data->path == NULL) { g_free(data); return NULL; } data->append = append; data->maxSize = maxSize * 1024 * 1024; data->maxFiles = maxFiles + 1; /* To account for the active log file. */ g_static_mutex_init(&data->lock); return &data->handler; }
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; }
static GstTagData * gst_tag_setter_get_data (GstTagSetter * setter) { GstTagData *data; data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key); if (!data) { static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT; /* make sure no other thread is creating a GstTagData at the same time */ g_static_mutex_lock (&create_mutex); data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key); if (!data) { data = g_slice_new (GstTagData); g_static_mutex_init (&data->lock); data->list = NULL; data->mode = GST_TAG_MERGE_KEEP; g_object_set_qdata_full (G_OBJECT (setter), gst_tag_key, data, gst_tag_data_free); } g_static_mutex_unlock (&create_mutex); } return data; }
RpcChannel * BackdoorChannel_New(void) { RpcChannel *ret; BackdoorChannel *bdoor; ret = RpcChannel_Create(); bdoor = g_malloc0(sizeof *bdoor); g_static_mutex_init(&bdoor->outLock); bdoor->out = RpcOut_Construct(); ASSERT(bdoor->out != NULL); bdoor->inStarted = FALSE; bdoor->outStarted = FALSE; ret->start = RpcInStart; ret->stop = RpcInStop; ret->send = RpcInSend; ret->setup = RpcInSetup; ret->shutdown = RpcInShutdown; ret->_private = bdoor; return ret; }
/* one-time initialization of the MlBatchedTimer structure */ void ml_batched_timer_init(MlBatchedTimer *self) { g_static_mutex_init(&self->lock); IV_TIMER_INIT(&self->timer); self->timer.cookie = self; self->timer.handler = (void (*)(void *)) ml_batched_timer_handle; }
struct target_pool *target_pool_new() { struct target_pool *retval = g_malloc0(sizeof(struct target_pool)); retval->table = g_hash_table_new(g_str_hash, g_str_equal); g_static_mutex_init(&retval->mutex); retval->deleted=false; return retval; }
static gpointer MsgInitState(gpointer unused) { ASSERT(msgState == NULL); msgState = g_new0(MsgState, 1); g_static_mutex_init(&msgState->lock); return NULL; }
static void late_ack_tracker_init_instance(LateAckTracker *self, LogSource *source) { self->super.source = source; source->ack_tracker = (AckTracker *)self; ring_buffer_alloc(&self->ack_record_storage, sizeof(LateAckRecord), log_source_get_init_window_size(source)); g_static_mutex_init(&self->storage_mutex); _setup_callbacks(self); }
void log_queue_init_instance(LogQueue *self, const gchar *persist_name) { g_atomic_counter_set(&self->ref_cnt, 1); self->free_fn = log_queue_free_method; self->persist_name = persist_name ? g_strdup(persist_name) : NULL; g_static_mutex_init(&self->lock); }
static void coil_expandable_init(CoilExpandable *self) { g_return_if_fail(COIL_IS_EXPANDABLE(self)); CoilExpandablePrivate *priv = COIL_EXPANDABLE_GET_PRIVATE(self); self->priv = priv; g_static_mutex_init(&priv->expand_lock); }
static void late_ack_tracker_init_instance(LateAckTracker *self, LogSource *source) { self->super.late = TRUE; self->super.source = source; source->ack_tracker = (AckTracker *)self; self->super.request_bookmark = late_ack_tracker_request_bookmark; self->super.track_msg = late_ack_tracker_track_msg; self->super.manage_msg_ack = late_ack_tracker_manage_msg_ack; ring_buffer_alloc(&self->ack_record_storage, sizeof(LateAckRecord), log_source_get_init_window_size(source)); g_static_mutex_init(&self->storage_mutex); }
/************************************************************** * class cHandler *************************************************************/ cHandler::cHandler( unsigned int id, unsigned short port, oh_evt_queue& eventq ) : cObject( "root" ), cConsole( port, *this ), m_id( id ), m_eventq( eventq ), m_ai_timeout( SAHPI_TIMEOUT_IMMEDIATE ) { g_static_mutex_init( &m_lock ); }
static void gst_skin_init(GstSkin * skin, GstSkinClass * klass) { gst_base_transform_set_in_place((GstBaseTransform *)skin, TRUE); g_static_mutex_init(&skin->lock); skin->cvRGB = NULL; skin->display = false; skin->enableskin = true; skin->showH = false; skin->showS = false; skin->showV = false; skin->method = 1; // RGB by default!!! }
static void crypto_init_threading(void) { gint i; ssl_lock_count = CRYPTO_num_locks(); ssl_locks = g_new(GStaticMutex, ssl_lock_count); for (i = 0; i < ssl_lock_count; i++) { g_static_mutex_init(&ssl_locks[i]); } CRYPTO_set_id_callback(ssl_thread_id); CRYPTO_set_locking_callback(ssl_locking_callback); }
RpcChannel * RpcChannel_New(void) { RpcChannel *chan; #if (defined(__linux__) && !defined(USERWORLD)) || defined(_WIN32) chan = gUseBackdoorOnly ? BackdoorChannel_New() : VSockChannel_New(); #else chan = BackdoorChannel_New(); #endif if (chan) { g_static_mutex_init(&chan->outLock); } return chan; }
static void gst_retinex_init(GstRetinex * retinex, GstRetinexClass * klass) { gst_base_transform_set_in_place((GstBaseTransform *)retinex, TRUE); g_static_mutex_init(&retinex->lock); retinex->pFrame = NULL; retinex->pFrame2 = NULL; retinex->pFrameA = NULL; retinex->ch1 = NULL; retinex->ch2 = NULL; retinex->ch3 = NULL; retinex->display = false; }
LogReader * log_reader_new(GlobalConfig *cfg) { LogReader *self = g_new0(LogReader, 1); log_source_init_instance(&self->super, cfg); self->super.super.init = log_reader_init; self->super.super.deinit = log_reader_deinit; self->super.super.free_fn = log_reader_free; self->super.wakeup = log_reader_wakeup; self->immediate_check = FALSE; log_reader_init_watches(self); g_static_mutex_init(&self->pending_proto_lock); self->pending_proto_cond = g_cond_new(); return self; }
LogPipe * log_reader_new(LogProto *proto) { LogReader *self = g_new0(LogReader, 1); log_source_init_instance(&self->super); self->super.super.init = log_reader_init; self->super.super.deinit = log_reader_deinit; self->super.super.free_fn = log_reader_free; self->super.wakeup = log_reader_wakeup; self->proto = proto; self->immediate_check = FALSE; self->pollable_state = -1; log_reader_init_watches(self); g_static_mutex_init(&self->pending_proto_lock); self->pending_proto_cond = g_cond_new(); return &self->super.super; }
int main (int argc, char *argv[]) { g_thread_init (NULL); gtk_init (&argc, &argv); document.grf = (Grf *) 0; mainWin.init (); memset (&extractProgress, 0, sizeof (ExtractProgress)); g_static_mutex_init (&extractProgressM); if (argv[1]) gtk_idle_add (idle_open, argv[1]); gtk_widget_realize (W(main)); gtk_widget_show (W(main)); gtk_main (); return 0; }
/* Initialize a [zeroed] struct wmxsdk */ static struct wmxsdk *wmxsdk_new(void) { struct wmxsdk *wmxsdk; wmxsdk = malloc(sizeof(*wmxsdk)); if (wmxsdk) { memset(wmxsdk, 0, sizeof(*wmxsdk)); wmxsdk->refcount = 1; g_static_mutex_init(&wmxsdk->network_mutex); wmxsdk->status = WIMAX_API_DEVICE_STATUS_UnInitialized; wmxsdk->status_mutex = g_mutex_new(); g_assert(wmxsdk->status_mutex); wmxsdk->connect_mutex = g_mutex_new(); g_assert(wmxsdk->connect_mutex); } return wmxsdk; }
static AFInetDestDriver * afinet_dd_new_instance(TransportMapper *transport_mapper, gchar *hostname, GlobalConfig *cfg) { AFInetDestDriver *self = g_new0(AFInetDestDriver, 1); afsocket_dd_init_instance(&self->super, socket_options_inet_new(), transport_mapper, cfg); self->super.super.super.super.init = afinet_dd_init; self->super.super.super.super.queue = afinet_dd_queue; self->super.super.super.super.free_fn = afinet_dd_free; self->super.construct_writer = afinet_dd_construct_writer; self->super.setup_addresses = afinet_dd_setup_addresses; self->super.get_dest_name = afinet_dd_get_dest_name; self->hostname = g_strdup(hostname); #if SYSLOG_NG_ENABLE_SPOOF_SOURCE g_static_mutex_init(&self->lnet_lock); self->spoof_source_maxmsglen = 1024; #endif return self; }
gboolean engine_cryptoSetup(Engine* engine, gint numLocks) { MAGIC_ASSERT(engine); if(numLocks) { _engine_lock(engine); if(engine->cryptoThreadLocks) { g_assert(numLocks <= engine->numCryptoThreadLocks); } else { engine->numCryptoThreadLocks = numLocks; engine->cryptoThreadLocks = g_new0(GStaticMutex, numLocks); for(int i = 0; i < engine->numCryptoThreadLocks; i++) { g_static_mutex_init(&(engine->cryptoThreadLocks[i])); } } _engine_unlock(engine); } return TRUE; }
LogParser * log_db_parser_new(void) { LogDBParser *self = g_new0(LogDBParser, 1); log_parser_init_instance(&self->super); self->super.super.free_fn = log_db_parser_free; self->super.super.init = log_db_parser_init; self->super.super.deinit = log_db_parser_deinit; self->super.super.clone = log_db_parser_clone; self->super.process = log_db_parser_process; self->db_file = g_strdup(PATH_PATTERNDB_FILE); g_static_mutex_init(&self->lock); if (configuration && configuration->version < 0x0303) { msg_warning("WARNING: The default behaviour for injecting messages in db-parser() has changed in version 3.3 from internal to pass-through, use an explicit inject-mode(internal) option for old behaviour", NULL); self->inject_mode = LDBP_IM_INTERNAL; } else self->inject_mode = LDBP_IM_PASSTHROUGH; return &self->super; }
static void gst_gcs_init(GstGcs * gcs, GstGcsClass * klass) { gst_base_transform_set_in_place((GstBaseTransform *)gcs, TRUE); g_static_mutex_init(&gcs->lock); gcs->pImageRGBA = NULL; gcs->pImgRGB = NULL; gcs->pImgGRAY = NULL; gcs->pImgGRAY_copy = NULL; gcs->pImgGRAY_diff = NULL; gcs->pImgGRAY_1 = NULL; gcs->pImgGRAY_1copy = NULL; gcs->pImgChA = NULL; gcs->pImgCh1 = NULL; gcs->pImgCh2 = NULL; gcs->pImgCh3 = NULL; gcs->ghostfilename = NULL; gcs->display = false; gcs->debug = 0; }
/** * Initialize all data: * - Create different queues: * - tls_push_queue: read in push_worker() ; * - connections_queue: read in search_and_fill() ; * - localid_auth_queue: read in localid_auth(). * - Create hash table ::conn_list * - Init. modules: init_modules_system(), load_modules() * - Init. periods: init_periods() * - Init. cache: init_acl_cache() and init_user_cache() (if enabled) * - Create thread pools: * - ip_authentication_workers with external_ip_auth() (if enabled) ; * - acl_checkers with acl_check_and_decide() ; * - user_loggers with real_log_user_packet() ; * - user_session_loggers with log_user_session_thread() ; * - decisions_workers with decisions_queue_work(). * - Create threads: * - tls_pusher with push_worker() ; * - search_and_fill_worker with search_and_fill() ; * - localid_auth_thread with localid_auth() (if needed) ; * - tls_auth_servers with tls_user_start_servers() ; * - tls_nufw_servers with tls_nufw_start_servers() ; * - limited_connections_handler with limited_connection_handler(). * * Other queue, threads, etc. are created elsewhere: * - in tls_user_init(): tls_sasl_worker thread pool, tls_sasl_connect(). */ void init_nuauthdata() { block_thread_pools(); nuauthdatas->tls_push_queue = g_async_queue_new(); if (!nuauthdatas->tls_push_queue) exit(EXIT_FAILURE); /* initialize packets list */ conn_list = g_hash_table_new_full((GHashFunc) hash_connection, (GEqualFunc) tracking_equal, NULL, (GDestroyNotify) free_connection); /* async queue initialisation */ nuauthdatas->connections_queue = g_async_queue_new(); if (!nuauthdatas->connections_queue) exit(EXIT_FAILURE); init_protocol_extension(nuauthdatas); /* init and load modules */ init_modules_system(); if (!load_modules()) exit(EXIT_FAILURE); /* init periods */ nuauthconf->periods = init_periods(nuauthconf); if (nuauthconf->acl_cache) init_acl_cache(); /* create user cache thread */ if (nuauthconf->user_cache) init_user_cache(); start_all_thread_pools(); null_message = g_new0(struct cache_message, 1); null_queue_datas = g_new0(gchar, 1); /* init private datas for pool thread */ nuauthdatas->aclqueue = g_private_new((GDestroyNotify) g_async_queue_unref); nuauthdatas->userqueue = g_private_new((GDestroyNotify) g_async_queue_unref); g_static_mutex_init(&insert_mutex); /* create thread for search_and_fill thread */ log_message(VERBOSE_DEBUG, DEBUG_AREA_MAIN, "Creating search_and_fill thread"); thread_new(&nuauthdatas->search_and_fill_worker, "search&fill", search_and_fill); if (nuauthconf->push && nuauthconf->hello_authentication) { log_message(VERBOSE_DEBUG, DEBUG_AREA_MAIN, "Creating hello mode authentication thread"); nuauthdatas->localid_auth_queue = g_async_queue_new(); thread_new(&nuauthdatas->localid_auth_thread, "localid", localid_auth); } #ifdef BUILD_NUAUTH_COMMAND if (nuauthconf->use_command_server) { log_message(VERBOSE_DEBUG, DEBUG_AREA_MAIN, "Creating command thread"); thread_new(&nuauthdatas->command_thread, "command", command_server); } #endif /* create thread for client request sender */ thread_new(&nuauthdatas->tls_pusher, "tls pusher", push_worker); /* create TLS authentication server threads (auth + nufw) */ tls_common_init(); log_message(VERBOSE_DEBUG, DEBUG_AREA_MAIN, "Creating tls authentication server threads"); tls_user_start_servers(nuauthdatas->tls_auth_servers); log_message(VERBOSE_DEBUG, DEBUG_AREA_MAIN, "Creating tls nufw server threads"); tls_nufw_start_servers(nuauthdatas->tls_nufw_servers); log_message(INFO, DEBUG_AREA_MAIN, "Threads system started"); release_thread_pools(); nuauthdatas->is_starting = FALSE; }
lcm_provider_t * lcm_udpm_create (lcm_t * parent, const char *network, const GHashTable *args) { udpm_params_t params; memset (¶ms, 0, sizeof (udpm_params_t)); g_hash_table_foreach ((GHashTable*) args, new_argument, ¶ms); if (parse_mc_addr_and_port (network, ¶ms) < 0) { return NULL; } lcm_udpm_t * lcm = (lcm_udpm_t *) calloc (1, sizeof (lcm_udpm_t)); lcm->lcm = parent; lcm->params = params; lcm->recvfd = -1; lcm->sendfd = -1; lcm->thread_msg_pipe[0] = lcm->thread_msg_pipe[1] = -1; lcm->udp_low_watermark = 1.0; lcm->kernel_rbuf_sz = 0; lcm->warned_about_small_kernel_buf = 0; lcm->frag_bufs = NULL; // synchronization variables used when allocating receive resources lcm->creating_read_thread = 0; lcm->create_read_thread_mutex = NULL; lcm->create_read_thread_cond = NULL; // internal notification pipe if(0 != lcm_internal_pipe_create(lcm->notify_pipe)) { perror(__FILE__ " pipe(create)"); lcm_udpm_destroy (lcm); return NULL; } fcntl (lcm->notify_pipe[1], F_SETFL, O_NONBLOCK); g_static_rec_mutex_init (&lcm->mutex); g_static_mutex_init (&lcm->transmit_lock); dbg (DBG_LCM, "Initializing LCM UDPM context...\n"); dbg (DBG_LCM, "Multicast %s:%d\n", inet_ntoa(params.mc_addr), ntohs (params.mc_port)); // setup destination multicast address memset (&lcm->dest_addr, 0, sizeof (lcm->dest_addr)); lcm->dest_addr.sin_family = AF_INET; lcm->dest_addr.sin_addr = params.mc_addr; lcm->dest_addr.sin_port = params.mc_port; // test connectivity SOCKET testfd = socket (AF_INET, SOCK_DGRAM, 0); if (connect (testfd, (struct sockaddr*) &lcm->dest_addr, sizeof (lcm->dest_addr)) < 0) { perror ("connect"); lcm_udpm_destroy (lcm); #ifdef __linux__ linux_check_routing_table(lcm->dest_addr.sin_addr); #endif return NULL; } lcm_close_socket(testfd); // create a transmit socket // // don't use connect() on the actual transmit socket, because linux then // has problems multicasting to localhost lcm->sendfd = socket (AF_INET, SOCK_DGRAM, 0); // set multicast TTL if (params.mc_ttl == 0) { dbg (DBG_LCM, "LCM multicast TTL set to 0. Packets will not " "leave localhost\n"); } dbg (DBG_LCM, "LCM: setting multicast packet TTL to %d\n", params.mc_ttl); if (setsockopt (lcm->sendfd, IPPROTO_IP, IP_MULTICAST_TTL, (char *) ¶ms.mc_ttl, sizeof (params.mc_ttl)) < 0) { perror ("setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)"); lcm_udpm_destroy (lcm); return NULL; } #ifdef WIN32 // Windows has small (8k) buffer by default // increase the send buffer to a reasonable amount. int send_buf_size = 256 * 1024; setsockopt(lcm->sendfd, SOL_SOCKET, SO_SNDBUF, (char*)&send_buf_size, sizeof(send_buf_size)); #endif // debugging... how big is the send buffer? int sockbufsize = 0; unsigned int retsize = sizeof(int); getsockopt(lcm->sendfd, SOL_SOCKET, SO_SNDBUF, (char*)&sockbufsize, (socklen_t *) &retsize); dbg (DBG_LCM, "LCM: send buffer is %d bytes\n", sockbufsize); // set loopback option on the send socket #ifdef __sun__ unsigned char send_lo_opt = 1; #else unsigned int send_lo_opt = 1; #endif if (setsockopt (lcm->sendfd, IPPROTO_IP, IP_MULTICAST_LOOP, (char *) &send_lo_opt, sizeof (send_lo_opt)) < 0) { perror ("setsockopt (IPPROTO_IP, IP_MULTICAST_LOOP)"); lcm_udpm_destroy (lcm); return NULL; } // don't start the receive thread yet. Only allocate resources for // receiving messages when a subscription is made. // However, we still need to setup sendfd in multi-cast group struct ip_mreq mreq; mreq.imr_multiaddr = lcm->params.mc_addr; mreq.imr_interface.s_addr = INADDR_ANY; dbg (DBG_LCM, "LCM: joining multicast group\n"); if (setsockopt (lcm->sendfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof (mreq)) < 0) { #ifdef WIN32 // ignore this error in windows... see issue #60 #else perror ("setsockopt (IPPROTO_IP, IP_ADD_MEMBERSHIP)"); lcm_udpm_destroy (lcm); return NULL; #endif } return lcm; }