void clientmgr_reomve_outdate_client(gulong inactive_time_allowed, void (*removethis)(Client * client) ) { time_t cutime; time(&cutime); gboolean remove_outdate(gpointer key, Client * client, GTree * newtree) { if( client->remove_outdate && ( (cutime - client->last_active_time) > inactive_time_allowed)) { removethis(client); }else { //add the unit to new tree g_tree_insert(newtree,g_memdup(key,6),g_object_ref(client)); } return FALSE; } g_static_rw_lock_writer_lock(&lock); GTree * oldclient_tree = client_tree; clientmgr_init(); g_tree_foreach(oldclient_tree,(GTraverseFunc)remove_outdate,client_tree); g_tree_unref(oldclient_tree); g_static_rw_lock_writer_unlock(&lock); }
/** Wrapper for e_cal_backend_cache_put_component(). * * Keeps track of cache state of the component by using * e_cal_component_set_cache_state(). If component already existed in cache and * did not have cache state E_CAL_COMPONENT_CACHE_STATE_CREATED, its cache state will * be set to E_CAL_COMPONENT_CACHE_STATE_MODIFIED, in all other cases it will be * set to will be set to E_CAL_COMPONENT_CACHE_STATE_CREATED. * * @param cb 3E calendar backend. * @param cache Calendar backend cache object. * @param comp ECalComponent object. * * @return TRUE if successfully stored. */ gboolean e_cal_backend_3e_cache_put_component(ECalBackend3e *cb, ECalBackendCache *cache, ECalComponent *comp) { ECalComponentId *id; ECalComponentCacheState cache_state = E_CAL_COMPONENT_CACHE_STATE_CREATED; gboolean retval; id = e_cal_component_get_id(comp); if (id) { g_static_rw_lock_writer_lock(&cb->priv->cache_lock); ECalComponent *existing = e_cal_backend_cache_get_component(cache, id->uid, id->rid); if (existing) { if (e_cal_component_get_cache_state(existing) != E_CAL_COMPONENT_CACHE_STATE_CREATED) { cache_state = E_CAL_COMPONENT_CACHE_STATE_MODIFIED; } g_object_unref(existing); } e_cal_component_set_cache_state(comp, cache_state); retval = e_cal_backend_cache_put_component(cache, comp); g_static_rw_lock_writer_unlock(&cb->priv->cache_lock); e_cal_component_free_id(id); return retval; } return FALSE; }
/** * pka_subscription_remove_source: * @subscription: A #PkaSubscription. * @context: A #PkaContext. * @source: A #PkaSource. * @error: A location for #GError, or %NULL. * * Removes @source from @subscription. * * Returns: %TRUE if successful; otherwise %FALSE and @error is set. * Side effects: None. */ gboolean pka_subscription_remove_source (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaSource *source, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; gint key; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); g_return_val_if_fail(PKA_IS_SOURCE(source), FALSE); ENTRY; if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Not authoraized to remove source %d from subscription %d.", pka_source_get_id(source), subscription->id); GOTO(failed); } key = pka_source_get_id(source); pka_source_remove_subscription(source, subscription); g_static_rw_lock_writer_lock(&subscription->rw_lock); g_tree_remove(subscription->sources, &key); g_static_rw_lock_writer_unlock(&subscription->rw_lock); ret = TRUE; failed: RETURN(ret); }
/** Wrapper for e_cal_backend_cache_remove_component(). * * This function does not actually remove component from cache in most cases. If * component already existed in cache and did not have cache state * E_CAL_COMPONENT_CACHE_STATE_CREATED, its state will be set to * E_CAL_COMPONENT_CACHE_STATE_REMOVED, otherwise it will be removed from cache. * * @param cb 3E calendar backend. * @param cache Calendar backend cache object. * @param uid UID of the calendar component. * @param rid RID of the detached instance of recurring event. * * @return TRUE if successfully removed, FALSE on failure (storage problem or not * found). */ gboolean e_cal_backend_3e_cache_remove_component(ECalBackend3e *cb, ECalBackendCache *cache, const char *uid, const char *rid) { ECalComponent *existing; gboolean retval; g_static_rw_lock_writer_lock(&cb->priv->cache_lock); existing = e_cal_backend_cache_get_component(cache, uid, rid); if (existing) { if (e_cal_component_get_cache_state(existing) == E_CAL_COMPONENT_CACHE_STATE_CREATED) { retval = e_cal_backend_cache_remove_component(cache, uid, rid); } else { e_cal_component_set_cache_state(existing, E_CAL_COMPONENT_CACHE_STATE_REMOVED); retval = e_cal_backend_cache_put_component(cache, existing); } g_object_unref(existing); } else { retval = FALSE; } g_static_rw_lock_writer_unlock(&cb->priv->cache_lock); return retval; }
gboolean pka_subscription_set_buffer (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ gint buffer_timeout, /* IN */ gint buffer_size, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); ENTRY; if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { GOTO(failed); } g_static_rw_lock_writer_lock(&subscription->rw_lock); subscription->buffer_timeout = buffer_timeout; subscription->buffer_size = buffer_size; /* * TODO: Flush buffers (once re-implemented). */ g_static_rw_lock_writer_unlock(&subscription->rw_lock); ret = TRUE; failed: RETURN(ret); }
static gboolean vfs_mime_type_reload( gpointer user_data ) { GList* l; /* FIXME: process mime database reloading properly. */ /* Remove all items in the hash table */ GDK_THREADS_ENTER(); g_static_rw_lock_writer_lock( &mime_hash_lock ); g_hash_table_foreach_remove ( mime_hash, ( GHRFunc ) gtk_true, NULL ); g_static_rw_lock_writer_unlock( &mime_hash_lock ); g_source_remove( reload_callback_id ); reload_callback_id = 0; /* g_debug( "reload mime-types" ); */ /* call all registered callbacks */ for( l = reload_cb; l; l = l->next ) { VFSMimeReloadCbEnt* ent = (VFSMimeReloadCbEnt*)l->data; ent->cb( ent->user_data ); } GDK_THREADS_LEAVE(); return FALSE; }
void trash_root_thaw (TrashRoot *root) { NotifyClosure *closure; gboolean size_changed; int size; /* send notifications until we have none */ while (TRUE) { g_static_rw_lock_writer_lock (&root->lock); if (g_queue_is_empty (root->notifications)) break; closure = g_queue_pop_head (root->notifications); g_static_rw_lock_writer_unlock (&root->lock); trash_item_invoke_closure (closure); } /* still holding lock... */ size = g_hash_table_size (root->item_table); size_changed = root->old_size != size; root->old_size = size; g_static_rw_lock_writer_unlock (&root->lock); if (size_changed) root->size_change (root->user_data); }
static void _lock_rw(GStaticRWLock * lock, char mode) { if (mode == 'w' || mode == 'W') g_static_rw_lock_writer_lock(lock); else g_static_rw_lock_reader_lock(lock); }
void pattern_db_forget_state(PatternDB *self) { g_static_rw_lock_writer_lock(&self->lock); _destroy_state(self); _init_state(self); g_static_rw_lock_writer_unlock(&self->lock); }
static void _pattern_db_process_unmatching_rule(PatternDB *self, PDBProcessParams *process_params) { LogMessage *msg = process_params->msg; g_static_rw_lock_writer_lock(&self->lock); _advance_time_based_on_message(self, process_params, &msg->timestamps[LM_TS_STAMP]); _emit_message(self, process_params, FALSE, msg); g_static_rw_lock_writer_unlock(&self->lock); }
gboolean clientmgr_reomve_client(Client * client) { gboolean ret; g_static_rw_lock_writer_lock(&lock); ret = clientmgr_reomve_client_internal(client); g_static_rw_lock_writer_unlock(&lock); return ret; }
/** Wrapper for e_cal_backend_cache_put_timezone(). * * Put timezone into cache. Timezone component cache state will be set to * E_CAL_COMPONENT_CACHE_STATE_CREATED. * * @param cb 3E calendar backend. * @param cache Calendar backend cache object. * @param zone icaltimezone object. * * @return TRUE if successfully stored. */ gboolean e_cal_backend_3e_cache_put_timezone(ECalBackend3e *cb, ECalBackendCache *cache, const icaltimezone *zone) { gboolean retval; icalcomponent_set_cache_state(icaltimezone_get_component((icaltimezone *)zone), E_CAL_COMPONENT_CACHE_STATE_CREATED); g_static_rw_lock_writer_lock(&cb->priv->cache_lock); retval = e_cal_backend_cache_put_timezone(cache, zone); g_static_rw_lock_writer_unlock(&cb->priv->cache_lock); return retval; }
void pattern_db_expire_state(PatternDB *self) { PDBProcessParams process_params_p = {0}; PDBProcessParams *process_params = &process_params_p; g_static_rw_lock_writer_lock(&self->lock); self->timer_process_params = process_params; timer_wheel_expire_all(self->timer_wheel); self->timer_process_params = NULL; g_static_rw_lock_writer_unlock(&self->lock); _flush_emitted_messages(self, process_params); }
/** * clientmgr_insert_client_by_mac: * @mac : mac 地址 * @client : #Client 客户 * * 加入一个客户到管理列队。此后将能通过 clientmgr_get_client_by_ip() * clientmgr_get_client_by_mac() 找到他 */ void clientmgr_insert_client_by_mac(guchar * mac, Client * client) { g_static_rw_lock_writer_lock(&lock); Client* old = clientmgr_get_client_by_mac_internal(mac); if(old) clientmgr_reomve_client_internal(old); guchar * mac_ = g_memdup(mac,6); g_tree_insert(client_tree, mac_, client); g_static_rw_lock_writer_unlock(&lock); }
static gpointer sessions_cleaner_func(xr_server* server) { while (g_socket_service_is_active(G_SOCKET_SERVICE(server->service))) { server->current_time = time(NULL); g_static_rw_lock_writer_lock(&server->sessions_lock); g_hash_table_foreach_remove(server->sessions, _maybe_remove_servlet, server); g_static_rw_lock_writer_unlock(&server->sessions_lock); g_usleep(1000000); } return NULL; }
static gpointer test_g_static_rw_lock_thread (gpointer data) { while (test_g_static_rw_lock_run) { if (g_random_double() > .2) /* I'm a reader */ { if (g_random_double() > .2) /* I'll block */ g_static_rw_lock_reader_lock (&test_g_static_rw_lock_lock); else /* I'll only try */ if (!g_static_rw_lock_reader_trylock (&test_g_static_rw_lock_lock)) continue; G_LOCK (test_g_static_rw_lock_state); g_assert (test_g_static_rw_lock_state >= 0); test_g_static_rw_lock_state++; G_UNLOCK (test_g_static_rw_lock_state); g_usleep (g_random_int_range (20,1000)); G_LOCK (test_g_static_rw_lock_state); test_g_static_rw_lock_state--; G_UNLOCK (test_g_static_rw_lock_state); g_static_rw_lock_reader_unlock (&test_g_static_rw_lock_lock); } else /* I'm a writer */ { if (g_random_double() > .2) /* I'll block */ g_static_rw_lock_writer_lock (&test_g_static_rw_lock_lock); else /* I'll only try */ if (!g_static_rw_lock_writer_trylock (&test_g_static_rw_lock_lock)) continue; G_LOCK (test_g_static_rw_lock_state); g_assert (test_g_static_rw_lock_state == 0); test_g_static_rw_lock_state = -1; G_UNLOCK (test_g_static_rw_lock_state); g_usleep (g_random_int_range (20,1000)); G_LOCK (test_g_static_rw_lock_state); test_g_static_rw_lock_state = 0; G_UNLOCK (test_g_static_rw_lock_state); g_static_rw_lock_writer_unlock (&test_g_static_rw_lock_lock); } } return NULL; }
/** * pka_subscription_add_channel: * @subscription: A #PkaSubscription. * @context: A #PkaContext. * @channel: A #PkaChannel. * @error: A location for a #GError, or %NULL. * * Adds @channel and all of its sources to @subscription. Any new sources * added to @channel will be automatically added to @subscription. * * Returns: %TRUE if successful; otherwise %FALSE and @error is set. * Side effects: None. */ gboolean pka_subscription_add_channel (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaChannel *channel, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; GList *sources = NULL; GList *iter; gint *key; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); g_return_val_if_fail(PKA_IS_CHANNEL(channel), FALSE); ENTRY; if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Not authorized to add channel."); GOTO(failed); } key = g_new(gint, 1); *key = pka_channel_get_id(channel); g_static_rw_lock_writer_lock(&subscription->rw_lock); g_tree_insert(subscription->channels, key, g_object_ref(channel)); g_static_rw_lock_writer_unlock(&subscription->rw_lock); g_signal_connect(channel, "source-added", G_CALLBACK(pka_subscription_channel_source_added), subscription); g_signal_connect(channel, "source-removed", G_CALLBACK(pka_subscription_channel_source_removed), subscription); sources = pka_channel_get_sources(channel); for (iter = sources; iter; iter = iter->next) { if (!pka_subscription_add_source(subscription, context, iter->data, NULL)) { WARNING(Subscription, "Failed to add source %d to subscription %d.", pka_source_get_id(iter->data), subscription->id); } } g_list_foreach(sources, (GFunc)g_object_unref, NULL); g_list_free(sources); ret = TRUE; failed: RETURN(ret); }
void on_icon_theme_changed( GtkIconTheme *icon_theme, gpointer user_data ) { /* reload_mime_icons */ g_static_rw_lock_writer_lock( &mime_hash_lock ); g_hash_table_foreach( mime_hash, free_cached_icons, GINT_TO_POINTER( 1 ) ); g_hash_table_foreach( mime_hash, free_cached_icons, GINT_TO_POINTER( 0 ) ); g_static_rw_lock_writer_unlock( &mime_hash_lock ); }
void pattern_db_advance_time(PatternDB *self, gint timeout) { PDBProcessParams process_params_p = {0}; PDBProcessParams *process_params = &process_params_p; time_t new_time; g_static_rw_lock_writer_lock(&self->lock); new_time = timer_wheel_get_time(self->timer_wheel) + timeout; self->timer_process_params = process_params; timer_wheel_set_time(self->timer_wheel, new_time); self->timer_process_params = NULL; g_static_rw_lock_writer_unlock(&self->lock); _flush_emitted_messages(self, process_params); }
/** * pka_subscription_remove_channel: * @subscription: A #PkaSubscription. * @context: A #PkaContext. * @channel: A #PkaChannel. * @error: A location #GError, or %NULL. * * Removes a channel and all of its sources from being monitored by the * subscription. * * Returns: %TRUE if successful; otherwise %FALSE and @error is set. * Side effects: None. */ gboolean pka_subscription_remove_channel (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaChannel *channel, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; GList *sources = NULL; GList *iter; gint key; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); g_return_val_if_fail(PKA_IS_CHANNEL(channel), FALSE); ENTRY; if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Not authorized to remove channel %d from subscription %d.", pka_channel_get_id(channel), subscription->id); GOTO(failed); } g_signal_handlers_disconnect_by_func(channel, pka_subscription_channel_source_added, subscription); g_signal_handlers_disconnect_by_func(channel, pka_subscription_channel_source_removed, subscription); sources = pka_channel_get_sources(channel); for (iter = sources; iter; iter = iter->next) { if (!pka_subscription_remove_source(subscription, context, iter->data, NULL)) { WARNING(Subscription, "Could not remove source %d from subscription %d", pka_source_get_id(iter->data), subscription->id); } } g_list_foreach(sources, (GFunc)g_object_unref, NULL); g_list_free(sources); key = pka_channel_get_id(channel); g_static_rw_lock_writer_lock(&subscription->rw_lock); g_tree_remove(subscription->channels, &key); g_static_rw_lock_writer_unlock(&subscription->rw_lock); ret = TRUE; failed: RETURN(ret); }
/** * pka_subscription_set_state: * @subscription: A #PkaSubscription. * * Sets the current #PkaSubscriptionState of the subscription. * * Returns: None. * Side effects: None. */ gboolean pka_subscription_set_state (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaSubscriptionState state, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); ENTRY; if ((state != PKA_SUBSCRIPTION_MUTED) && (state != PKA_SUBSCRIPTION_UNMUTED)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Invalid state [0x%08x].", state); GOTO(failed); } if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Cannot set state to 0x%08x.", (gint)state); GOTO(failed); } g_static_rw_lock_writer_lock(&subscription->rw_lock); if (subscription->state == state) { GOTO(finished); } subscription->state = state; switch (state) { CASE(PKA_SUBSCRIPTION_UNMUTED); /* * TODO: Send the current manifests to the handler. */ BREAK; CASE(PKA_SUBSCRIPTION_MUTED); BREAK; default: g_warn_if_reached(); BREAK; } finished: g_static_rw_lock_writer_unlock(&subscription->rw_lock); ret = TRUE; failed: RETURN(ret); }
VFSMimeType* vfs_mime_type_get_from_type( const char* type ) { VFSMimeType * mime_type; g_static_rw_lock_reader_lock( &mime_hash_lock ); mime_type = g_hash_table_lookup( mime_hash, type ); g_static_rw_lock_reader_unlock( &mime_hash_lock ); if ( !mime_type ) { mime_type = vfs_mime_type_new( type ); g_static_rw_lock_writer_lock( &mime_hash_lock ); g_hash_table_insert( mime_hash, mime_type->type, mime_type ); g_static_rw_lock_writer_unlock( &mime_hash_lock ); } vfs_mime_type_ref( mime_type ); return mime_type; }
/** * pka_subscription_set_handlers: * @subscription: A #PkaSubscription. * @context: A #PkaContext. * @manifest_func: A manifest callback function. * @manifest_data: Data for @manifest_func. * @manifest_destroy: A #GDestroyNotify to call when @manifest_func is no * longer needed. * @sample_func: A sample callback function. * @sample_data: Data for @sample_func. * @sample_destroy: A #GDestroyNotify to call when @sample_func is no * longer needed. * * Sets the manifest and sample callback methods for the subscription. * @manifest_func will be called when a manifest is received from a source * on the subscription. @sample_func will be called when a sample is received * from the subscription. * * Returns: None. * Side effects: None. */ void pka_subscription_set_handlers (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaManifestFunc manifest_func, /* IN */ gpointer manifest_data, /* IN */ GDestroyNotify manifest_destroy, /* IN */ PkaSampleFunc sample_func, /* IN */ gpointer sample_data, /* IN */ GDestroyNotify sample_destroy, /* IN */ GError **error) /* IN */ { GClosure *manifest; GClosure *sample; g_return_if_fail(subscription != NULL); g_return_if_fail(context != NULL); ENTRY; /* * Create the closures and set the marshaller. */ manifest = g_cclosure_new(G_CALLBACK(manifest_func), manifest_data, (GClosureNotify)manifest_destroy); sample = g_cclosure_new(G_CALLBACK(sample_func), sample_data, (GClosureNotify)sample_destroy); g_closure_set_marshal(manifest, pka_marshal_VOID__POINTER_ULONG); g_closure_set_marshal(sample, pka_marshal_VOID__POINTER_ULONG); /* * Store the closures. Requires writer lock. */ g_static_rw_lock_writer_lock(&subscription->rw_lock); if (subscription->manifest_closure) { g_closure_unref(subscription->manifest_closure); } if (subscription->sample_closure) { g_closure_unref(subscription->sample_closure); } subscription->manifest_closure = manifest; subscription->sample_closure = sample; g_static_rw_lock_writer_unlock(&subscription->rw_lock); EXIT; }
void fs_rtp_sub_stream_stop (FsRtpSubStream *substream) { substream->priv->stopped = TRUE; g_static_rw_lock_writer_lock (&substream->priv->stopped_lock); substream->priv->stopped = TRUE; g_static_rw_lock_writer_unlock (&substream->priv->stopped_lock); if (substream->priv->rtpbin_unlinked_sig) { g_signal_handler_disconnect (substream->priv->rtpbin_pad, substream->priv->rtpbin_unlinked_sig); substream->priv->rtpbin_unlinked_sig = 0; } gst_pad_set_blocked_async (substream->priv->rtpbin_pad, FALSE, do_nothing_blocked_callback, NULL); if (substream->priv->output_ghostpad) gst_pad_set_active (substream->priv->output_ghostpad, FALSE); if (substream->priv->output_valve) { gst_element_set_locked_state (substream->priv->output_valve, TRUE); gst_element_set_state (substream->priv->output_valve, GST_STATE_NULL); } if (substream->priv->codecbin) { gst_element_set_locked_state (substream->priv->codecbin, TRUE); gst_element_set_state (substream->priv->codecbin, GST_STATE_NULL); } if (substream->priv->capsfilter) { gst_element_set_locked_state (substream->priv->capsfilter, TRUE); gst_element_set_state (substream->priv->capsfilter, GST_STATE_NULL); } if (substream->priv->input_valve) { gst_element_set_locked_state (substream->priv->input_valve, TRUE); gst_element_set_state (substream->priv->input_valve, GST_STATE_NULL); } }
gboolean pattern_db_reload_ruleset(PatternDB *self, GlobalConfig *cfg, const gchar *pdb_file) { PDBRuleSet *new_ruleset; new_ruleset = pdb_rule_set_new(); if (!pdb_rule_set_load(new_ruleset, cfg, pdb_file, NULL)) { pdb_rule_set_free(new_ruleset); return FALSE; } else { g_static_rw_lock_writer_lock(&self->lock); if (self->ruleset) pdb_rule_set_free(self->ruleset); self->ruleset = new_ruleset; g_static_rw_lock_writer_unlock(&self->lock); return TRUE; } }
void vfs_mime_type_set_icon_size( int big, int small ) { g_static_rw_lock_writer_lock( &mime_hash_lock ); if ( big != big_icon_size ) { big_icon_size = big; /* Unload old cached icons */ g_hash_table_foreach( mime_hash, free_cached_icons, GINT_TO_POINTER( 1 ) ); } if ( small != small_icon_size ) { small_icon_size = small; /* Unload old cached icons */ g_hash_table_foreach( mime_hash, free_cached_icons, GINT_TO_POINTER( 0 ) ); } g_static_rw_lock_writer_unlock( &mime_hash_lock ); }
/** * clientmgr_get_client_by_ip: * @ip : 客户的ip地址 * Returns: #Client , NULL 没有找到 * 通过给定的 @ip 地址寻找拥有此@ip地址的客户 */ Client * clientmgr_get_client_by_ip(in_addr_t ip) { Client * ret = NULL; gboolean findval_func(gpointer key,gpointer val, gpointer user_data) { if(((Client*)val)->ip == ip) { ret = val ; return TRUE; } return FALSE; } g_static_rw_lock_writer_lock(&lock); g_tree_foreach(client_tree,findval_func,&ret); g_static_rw_lock_writer_unlock(&lock); return ret; }
/** * pka_subscription_add_source: * @subscription: A #PkaSubscription. * @context: A #PkaContext. * @source: A #PkaSource. * @error: A location for a #GError, or %NULL. * * Adds @source to the list of #PkaSource<!-- -->'s monitored by * @subscription. * * Returns: %TRUE if successful; otherwise %FALSE. * Side effects: None. */ gboolean pka_subscription_add_source (PkaSubscription *subscription, /* IN */ PkaContext *context, /* IN */ PkaSource *source, /* IN */ GError **error) /* OUT */ { gboolean ret = FALSE; gint *key; g_return_val_if_fail(subscription != NULL, FALSE); g_return_val_if_fail(context != NULL, FALSE); g_return_val_if_fail(PKA_IS_SOURCE(source), FALSE); ENTRY; if (!IS_AUTHORIZED(context, MODIFY_SUBSCRIPTION, subscription)) { g_set_error(error, PKA_CONTEXT_ERROR, PKA_CONTEXT_ERROR_NOT_AUTHORIZED, "Not authoraized to remove source %d from subscription %d.", pka_source_get_id(source), subscription->id); GOTO(failed); } g_static_rw_lock_writer_lock(&subscription->rw_lock); key = g_new(gint, 1); *key = pka_source_get_id(source); g_tree_insert(subscription->sources, key, g_object_ref(source)); g_static_rw_lock_writer_unlock(&subscription->rw_lock); /* * The source will notify us of the current manifest if necessary. Such * an example would be if a source is already running and the source is * added to the subscription. * * Therefore, this should be done outside of any subscription locks. */ pka_source_add_subscription(source, subscription); ret = TRUE; failed: RETURN(ret); }
/* * This function can be called any time when pattern-db is not processing * messages, but we expect the correllation timer to move forward. It * doesn't need to be called absolutely regularly as it'll use the current * system time to determine how much time has passed since the last * invocation. See the timing comment at pattern_db_process() for more * information. */ void pattern_db_timer_tick(PatternDB *self) { GTimeVal now; glong diff; PDBProcessParams process_params_p = {0}; PDBProcessParams *process_params = &process_params_p; g_static_rw_lock_writer_lock(&self->lock); self->timer_process_params = process_params; cached_g_current_time(&now); diff = g_time_val_diff(&now, &self->last_tick); if (diff > 1e6) { glong diff_sec = (glong) (diff / 1e6); timer_wheel_set_time(self->timer_wheel, timer_wheel_get_time(self->timer_wheel) + diff_sec); msg_debug("Advancing patterndb current time because of timer tick", evt_tag_long("utc", timer_wheel_get_time(self->timer_wheel))); /* update last_tick, take the fraction of the seconds not calculated into this update into account */ self->last_tick = now; g_time_val_add(&self->last_tick, - (glong)(diff - diff_sec * 1e6)); } else if (diff < 0) { /* time moving backwards, this can only happen if the computer's time * is changed. We don't update patterndb's idea of the time now, wait * another tick instead to update that instead. */ self->last_tick = now; } self->timer_process_params = NULL; g_static_rw_lock_writer_unlock(&self->lock); _flush_emitted_messages(self, process_params); }
/** Sync new timezones from the cache to the server. * * Assumes caller opened connection using e_cal_backend_3e_open_connection(). * * @param cb 3E calendar backend. * * @return TRUE on success. */ static gboolean sync_timezones_to_server(ECalBackend3e *cb) { GError *local_err = NULL; GSList *timezones, *iter; timezones = e_cal_backend_cache_get_timezones(cb, cb->priv->cache); for (iter = timezones; iter; iter = iter->next) { icaltimezone *zone = iter->data; icalcomponent *zone_comp = icaltimezone_get_component(zone); ECalComponentCacheState state = icalcomponent_get_cache_state(zone_comp); icalcomponent_set_cache_state(zone_comp, E_CAL_COMPONENT_CACHE_STATE_NONE); char *object = icalcomponent_as_ical_string(zone_comp); //XXX: always try to add all timezones from the cache //if (state == E_CAL_COMPONENT_CACHE_STATE_CREATED) { ESClient_addObject(cb->priv->conn, cb->priv->calspec, object, &local_err); if (local_err) { g_clear_error(&local_err); break; } g_static_rw_lock_writer_lock(&cb->priv->cache_lock); e_cal_backend_cache_put_timezone(cb->priv->cache, zone); g_static_rw_lock_writer_unlock(&cb->priv->cache_lock); } icaltimezone_free(zone, 1); } g_slist_free(timezones); return TRUE; }