device: fix race condition in device_sync if ISR runs before thread waits
device: fix race condition in device_sync if ISR runs before thread waits

If an ISR was enabled and ran before the thread that wants to wait for
completion actually does wait, the type of thread would not be
registered in the object. The ISR would thus not know what type of
semaphore to release. This caused the ISR to release the object for the
previous caller of device_sync_call_wait().

Instead, the ISR now looks if there is already a waiter: if not, it
marks the device as being ready in the object, which allows the thread
to skip taking the semaphore; if there is a waiter, the correct
semaphore type is released, as before.

Change-Id: Ib97480db8ba3e895812cf4bc209d9794639af325
Signed-off-by: Benjamin Walsh <578db18f23ec223e50c404886c947386478a464e@windriver.com>

ldts/zephyr,sharronliu/zephyr,nashif/zephyr,zephyriot/zephyr,mbolivar/zephyr,coldnew/zephyr-project-fork,sharronliu/zephyr,coldnew/zephyr-project-fork,kraj/zephyr,explora26/zephyr,zephyriot/zephyr,finikorg/zephyr,ldts/zephyr,coldnew/zephyr-project-fork,holtmann/zephyr,tidyjiang8/zephyr-doc,zephyrproject-rtos/zephyr,rsalveti/zephyr,punitvara/zephyr,mirzak/zephyr-os,tidyjiang8/zephyr-doc,punitvara/zephyr,bigdinotech/zephyr,fractalclone/zephyr-riscv,zephyriot/zephyr,mirzak/zephyr-os,galak/zephyr,runchip/zephyr-cc3220,bigdinotech/zephyr,Vudentz/zephyr,bigdinotech/zephyr,zephyrproject-rtos/zephyr,erwango/zephyr,pklazy/zephyr,GiulianoFranchetto/zephyr,bboozzoo/zephyr,fbsder/zephyr,kraj/zephyr,fbsder/zephyr,Vudentz/zephyr,rsalveti/zephyr,bigdinotech/zephyr,bboozzoo/zephyr,Vudentz/zephyr,galak/zephyr,erwango/zephyr,explora26/zephyr,bboozzoo/zephyr,ldts/zephyr,32bitmicro/zephyr,nashif/zephyr,runchip/zephyr-cc3220,coldnew/zephyr-project-fork,aceofall/zephyr-iotos,fractalclone/zephyr-riscv,nashif/zephyr,fractalclone/zephyr-riscv,runchip/zephyr-cc3220,kraj/zephyr,Vudentz/zephyr,holtmann/zephyr,bboozzoo/zephyr,sharronliu/zephyr,finikorg/zephyr,zephyrproject-rtos/zephyr,erwango/zephyr,explora26/zephyr,mbolivar/zephyr,Vudentz/zephyr,mbolivar/zephyr,GiulianoFranchetto/zephyr,erwango/zephyr,zephyrproject-rtos/zephyr,32bitmicro/zephyr,runchip/zephyr-cc3220,zephyrproject-rtos/zephyr,mirzak/zephyr-os,32bitmicro/zephyr,mbolivar/zephyr,punitvara/zephyr,holtmann/zephyr,fractalclone/zephyr-riscv,erwango/zephyr,mirzak/zephyr-os,aceofall/zephyr-iotos,finikorg/zephyr,Vudentz/zephyr,pklazy/zephyr,mbolivar/zephyr,finikorg/zephyr,sharronliu/zephyr,fbsder/zephyr,zephyriot/zephyr,runchip/zephyr-cc3200,fractalclone/zephyr-riscv,explora26/zephyr,coldnew/zephyr-project-fork,runchip/zephyr-cc3200,runchip/zephyr-cc3220,ldts/zephyr,runchip/zephyr-cc3200,fbsder/zephyr,runchip/zephyr-cc3200,nashif/zephyr,tidyjiang8/zephyr-doc,galak/zephyr,pklazy/zephyr,fbsder/zephyr,tidyjiang8/zephyr-doc,finikorg/zephyr,mirzak/zephyr-os,explora26/zephyr,nashif/zephyr,galak/zephyr,bboozzoo/zephyr,aceofall/zephyr-iotos,sharronliu/zephyr,aceofall/zephyr-iotos,GiulianoFranchetto/zephyr,aceofall/zephyr-iotos,32bitmicro/zephyr,ldts/zephyr,runchip/zephyr-cc3200,rsalveti/zephyr,punitvara/zephyr,holtmann/zephyr,bigdinotech/zephyr,kraj/zephyr,GiulianoFranchetto/zephyr,32bitmicro/zephyr,zephyriot/zephyr,GiulianoFranchetto/zephyr,pklazy/zephyr,holtmann/zephyr,galak/zephyr,kraj/zephyr,tidyjiang8/zephyr-doc,rsalveti/zephyr,rsalveti/zephyr,punitvara/zephyr,pklazy/zephyr