Commit 7b1fe6ec authored by Benjamin Berg's avatar Benjamin Berg
Browse files

ssm: Allow marking an SSM as being critical

This way the SSM cannot be interrupted while it is running.
parent 999bca07
......@@ -247,6 +247,7 @@ fpi_ssm_new_full
fpi_ssm_free
fpi_ssm_start
fpi_ssm_start_subsm
fpi_ssm_set_critical
fpi_ssm_next_state
fpi_ssm_next_state_delayed
fpi_ssm_jump_to_state
......
......@@ -81,6 +81,7 @@ struct _FpiSsm
int start_cleanup;
int cur_state;
gboolean completed;
gboolean critical;
gboolean silence;
GSource *timeout;
GError *error;
......@@ -277,6 +278,10 @@ fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback)
ssm->cur_state = 0;
ssm->completed = FALSE;
ssm->error = NULL;
if (ssm->critical)
fpi_device_critical_enter (ssm->dev);
__ssm_call_handler (ssm, TRUE);
}
......@@ -366,6 +371,10 @@ fpi_ssm_mark_completed (FpiSsm *machine)
machine->callback (machine, machine->dev, error);
}
if (machine->critical)
fpi_device_critical_leave (machine->dev);
fpi_ssm_free (machine);
}
......@@ -660,6 +669,23 @@ fpi_ssm_silence_debug (FpiSsm *machine)
machine->silence = TRUE;
}
/**
* fpi_ssm_set_critical:
* @machine: an #FpiSsm state machine
*
* Sets up the SSM to hold a critical section in the driver code. See
* fpi_device_critical_enter() for more details. This is useful if the SSM must
* not be interrupted in order to keep the device in a good state. You can e.g.
* guarantee that an image transfer is completed.
*
* This function must be called before starting the SSM.
*/
void
fpi_ssm_set_critical (FpiSsm *machine)
{
machine->critical = TRUE;
}
/**
* fpi_ssm_usb_transfer_cb:
* @transfer: a #FpiUsbTransfer
......
......@@ -97,6 +97,7 @@ GError * fpi_ssm_dup_error (FpiSsm *machine);
int fpi_ssm_get_cur_state (FpiSsm *machine);
void fpi_ssm_silence_debug (FpiSsm *machine);
void fpi_ssm_set_critical (FpiSsm *machine);
/* Callbacks to be used by the driver instead of implementing their own
* logic.
......
Supports Markdown
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