[CritFix] Fix issue with inconsistent resorting
[CritFix] Fix issue with inconsistent resorting

This is a long term issue that was in rspamd for many years. Sometimes,
some rules are not scanned or scanned twice. That happened because of
resorting called during pending tasks exist in the wait queue. In this
case, resorting breaks logic of symbols processing, causing unprocessed
rules to be treated as processed and, vice versa, processed rules as
unprocessed.

This commit introduces refcounted approach for resorting keeping state
for each individual task. This allows to resort independently from the
existing tasks waiting in the queue.

minaevmike/rspamd,minaevmike/rspamd,andrejzverev/rspamd,andrejzverev/rspamd,andrejzverev/rspamd,AlexeySa/rspamd,andrejzverev/rspamd,andrejzverev/rspamd,AlexeySa/rspamd,minaevmike/rspamd,AlexeySa/rspamd,andrejzverev/rspamd,andrejzverev/rspamd,AlexeySa/rspamd,andrejzverev/rspamd,minaevmike/rspamd,minaevmike/rspamd,minaevmike/rspamd,minaevmike/rspamd,AlexeySa/rspamd,AlexeySa/rspamd,AlexeySa/rspamd,minaevmike/rspamd,minaevmike/rspamd,AlexeySa/rspamd,AlexeySa/rspamd