lib/intel_allocator: Wait for allocator thread to be ready

Before allowing allocator working in multiprocess mode we have to
ensure it is ready and able to process allocator messages passed
from children.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Jason Ekstrand <jason@jlekstrand.net>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Petri Latvala <petri.latvala@intel.com>
diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index 8a2e607..96f839d 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -794,10 +794,17 @@
 	channel->init(channel);
 }
 
+#define START_TIMEOUT_MS 100
 void __intel_allocator_multiprocess_start(void)
 {
+	int time_left = START_TIMEOUT_MS;
+
 	pthread_create(&allocator_thread, NULL,
 		       allocator_thread_loop, NULL);
+
+	/* Wait unless allocator thread get started */
+	while (time_left-- > 0 && !READ_ONCE(allocator_thread_running))
+		usleep(1000);
 }
 
 /**