Use g_timeout_add_seconds() to reduce wakeups

(and refine the older glib compat mechanism, by Dan)
This commit is contained in:
Jan Kantert
2008-12-31 18:57:36 -05:00
committed by Dan Williams
parent 64af880fd7
commit 4ca66db721
22 changed files with 115 additions and 54 deletions

View File

@@ -36,6 +36,7 @@
#include <dbus/dbus-glib.h>
#include <NetworkManager.h>
#include "nm-glib-compat.h"
#include <libnm-util/nm-connection.h>
#include <libnm-util/nm-setting-ip4-config.h>
#include <libnm-util/nm-setting-connection.h>
@@ -486,7 +487,7 @@ nm_dispatcher_action (Handler *h,
if (d->quit_timeout)
g_source_remove (d->quit_timeout);
if (!d->persist)
d->quit_timeout = g_timeout_add (10000, quit_timeout_cb, NULL);
d->quit_timeout = g_timeout_add_seconds (10, quit_timeout_cb, NULL);
connection = nm_connection_new_from_hash (connection_hash, error);
if (connection) {
@@ -780,7 +781,7 @@ main (int argc, char **argv)
G_OBJECT (d->handler));
if (!persist)
d->quit_timeout = g_timeout_add (10000, quit_timeout_cb, NULL);
d->quit_timeout = g_timeout_add_seconds (10, quit_timeout_cb, NULL);
g_main_loop_run (loop);

View File

@@ -71,7 +71,11 @@ _im_add (inotify_sub *sub)
if (!scan_missing_running)
{
scan_missing_running = TRUE;
#if !GLIB_CHECK_VERSION(2,14,0)
g_timeout_add (SCAN_MISSING_TIME * G_USEC_PER_SEC, im_scan_missing, NULL);
#else
g_timeout_add_seconds (SCAN_MISSING_TIME, im_scan_missing, NULL);
#endif
}
}

View File

@@ -2,7 +2,8 @@ EXTRA_DIST = \
NetworkManager.h \
NetworkManagerVPN.h \
wireless-helper.h \
nm-dbus-glib-types.h
nm-dbus-glib-types.h \
nm-glib-compat.h
NetworkManagerincludedir=$(includedir)/NetworkManager

37
include/nm-glib-compat.h Normal file
View File

@@ -0,0 +1,37 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Red Hat, Inc.
*/
#ifndef NM_GLIB_COMPAT_H
#define NM_GLIB_COMPAT_H
#include <glib.h>
#if !GLIB_CHECK_VERSION(2,14,0)
#define g_timeout_add_seconds(i, f, d) \
g_timeout_add (i * G_USEC_PER_SEC, f, d)
#define g_timeout_add_seconds_full(p, i, f, d, n) \
g_timeout_add_full (p, i * G_USEC_PER_SEC, f, d, n)
#endif /* !GLIB_CHECK_VERSION(2,14,0) */
#endif /* NM_GLIB_COMPAT_H */

View File

@@ -22,6 +22,7 @@
*/
#include <signal.h>
#include "nm-glib-compat.h"
#include "nm-vpn-plugin.h"
#include "nm-utils.h"
#include "nm-connection.h"
@@ -49,8 +50,8 @@ static gboolean impl_vpn_plugin_set_failure (NMVPNPlugin *plugin,
#include "nm-vpn-plugin-glue.h"
#define NM_VPN_PLUGIN_CONNECT_TIMER 60000
#define NM_VPN_PLUGIN_QUIT_TIMER 20000
#define NM_VPN_PLUGIN_CONNECT_TIMER 60
#define NM_VPN_PLUGIN_QUIT_TIMER 20
G_DEFINE_ABSTRACT_TYPE (NMVPNPlugin, nm_vpn_plugin, G_TYPE_OBJECT)
@@ -680,18 +681,18 @@ state_changed (NMVPNPlugin *plugin, NMVPNServiceState state)
}
/* Add a timer to make sure we do not wait indefinitely for the successful connect. */
priv->connect_timer = g_timeout_add_full (G_PRIORITY_DEFAULT,
NM_VPN_PLUGIN_CONNECT_TIMER,
connect_timer_expired,
plugin,
connect_timer_removed);
priv->connect_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
NM_VPN_PLUGIN_CONNECT_TIMER,
connect_timer_expired,
plugin,
connect_timer_removed);
break;
case NM_VPN_SERVICE_STATE_STOPPED:
priv->quit_timer = g_timeout_add_full (G_PRIORITY_DEFAULT,
NM_VPN_PLUGIN_QUIT_TIMER,
quit_timer_expired,
plugin,
quit_timer_removed);
priv->quit_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
NM_VPN_PLUGIN_QUIT_TIMER,
quit_timer_expired,
plugin,
quit_timer_removed);
break;
default:
/* Clean up all timers we might have set up. */

View File

@@ -41,6 +41,7 @@
#include "nm-utils.h"
#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#define NM_DHCP_CLIENT_DBUS_SERVICE "org.freedesktop.nm_dhcp_client"
#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
@@ -603,9 +604,9 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
timeout = NM_DHCP_TIMEOUT;
/* Set up a timeout on the transaction to kill it after the timeout */
device->timeout_id = g_timeout_add (timeout * 1000,
nm_dhcp_manager_handle_timeout,
device);
device->timeout_id = g_timeout_add_seconds (timeout,
nm_dhcp_manager_handle_timeout,
device);
nm_dhcp_client_start (device, s_ip4);
device->watch_id = g_child_watch_add (device->pid,

View File

@@ -28,6 +28,7 @@
#include "nm-dnsmasq-manager.h"
#include "nm-utils.h"
#include "nm-glib-compat.h"
typedef struct {
char *iface;
@@ -450,7 +451,7 @@ nm_dnsmasq_manager_stop (NMDnsMasqManager *manager)
if (priv->pid) {
if (kill (priv->pid, SIGTERM) == 0)
g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
else {
kill (priv->pid, SIGKILL);

View File

@@ -23,6 +23,7 @@
#include "NetworkManager.h"
#include "nm-dbus-manager.h"
#include "nm-marshal.h"
#include "nm-glib-compat.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
@@ -158,7 +159,7 @@ static void
start_reconnection_timeout (NMDBusManager *self)
{
/* Schedule timeout for reconnection attempts */
g_timeout_add (3000, nm_dbus_manager_reconnect, self);
g_timeout_add_seconds (3, nm_dbus_manager_reconnect, self);
}
char *

View File

@@ -34,6 +34,7 @@
#include <net/if.h>
#include <errno.h>
#include "nm-glib-compat.h"
#include "nm-device-ethernet.h"
#include "nm-device-interface.h"
#include "nm-device-private.h"
@@ -991,7 +992,7 @@ supplicant_iface_connection_state_cb_handler (gpointer user_data)
/* Start the link timeout so we allow some time for reauthentication */
if (!priv->link_timeout_id)
priv->link_timeout_id = g_timeout_add (15000, link_timeout_cb, dev);
priv->link_timeout_id = g_timeout_add_seconds (15, link_timeout_cb, dev);
}
}
@@ -1156,7 +1157,7 @@ supplicant_interface_init (NMDeviceEthernet *self)
self);
/* Set up a timeout on the connection attempt to fail it after 25 seconds */
priv->supplicant.con_timeout_id = g_timeout_add (25000, supplicant_connection_timeout_cb, self);
priv->supplicant.con_timeout_id = g_timeout_add_seconds (25, supplicant_connection_timeout_cb, self);
return TRUE;
}

View File

@@ -31,6 +31,7 @@
#include <signal.h>
#include <unistd.h>
#include "nm-glib-compat.h"
#include "nm-device.h"
#include "nm-device-wifi.h"
#include "nm-device-interface.h"
@@ -910,7 +911,7 @@ real_bring_up (NMDevice *dev)
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
priv->periodic_source_id = g_timeout_add (6000, nm_device_wifi_periodic_update, self);
priv->periodic_source_id = g_timeout_add_seconds (6, nm_device_wifi_periodic_update, self);
return TRUE;
}
@@ -1717,9 +1718,9 @@ schedule_scan (NMDeviceWifi *self, gboolean backoff)
|| (nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED))
factor = 1;
priv->pending_scan_id = g_timeout_add (priv->scan_interval * 1000,
request_wireless_scan,
self);
priv->pending_scan_id = g_timeout_add_seconds (priv->scan_interval,
request_wireless_scan,
self);
priv->scheduled_scan_time = now.tv_sec + priv->scan_interval;
if (backoff && (priv->scan_interval < (SCAN_INTERVAL_MAX / factor))) {
@@ -2274,8 +2275,8 @@ supplicant_iface_connection_state_cb_handler (gpointer user_data)
* while to scan.
*/
if (!priv->link_timeout_id) {
priv->link_timeout_id = g_timeout_add (priv->scanning ? 30000 : 15000,
link_timeout_cb, self);
priv->link_timeout_id = g_timeout_add_seconds (priv->scanning ? 30 : 15,
link_timeout_cb, self);
}
}
}
@@ -2573,7 +2574,7 @@ start_supplicant_connection_timeout (NMDeviceWifi *self)
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
/* Set up a timeout on the connection attempt to fail it after 25 seconds */
id = g_timeout_add (25000, supplicant_connection_timeout_cb, self);
id = g_timeout_add_seconds (25, supplicant_connection_timeout_cb, self);
if (id <= 0) {
nm_warning ("Activation (%s/wireless): couldn't start supplicant "
"timeout timer.",

View File

@@ -34,6 +34,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include "nm-glib-compat.h"
#include "nm-device-interface.h"
#include "nm-device.h"
#include "nm-device-private.h"
@@ -204,7 +205,7 @@ constructor (GType type,
* system settings service a chance to figure out whether the device is
* managed or not.
*/
priv->start_timer = g_timeout_add (4000, device_start, dev);
priv->start_timer = g_timeout_add_seconds (4, device_start, dev);
priv->initialized = TRUE;
return object;
@@ -830,7 +831,7 @@ aipd_exec (NMDevice *self, GError **error)
priv->aipd_watch = g_child_watch_add (priv->aipd_pid, aipd_watch_cb, self);
/* Start a timeout to bound the address attempt */
priv->aipd_timeout = g_timeout_add (20000, aipd_timeout_cb, self);
priv->aipd_timeout = g_timeout_add_seconds (20, aipd_timeout_cb, self);
return TRUE;
}

View File

@@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include "nm-glib-compat.h"
#include "nm-gsm-device.h"
#include "nm-device-interface.h"
#include "nm-device-private.h"
@@ -354,7 +355,7 @@ schedule_automatic_registration_again (NMGsmDevice *self)
if (priv->pending_id)
g_source_remove (priv->pending_id);
priv->pending_id = g_timeout_add (1000, automatic_registration_again, self);
priv->pending_id = g_timeout_add_seconds (1, automatic_registration_again, self);
}
static void

View File

@@ -26,6 +26,7 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-glib-compat.h"
#include "nm-hal-manager.h"
#include "nm-marshal.h"
#include "nm-dbus-manager.h"
@@ -500,7 +501,7 @@ killswitch_getpower_done (gpointer user_data)
killswitch_poll_cleanup (self);
/* Schedule next poll */
priv->killswitch_poll_id = g_timeout_add (RFKILL_POLL_FREQUENCY * 1000,
priv->killswitch_poll_id = g_timeout_add_seconds (RFKILL_POLL_FREQUENCY,
poll_killswitches,
self);
}

View File

@@ -24,6 +24,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h>
#include "nm-glib-compat.h"
#include "nm-manager.h"
#include "nm-utils.h"
#include "nm-dbus-manager.h"
@@ -95,7 +96,7 @@ static void system_settings_properties_changed_cb (DBusGProxy *proxy,
GHashTable *properties,
gpointer user_data);
#define SSD_POKE_INTERVAL 120000
#define SSD_POKE_INTERVAL 120
typedef struct {
DBusGMethodInvocation *context;
@@ -1389,7 +1390,7 @@ poke_system_settings_daemon_cb (gpointer user_data)
out:
/* Reschedule the poke */
priv->poke_id = g_timeout_add (SSD_POKE_INTERVAL, poke_system_settings_daemon_cb, (gpointer) manager);
priv->poke_id = g_timeout_add_seconds (SSD_POKE_INTERVAL, poke_system_settings_daemon_cb, (gpointer) manager);
return FALSE;
}
@@ -2134,7 +2135,7 @@ impl_manager_activate_connection (NMManager *manager,
info->scope = scope;
info->connection_path = g_strdup (connection_path);
info->specific_object_path = g_strdup (real_sop);
info->timeout_id = g_timeout_add (5000, wait_for_connection_expired, manager);
info->timeout_id = g_timeout_add_seconds (5, wait_for_connection_expired, manager);
// FIXME: should probably be per-device, not global to the manager
NM_MANAGER_GET_PRIVATE (manager)->pending_connection_info = info;

View File

@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <glib.h>
#include "nm-glib-compat.h"
#include "nm-serial-device.h"
#include "nm-device-interface.h"
#include "nm-device-private.h"
@@ -285,11 +286,11 @@ nm_serial_device_add_timeout (NMSerialDevice *self, guint timeout)
g_source_remove (priv->timeout_id);
}
priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
timeout * 1000,
nm_serial_device_timed_out,
self,
nm_serial_device_timeout_removed);
priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
timeout,
nm_serial_device_timed_out,
self,
nm_serial_device_timeout_removed);
if (G_UNLIKELY (priv->timeout_id == 0))
nm_warning ("Registering serial device time out failed.");
}

View File

@@ -41,6 +41,7 @@
#include <linux/if_ppp.h>
#include "NetworkManager.h"
#include "nm-glib-compat.h"
#include "nm-ppp-manager.h"
#include "nm-setting-connection.h"
#include "nm-setting-ppp.h"
@@ -65,7 +66,7 @@ static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
#include "nm-ppp-manager-glue.h"
#define NM_PPPD_PLUGIN PLUGINDIR "/nm-pppd-plugin.so"
#define NM_PPP_WAIT_PPPD 15000 /* 10 seconds */
#define NM_PPP_WAIT_PPPD 15 /* 15 seconds */
#define PPP_MANAGER_SECRET_TRIES "ppp-manager-secret-tries"
typedef struct {
@@ -342,7 +343,7 @@ monitor_stats (NMPPPManager *manager)
priv->monitor_fd = socket (AF_INET, SOCK_DGRAM, 0);
if (priv->monitor_fd > 0)
priv->monitor_id = g_timeout_add (5000, monitor_cb, manager);
priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, manager);
else
nm_warning ("Could not open pppd monitor: %s", strerror (errno));
}
@@ -936,7 +937,7 @@ nm_ppp_manager_start (NMPPPManager *manager,
nm_debug ("ppp started with pid %d", priv->pid);
priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager);
priv->ppp_timeout_handler = g_timeout_add (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
priv->ppp_timeout_handler = g_timeout_add_seconds (NM_PPP_WAIT_PPPD, pppd_timed_out, manager);
priv->act_req = g_object_ref (req);
out:
@@ -1035,7 +1036,7 @@ nm_ppp_manager_stop (NMPPPManager *manager)
if (priv->pid) {
if (kill (priv->pid, SIGTERM) == 0)
g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
else {
kill (priv->pid, SIGKILL);

View File

@@ -31,6 +31,7 @@
#include "nm-dbus-manager.h"
#include "nm-call-store.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface"
#define WPAS_DBUS_IFACE_BSSID WPAS_DBUS_INTERFACE ".BSSID"
@@ -579,7 +580,7 @@ wpas_iface_query_scan_results (DBusGProxy *proxy, gpointer user_data)
return;
/* Only fetch scan results every 4s max, but initially do it right away */
priv->scan_results_timeout = g_timeout_add (priv->last_scan ? 4000 : 0,
priv->scan_results_timeout = g_timeout_add_seconds (priv->last_scan ? 4 : 0,
request_scan_results,
user_data);
}

View File

@@ -28,8 +28,9 @@
#include "nm-dbus-manager.h"
#include "nm-marshal.h"
#include "nm-utils.h"
#include "nm-glib-compat.h"
#define SUPPLICANT_POKE_INTERVAL 120000
#define SUPPLICANT_POKE_INTERVAL 120
typedef struct {
NMDBusManager * dbus_mgr;
@@ -106,7 +107,7 @@ poke_supplicant_cb (gpointer user_data)
out:
/* Reschedule the poke */
priv->poke_id = g_timeout_add (SUPPLICANT_POKE_INTERVAL,
priv->poke_id = g_timeout_add_seconds (SUPPLICANT_POKE_INTERVAL,
poke_supplicant_cb,
(gpointer) self);

View File

@@ -45,6 +45,7 @@
#include "NetworkManagerUtils.h"
#include "nm-named-manager.h"
#include "nm-netlink.h"
#include "nm-glib-compat.h"
#include "nm-vpn-connection-glue.h"
@@ -570,7 +571,7 @@ nm_vpn_connection_connect_cb (DBusGProxy *proxy, GError *err, gpointer user_data
NM_VPN_CONNECTION_STATE_REASON_NONE);
/* 40 second timeout waiting for IP config signal from VPN service */
priv->ipconfig_timeout = g_timeout_add (40000, nm_vpn_connection_ip_config_timeout, connection);
priv->ipconfig_timeout = g_timeout_add_seconds (40, nm_vpn_connection_ip_config_timeout, connection);
}
}

View File

@@ -31,6 +31,7 @@
#include "nm-dbus-manager.h"
#include "nm-utils.h"
#include "nm-vpn-manager.h"
#include "nm-glib-compat.h"
G_DEFINE_TYPE (NMVPNService, nm_vpn_service, G_TYPE_OBJECT)
@@ -249,7 +250,7 @@ nm_vpn_service_daemon_exec (NMVPNService *service, GError **error)
nm_vpn_service_get_name (service), priv->dbus_service, priv->pid);
priv->service_child_watch = g_child_watch_add (priv->pid, vpn_service_watch_cb, service);
priv->service_start_timeout = g_timeout_add (5000, nm_vpn_service_timeout, service);
priv->service_start_timeout = g_timeout_add_seconds (5, nm_vpn_service_timeout, service);
} else {
nm_warning ("VPN service '%s': could not launch the VPN service. error: (%d) %s.",
nm_vpn_service_get_name (service), spawn_error->code, spawn_error->message);
@@ -291,7 +292,7 @@ connection_vpn_state_changed (NMVPNConnection *connection,
if (priv->connections == NULL) {
/* schedule a timeout (10 seconds) to destroy the service */
g_timeout_add (10000, destroy_service, user_data);
g_timeout_add_seconds (10, destroy_service, user_data);
}
break;
default:
@@ -436,7 +437,7 @@ finalize (GObject *object)
if (priv->pid) {
if (kill (priv->pid, SIGTERM) == 0)
g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid));
g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
else {
kill (priv->pid, SIGKILL);

View File

@@ -43,6 +43,7 @@
#include <nm-settings.h>
#include <nm-utils.h>
#include <NetworkManager.h>
#include "nm-glib-compat.h"
#include "dbus-settings.h"
#include "nm-system-config-hal-manager.h"
@@ -426,7 +427,7 @@ device_added_cb (DBusGProxy *proxy, const char *udi, NMDeviceType devtype, gpoin
/* Wait for a plugin to figure out if the device should be managed or not */
info = g_malloc0 (sizeof (WiredDeviceInfo));
info->app = app;
info->add_id = g_timeout_add (4000, add_default_dhcp_connection, info);
info->add_id = g_timeout_add_seconds (4, add_default_dhcp_connection, info);
info->udi = g_strdup (udi);
g_hash_table_insert (app->wired_devices, info->udi, info);
}

View File

@@ -44,6 +44,7 @@
#include <dbus/dbus-glib.h>
#include "NetworkManager.h"
#include "nm-glib-compat.h"
typedef struct
{
@@ -200,7 +201,7 @@ int main (int argc, char *argv[])
if (timeout.value) {
timeout.norm = (double) timeout.value / (double) PROGRESS_STEPS;
g_timeout_add (1000, handle_timeout, &timeout);
g_timeout_add_seconds (1, handle_timeout, &timeout);
}
timeout.quiet = quiet;