static void wait_for_no_addresses (NMIP6Manager *self, NMIP6Device *device) { NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (self); guint64 now, end; gboolean has_addrs = TRUE; now = end = g_get_real_time (); end += (G_USEC_PER_SEC * 3); while (has_addrs && now < end) { struct rtnl_addr *rtnladdr; struct nl_addr *nladdr; nl_cache_refill (priv->nlh, priv->addr_cache); for (has_addrs = FALSE, rtnladdr = FIRST_ADDR (priv->addr_cache); rtnladdr; rtnladdr = NEXT_ADDR (rtnladdr)) { nladdr = rtnl_addr_get_local (rtnladdr); if ( rtnl_addr_get_ifindex (rtnladdr) == device->ifindex && nladdr && nl_addr_get_family (nladdr) == AF_INET6) { /* Still IPv6 addresses on the interface */ has_addrs = TRUE; nm_log_dbg (LOGD_IP6, "(%s) waiting for cleared IPv6 addresses", device->iface); g_usleep (100); now = g_get_real_time (); break; } } } }
GssTransaction * gss_transaction_new (GssServer * server, SoupServer * soupserver, SoupMessage * msg, const char *path, GHashTable * query, SoupClientContext * client) { GssTransaction *transaction; transaction = g_new0 (GssTransaction, 1); transaction->server = server; transaction->soupserver = soupserver; transaction->msg = msg; transaction->path = path; transaction->query = query; transaction->client = client; transaction->sync_process_time = -g_get_real_time (); transaction->total_time = -g_get_real_time (); g_signal_connect (msg, "wrote-headers", G_CALLBACK (gss_transaction_wrote_headers), transaction); g_signal_connect (msg, "finished", G_CALLBACK (gss_transaction_finished), transaction); g_object_weak_ref (G_OBJECT (msg), (GWeakNotify) (gss_transaction_finalize), transaction); return transaction; }
static void _mark_service_state(const gchar *ns_name, const gchar *srv_key, gboolean is_up) { struct namespace_data_s *ns_data; struct service_info_s *si; ns_data = g_hash_table_lookup(namespaces, ns_name); if (!ns_data) return; if (is_up) { si = g_hash_table_lookup(ns_data->local_services, srv_key); if (!si) { /*service was DOWN*/ si = g_hash_table_lookup(ns_data->down_services, srv_key); if (si && (si = service_info_dup(si))) { g_hash_table_remove(ns_data->down_services, srv_key); g_hash_table_insert(ns_data->local_services, g_strdup(srv_key), si); INFO("Service [%s/%s] now UP", ns_name, srv_key); } } else { si->score.timestamp = g_get_real_time() / 1000000; DEBUG("Service [%s/%s] still UP", ns_name, srv_key); } /*ensure the UP tag on TRUE*/ if (si) { service_tag_set_value_boolean(service_info_ensure_tag(si->tags,"tag.up"), TRUE); si->score.timestamp = g_get_real_time() / 1000000; } } else { si = g_hash_table_lookup(ns_data->down_services, srv_key); if (!si) { /*service was maybe UP*/ si = g_hash_table_lookup(ns_data->local_services, srv_key); if (si && (si = service_info_dup(si))) { g_hash_table_remove(ns_data->local_services, srv_key); g_hash_table_insert(ns_data->down_services, g_strdup(srv_key), si); si->score.value = -2; } INFO("Service [%s/%s] now DOWN", ns_name, srv_key); } else { DEBUG("Service [%s/%s] still DOWN", ns_name, srv_key); si->score.value = -2; } /*was it UP or not, we ensure it has ZERO stats and the right flags*/ if (si) { service_tag_set_value_boolean(service_info_ensure_tag(si->tags,"tag.up"), FALSE); zero_service_stats(si->tags); invalidate_conscience_service(ns_data, si); DEBUG("Service [%s/%s] zeroed, invalidated, marked down", ns_name, srv_key); } } }
void ocl_stub_create_event( cl_event* event, cl_command_queue queue, cl_command_type ctype) { if (event != NULL) { \ *event = g_slice_new0(struct _cl_event); (*event)->t_queued = g_get_real_time(); (*event)->t_submit = g_get_real_time(); (*event)->t_start = g_get_real_time(); (*event)->t_end = g_get_real_time(); (*event)->command_queue = queue; if (queue != NULL) (*event)->context = queue->context; (*event)->command_type = ctype; (*event)->exec_status = CL_COMPLETE; (*event)->ref_count = 1; }
int main(int argc, char **argv) { struct pg_error *error = NULL; struct pg_brick *nic, *app; struct pg_graph *graph; struct mydata pd; pd.pkt_count = 0; pg_start(argc, argv, &error); start_time = g_get_real_time(); if (pg_nic_port_count() < 1) { g_printf("No NIC port has been found, try adding --vdev=eth_pcap0,iface=eth0 arguments\n"); return 1; } nic = pg_nic_new_by_id("port 0", 0, &error); app = pg_rxtx_new("myapp", &rx_callback, &tx_callback, (void *) &pd); pg_brick_link(nic, app, &error); graph = pg_graph_new("example", nic, &error); while (42) if (pg_graph_poll(graph, &error) < 0) break; pg_error_print(error); pg_error_free(error); pg_graph_destroy(graph); pg_stop(); return 1; }
static void tx_callback(struct pg_brick *brick, struct pg_rxtx_packet *tx_burst, uint16_t *tx_burst_len, void *private_data) { static uint64_t pkt_count = 0; struct mydata *pd = (struct mydata *)private_data; if (pkt_count == pd->pkt_count) { *tx_burst_len = 0; return; } pkt_count = pd->pkt_count; uint64_t current_time = g_get_real_time(); /* set number of packet we would like to write. * maximal number of packets is PG_RXTX_MAX_TX_BURST_LEN */; *tx_burst_len = 1; /* write the first packets data */ *((uint64_t *)(tx_burst[0].data)) = pd->pkt_count / (current_time - start_time); /* set lenght of written packet */ *tx_burst[0].len = sizeof(uint64_t); printf("%lf packets/s\n", pd->pkt_count / ((current_time - start_time) / 1000000.)); }
static gboolean set_timestamp (GsPlugin *plugin, const gchar *type, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); char *error_msg = NULL; gint result; g_autofree gchar *statement = NULL; statement = g_strdup_printf ("INSERT OR REPLACE INTO timestamps (key, value) " "VALUES ('%s', '%" G_GINT64_FORMAT "');", type, g_get_real_time () / G_USEC_PER_SEC); result = sqlite3_exec (priv->db, statement, NULL, NULL, &error_msg); if (result != SQLITE_OK) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "SQL error: %s", error_msg); sqlite3_free (error_msg); return FALSE; } return TRUE; }
static gchar * ido_source_menu_item_time_span_string (gint64 timestamp) { gchar *str; gint64 span; gint hours; gint minutes; span = MAX (g_get_real_time () - timestamp, 0) / G_USEC_PER_SEC; hours = span / 3600; minutes = (span / 60) % 60; if (hours == 0) { /* TRANSLATORS: number of minutes that have passed */ str = g_strdup_printf (ngettext ("%d min", "%d min", minutes), minutes); } else { /* TRANSLATORS: number of hours that have passed */ str = g_strdup_printf (ngettext ("%d h", "%d h", hours), hours); } return str; }
/** * fu_provider_unlock: **/ gboolean fu_provider_unlock (FuProvider *provider, FuDevice *device, GError **error) { guint64 flags; FuProviderClass *klass = FU_PROVIDER_GET_CLASS (provider); /* final check */ flags = fu_device_get_flags (device); if ((flags & FU_DEVICE_FLAG_LOCKED) == 0) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED, "Device %s is not locked", fu_device_get_id (device)); return FALSE; } /* run provider method */ if (klass->unlock != NULL) { if (!klass->unlock (provider, device, error)) return FALSE; } /* update with correct flags */ flags = fu_device_get_flags (device); fu_device_set_flags (device, flags &= ~FU_DEVICE_FLAG_LOCKED); fu_device_set_modified (device, g_get_real_time () / G_USEC_PER_SEC); return TRUE; }
static void gss_transaction_wrote_headers (SoupMessage * msg, GssTransaction * t) { if (t->sync_process_time < 0) { t->sync_process_time += g_get_real_time (); } }
/** * Insert file into cache. One should have verified that the file * does not already exists in the database. * @todo Use statements to avoid bugs when dealing with strings from user * space and thus avoid sql injection a bit. See * https://sqlite.org/c3ref/prepare.html * @param database is the structure that contains everything that is * related to the database (it's connexion for instance). * @param meta is the file's metadata that we want to insert into the * cache. * @param only_meta : a gboolean that when set to TRUE only meta_data will * be saved and hashs data will not ! FALSE means that something * went wrong with server and that all data will be cached localy. */ void db_save_meta_data(db_t *database, meta_data_t *meta, gboolean only_meta) { guint64 cache_time = 0; gint result = 0; sqlite3_stmt *stmt = NULL; if (meta != NULL && database != NULL && database->stmts != NULL) { cache_time = g_get_real_time(); /* beginning a transaction */ sql_begin(database); /* Inserting the file into the files table */ stmt = database->stmts->save_meta_stmt; if (stmt != NULL) { bind_values_to_save_meta_data(database->db, stmt, meta, only_meta, cache_time); result = sqlite3_step(stmt); print_on_db_error(database->db, result, "sqlite3_step"); } /* ending the transaction here */ sql_commit(database); sqlite3_reset(stmt); } }
gint64 oio_ext_real_time (void) { if (oio_time_real) return (*oio_time_real)(); return g_get_real_time(); }
static void ready (void *hook_data, void *user_data) { cleanup_current_track(); Tuple *current_track = aud_playlist_entry_get_tuple(aud_playlist_get_playing(), aud_playlist_get_position(aud_playlist_get_playing()), FALSE); int duration_seconds = tuple_get_int(current_track, FIELD_LENGTH) / 1000; if (duration_seconds <= 30) { tuple_unref(current_track); return; } pthread_mutex_lock(&communication_mutex); now_playing_track = tuple_ref(current_track); now_playing_requested = TRUE; pthread_cond_signal(&communication_signal); pthread_mutex_unlock(&communication_mutex); time_until_scrobble = (((gint64)duration_seconds)*G_USEC_PER_SEC) / 2; if (time_until_scrobble > 4*60*G_USEC_PER_SEC) { time_until_scrobble = 4*60*G_USEC_PER_SEC; } timestamp = g_get_real_time() / G_USEC_PER_SEC; play_started_at = g_get_monotonic_time(); playing_track = current_track; queue_function_ID = g_timeout_add_seconds(time_until_scrobble / G_USEC_PER_SEC, (GSourceFunc) queue_track_to_scrobble, NULL); }
/** * g_cond_timed_wait: * @cond: a #GCond * @mutex: a #GMutex that is currently locked * @abs_time: a #GTimeVal, determining the final time * * Waits until this thread is woken up on @cond, but not longer than * until the time specified by @abs_time. The @mutex is unlocked before * falling asleep and locked again before resuming. * * If @abs_time is %NULL, g_cond_timed_wait() acts like g_cond_wait(). * * This function can be used even if g_thread_init() has not yet been * called, and, in that case, will immediately return %TRUE. * * To easily calculate @abs_time a combination of g_get_current_time() * and g_time_val_add() can be used. * * Returns: %TRUE if @cond was signalled, or %FALSE on timeout * * Deprecated:2.32: Use g_cond_wait_until() instead. */ gboolean g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time) { gint64 end_time; if (abs_time == NULL) { g_cond_wait (cond, mutex); return TRUE; } end_time = abs_time->tv_sec; end_time *= 1000000; end_time += abs_time->tv_usec; #ifdef CLOCK_MONOTONIC /* would be nice if we had clock_rtoffset, but that didn't seem to * make it into the kernel yet... */ end_time += g_get_monotonic_time () - g_get_real_time (); #else /* if CLOCK_MONOTONIC is not defined then g_get_montonic_time() and * g_get_real_time() are returning the same clock, so don't bother... */ #endif return g_cond_wait_until (cond, mutex, end_time); }
PhotosQuery * photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar *name) { GTimeVal tv; gchar *sparql; gchar *time; gint64 timestamp; timestamp = g_get_real_time () / G_USEC_PER_SEC; tv.tv_sec = timestamp; tv.tv_usec = 0; time = g_time_val_to_iso8601 (&tv); sparql = g_strdup_printf ("INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; " "nie:contentLastModified '%s' ; " "nie:title '%s' ; " "nao:identifier '%s%s' }", time, name, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER, name); g_free (time); return photos_query_new (state, sparql); }
/*static */ gboolean biji_note_obj_add_notebook (BijiItem *item, BijiItem *notebook, gchar *title) { BijiNoteObj *note; gchar *label = title; g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE); note = BIJI_NOTE_OBJ (item); if (BIJI_IS_NOTEBOOK (notebook)) label = (gchar*) biji_item_get_title (notebook); if (biji_note_obj_has_notebook (item, label)) return FALSE; g_hash_table_add (note->priv->labels, g_strdup (label)); if (BIJI_IS_NOTEBOOK (notebook)) { biji_push_existing_notebook_to_note ( note, label, _biji_notebook_refresh, notebook); // Tracker biji_note_id_set_last_metadata_change_date (note->priv->id, g_get_real_time () / G_USEC_PER_SEC); biji_note_obj_save_note (note); } return TRUE; }
void tuner_set_rotator(gpointer user_data) { gboolean cw = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.b_cw)); gboolean ccw = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.b_ccw)); gchar buffer[3]; gint state = GPOINTER_TO_INT(user_data); if(!cw && !ccw) { state = 0; } else if(state == 1) { if(ccw) { g_signal_handlers_block_by_func(G_OBJECT(ui.b_ccw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(2)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_ccw), FALSE); g_signal_handlers_unblock_by_func(G_OBJECT(ui.b_ccw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(2)); } } else if(state == 2) { if(cw) { g_signal_handlers_block_by_func(G_OBJECT(ui.b_cw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(1)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_cw), FALSE); g_signal_handlers_unblock_by_func(G_OBJECT(ui.b_cw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(1)); } } g_snprintf(buffer, sizeof(buffer), "C%d", state); tuner_write(tuner.thread, buffer); tuner.last_set_rotator = g_get_real_time() / 1000; }
/** * gs_plugin_fedora_tagger_set_timestamp: */ static gboolean gs_plugin_fedora_tagger_set_timestamp (GsPlugin *plugin, const gchar *type, GError **error) { char *error_msg = NULL; gint rc; _cleanup_free_ gchar *statement = NULL; /* insert the entry */ statement = g_strdup_printf ("INSERT OR REPLACE INTO timestamps (key, value) " "VALUES ('%s', '%" G_GINT64_FORMAT "');", type, g_get_real_time () / G_USEC_PER_SEC); rc = sqlite3_exec (plugin->priv->db, statement, NULL, NULL, &error_msg); if (rc != SQLITE_OK) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "SQL error: %s", error_msg); sqlite3_free (error_msg); return FALSE; } return TRUE; }
void tuner_set_squelch() { gchar buffer[5]; g_snprintf(buffer, sizeof(buffer), "Q%ld", lround(gtk_scale_button_get_value(GTK_SCALE_BUTTON(ui.squelch)))); tuner_write(tuner.thread, buffer); tuner.last_set_squelch = g_get_real_time() / 1000; }
void tuner_set_alignment() { gchar buffer[5]; g_snprintf(buffer, sizeof(buffer), "V%ld", lround(gtk_adjustment_get_value(GTK_ADJUSTMENT(ui.adj_align)))); tuner_write(tuner.thread, buffer); tuner.last_set_daa = g_get_real_time() / 1000; }
static void tray_check_hide (GtkWidget *menu) { if (tray_menu_inactivetime && g_get_real_time () - tray_menu_inactivetime >= 2000000) { tray_menu_destroy (menu, NULL); } }
void tuner_set_volume() { gchar buffer[5]; conf.volume = lround(gtk_scale_button_get_value(GTK_SCALE_BUTTON(ui.volume))); g_snprintf(buffer, sizeof(buffer), "Y%d", conf.volume); tuner_write(tuner.thread, buffer); tuner.last_set_volume = g_get_real_time() / 1000; }
void tuner_set_bandwidth() { gchar buffer[4]; g_snprintf(buffer, sizeof(buffer), "F%d", tuner_filter_from_index(gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_bw)))); tuner_write(tuner.thread, buffer); tuner.last_set_filter = g_get_real_time() / 1000; }
void tuner_set_deemphasis() { gchar buffer[3]; conf.deemphasis = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_deemph)); g_snprintf(buffer, sizeof(buffer), "D%d", conf.deemphasis); tuner_write(tuner.thread, buffer); tuner.last_set_deemph = g_get_real_time() / 1000; }
/// Initialize our session ID to something monotonically increasing. /// There are a couple of ways of achieving this... /// - One method is to store a sequence number in a file - but this has problems /// when you restore machines or if you can't create persistent files /// - Another method is to use the time of day - but if the clock gets set back /// to a time before the previous session id, then this doesn't work. /// - The best idea seems to be to use the time of day, but also store that /// value in a file. If the time gets set back before the previous session id, /// then use the previous session id + 1. /// /// Of course, this won't really work without taking into account /// the fact that we increment the session id by one each time we reset a connection. /// So, if you decide to do that, please look at _fsprotocol_fspe_reinit() /// and for good measure, look at _fsqueue_enq() too... /// FSTATIC void _seqnoframe_initsessionid(void) { # define FIVESECONDS 5000000 guint64 now = g_get_real_time(); now /= FIVESECONDS; /// @todo: cache this on disk and so on as described above... _sessionId = (guint32)now; }
void tuner_set_antenna() { gchar buffer[3]; gint antenna = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_ant)); g_snprintf(buffer, sizeof(buffer), "Z%d", (antenna >=0 ? antenna : 0)); tuner_write(tuner.thread, buffer); tuner.last_set_ant = g_get_real_time() / 1000; }
void tuner_set_agc() { gchar buffer[3]; conf.agc = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_agc)); g_snprintf(buffer, sizeof(buffer), "A%d", conf.agc); tuner_write(tuner.thread, buffer); tuner.last_set_agc = g_get_real_time() / 1000; }
/** * fu_provider_device_add: **/ void fu_provider_device_add (FuProvider *provider, FuDevice *device) { g_debug ("emit added from %s: %s", fu_provider_get_name (provider), fu_device_get_id (device)); fu_device_set_created (device, g_get_real_time () / G_USEC_PER_SEC); fu_device_set_provider (device, fu_provider_get_name (provider)); g_signal_emit (provider, signals[SIGNAL_DEVICE_ADDED], 0, device); }
void tuner_set_gain() { gchar buffer[4]; conf.rfgain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.x_rf)); conf.ifgain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.x_if)); g_snprintf(buffer, sizeof(buffer), "G%02d", conf.rfgain * 10 + conf.ifgain); tuner_write(tuner.thread, buffer); tuner.last_set_gain = g_get_real_time() / 1000; }
static GIOChannel * _open_tmp_file(gchar ** tmp_file_name) { GIOChannel * result; *tmp_file_name = g_strdup_printf("%s/segments_%lu", repo_path, g_get_real_time()); result = g_io_channel_new_file(*tmp_file_name, "w", null_ptr); return result; }