1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
9 /* This file implements a single-producer/single-consumer queue, using a mutex
10 * and a condition variable.
12 * There are techniques to implement a queue like this without using memory
13 * barriers or locks on x86, but ARM's memory system is different from x86, so
14 * we cannot make the same assumptions about visibility order of writes. Using a
15 * mutex is slower, but also simpler.
17 * We make the assumption that messages are only enqueued on the main thread
18 * and consumed on the worker thread. Because we don't want to block the main
19 * thread, EnqueueMessage will return zero if the message could not be enqueued.
21 * DequeueMessage will block until a message is available using a condition
22 * variable. Again, this may not be as fast as spin-waiting, but will consume
23 * much less CPU (and battery), which is important to consider for ChromeOS
26 void InitializeMessageQueue();
27 int EnqueueMessage(char* message);
28 char* DequeueMessage();