Fixing possible race conditioin in replace_state() function
Fixing possible race conditioin in replace_state() function

https://www.linux.org.ru/forum/lor-source/14805130
This fixes commit c92274db3da2ee9ccdb2b95d8d81ec4d95daf457

fat0troll/lorsource,maxcom/lorsource,maxcom/lorsource,fat0troll/lorsource,maxcom/lorsource,fat0troll/lorsource,maxcom/lorsource,fat0troll/lorsource