completely rewritten to use thread mailboxes

Signed-off-by: Jan Dvořák <mordae@anilinux.org>