base-modem: synchronize initialize/enable/disable/sync operations

Each of these now holds an exclusive lock, so all these operations are
synchronized.

This logic can be tested by queing different enable/disable operations
one after the other, e.g.:
  mmcli -m a -d &    --> Disable 1
  sleep 0.2
  mmcli -m a -e &    --> Enable 1
  sleep 0.2
  mmcli -m a -e &    --> Enable 2
  sleep 0.2
  mmcli -m a -d &    --> Disable 2
  sleep 0.2
  mmcli -m a -e &    --> Enable 3
  sleep 0.2
  mmcli -m a -d &    --> Disable 3

This previous sequence produces MM logs as follows:
  <dbg> [1726566352.936025] [modem0] [operation 9] default - disable:  scheduled     --> Disable 1 requested
  <dbg> [1726566352.936399] [modem0] [operation 9] default - disable:  lock acquired --> Disable 1 started
  <dbg> [1726566353.136445] [modem0] [operation 10] default - enable:  scheduled     --> Enable 1 requested
  <dbg> [1726566353.202980] [modem0] [operation 9] default - disable:  lock released --> Disable 1 finished
  <dbg> [1726566353.203526] [modem0] [operation 10] default - enable:  lock acquired --> Enable 1 started
  <dbg> [1726566353.320057] [modem0] [operation 11] default - enable:  scheduled     --> Enable 2 requested
  <dbg> [1726566353.440931] [modem0] [operation 10] default - enable:  lock released --> Enable 1 finished
  <dbg> [1726566353.443238] [modem0] [operation 11] default - enable:  lock acquired --> Enable 2 started
  <dbg> [1726566353.452984] [modem0] [operation 11] default - enable:  lock released --> Enable 2 finished
  <dbg> [1726566353.517512] [modem0] [operation 12] default - disable: scheduled     --> Disable 2 requested
  <dbg> [1726566353.517699] [modem0] [operation 12] default - disable: lock acquired --> Disable 2 started
  <dbg> [1726566353.688695] [modem0] [operation 12] default - disable: lock released --> Disable 2 finished
  <dbg> [1726566353.718237] [modem0] [operation 13] default - enable:  scheduled     --> Enable 3 requested
  <dbg> [1726566353.718417] [modem0] [operation 13] default - enable:  lock acquired --> Enable 3 started
  <dbg> [1726566353.937122] [modem0] [operation 14] default - disable: scheduled     --> Disable 3 requested
  <dbg> [1726566353.970791] [modem0] [operation 13] default - enable:  lock released --> Enable 3 finished
  <dbg> [1726566353.970964] [modem0] [operation 14] default - disable: lock acquired --> Disable 3 started
  <dbg> [1726566354.170938] [modem0] [operation 14] default - disable: lock released --> Disable 3 finished
This commit is contained in:
Aleksander Morgado
2024-09-30 07:55:05 +00:00
parent 8e0cbd9c94
commit be668462c0
7 changed files with 281 additions and 129 deletions
+10 -3
View File
@@ -961,7 +961,10 @@ foreach_disable (gpointer key,
ctx->low_power = foreach_ctx->low_power;
ctx->remove = foreach_ctx->remove;
mm_base_modem_disable (modem, (GAsyncReadyCallback)shutdown_disable_ready, ctx);
mm_base_modem_disable (modem,
MM_BASE_MODEM_OPERATION_LOCK_REQUIRED,
(GAsyncReadyCallback)shutdown_disable_ready,
ctx);
}
static gboolean
@@ -1067,8 +1070,12 @@ mm_base_manager_sync (MMBaseManager *self)
modem = mm_device_peek_modem (MM_DEVICE (value));
/* We just want to start the synchronization, we don't need the result */
if (modem)
mm_base_modem_sync (modem, (GAsyncReadyCallback)base_modem_sync_ready, NULL);
if (modem) {
mm_base_modem_sync (modem,
MM_BASE_MODEM_OPERATION_LOCK_REQUIRED,
(GAsyncReadyCallback)base_modem_sync_ready,
NULL);
}
}
}