Commit 3a907377 authored by Thomas Haller's avatar Thomas Haller

core: track NMActiveConnection in manager with CList

Using CList, we embed the list element in NMActiveConnection struct
itself. That means for example, that you couldn't track a
NMActiveConnection more then once. But we anyway never want that.

The advantage is, that removing an active connection from the list
is O(1), and we safe additional GSlice allocations for each node
element.
parent 51531c95
......@@ -1289,6 +1289,8 @@ nm_active_connection_init (NMActiveConnection *self)
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate);
self->_priv = priv;
c_list_init (&self->active_connections_lst);
_LOGT ("creating");
priv->activation_type = NM_ACTIVATION_TYPE_MANAGED;
......@@ -1331,6 +1333,8 @@ dispose (GObject *object)
NMActiveConnection *self = NM_ACTIVE_CONNECTION (object);
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
nm_assert (!c_list_is_linked (&self->active_connections_lst));
_LOGD ("disposing");
if (priv->chain) {
......
......@@ -24,6 +24,8 @@
#include "nm-exported-object.h"
#include "nm-connection.h"
#include "nm-utils/c-list.h"
#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ())
#define NM_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnection))
#define NM_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
......@@ -71,6 +73,10 @@ struct _NMActiveConnectionPrivate;
struct _NMActiveConnection {
NMExportedObject parent;
struct _NMActiveConnectionPrivate *_priv;
/* active connection can be tracked in a list by NMManager. This is
* the list node. */
CList active_connections_lst;
};
typedef struct {
......
......@@ -125,10 +125,10 @@ find_settings_connection (NMCheckpoint *self,
gboolean *need_activation)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self);
const GSList *active_connections, *iter;
NMActiveConnection *active = NULL;
NMActiveConnection *active;
NMSettingsConnection *connection;
const char *uuid, *ac_uuid;
const CList *tmp_clist;
*need_activation = FALSE;
*need_update = FALSE;
......@@ -149,9 +149,7 @@ find_settings_connection (NMCheckpoint *self,
}
/* ... is active, ... */
active_connections = nm_manager_get_active_connections (priv->manager);
for (iter = active_connections; iter; iter = g_slist_next (iter)) {
active = iter->data;
nm_manager_for_each_active_connection (priv->manager, active, tmp_clist) {
ac_uuid = nm_settings_connection_get_uuid (nm_active_connection_get_settings_connection (active));
if (nm_streq (uuid, ac_uuid)) {
_LOGT ("rollback: connection %s is active", uuid);
......@@ -159,7 +157,7 @@ find_settings_connection (NMCheckpoint *self,
}
}
if (!iter) {
if (!active) {
_LOGT ("rollback: connection %s is not active", uuid);
*need_activation = TRUE;
return connection;
......
This diff is collapsed.
......@@ -24,6 +24,7 @@
#include "nm-exported-object.h"
#include "settings/nm-settings-connection.h"
#include "nm-utils/c-list.h"
#define NM_TYPE_MANAGER (nm_manager_get_type ())
#define NM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MANAGER, NMManager))
......@@ -85,7 +86,19 @@ gboolean nm_manager_start (NMManager *manager,
GError **error);
void nm_manager_stop (NMManager *manager);
NMState nm_manager_get_state (NMManager *manager);
const GSList *nm_manager_get_active_connections (NMManager *manager);
const CList * nm_manager_get_active_connections (NMManager *manager);
#define nm_manager_for_each_active_connection(manager, iter, tmp_list) \
for (tmp_list = nm_manager_get_active_connections (manager), \
iter = c_list_entry (tmp_list->next, NMActiveConnection, active_connections_lst); \
({ \
gboolean _has_next = (&iter->active_connections_lst != tmp_list); \
\
if (!_has_next) \
iter = NULL; \
_has_next; \
}); \
iter = c_list_entry (iter->active_connections_lst.next, NMActiveConnection, active_connections_lst))
NMSettingsConnection **nm_manager_get_activatable_connections (NMManager *manager,
guint *out_len,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment