Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8d40bc9 authored by David Woodhouse's avatar David Woodhouse Committed by David S. Miller
Browse files

libertas: refactor the 'should I sleep?' decision in lbs_thread()



This was making my brain hurt.

Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 45c24903
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -722,6 +722,8 @@ static int lbs_thread(void *data)
	set_freezable();

	for (;;) {
		int shouldsleep;

		lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
				priv->intcounter, priv->currenttxskb, priv->dnld_sent);

@@ -729,8 +731,22 @@ static int lbs_thread(void *data)
		set_current_state(TASK_INTERRUPTIBLE);
		spin_lock_irq(&priv->driver_lock);

		if ((priv->psstate == PS_STATE_SLEEP) ||
		    (!priv->intcounter && (priv->dnld_sent || priv->cur_cmd || list_empty(&priv->cmdpendingq)))) {
		if (priv->surpriseremoved)
			shouldsleep = 0;	/* Bye */
		else if (priv->psstate == PS_STATE_SLEEP)
			shouldsleep = 1;	/* Sleep mode. Nothing we can do till it wakes */
		else if (priv->intcounter)
			shouldsleep = 0;	/* Interrupt pending. Deal with it now */
		else if (priv->dnld_sent)
			shouldsleep = 1;	/* Something is en route to the device already */
		else if (priv->cur_cmd)
			shouldsleep = 1;	/* Can't send a command; one already running */
		else if (!list_empty(&priv->cmdpendingq))
			shouldsleep = 0;	/* We have a command to send */
		else
			shouldsleep = 1;	/* No command */

		if (shouldsleep) {
			lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
				       priv->connect_status, priv->intcounter,
				       priv->psmode, priv->psstate);