]>
Commit | Line | Data |
---|---|---|
769a03c3 MF |
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. | |
4 | */ | |
5 | ||
6 | #ifndef QUEUE_H_ | |
7 | #define QUEUE_H_ | |
8 | ||
9 | #include <inttypes.h> | |
10 | #include <stdbool.h> | |
11 | ||
12 | /* This file implements a single-producer/single-consumer queue, using a mutex | |
13 | * and a condition variable. | |
14 | * | |
15 | * There are techniques to implement a queue like this without using memory | |
16 | * barriers or locks on x86, but ARM's memory system is different from x86, so | |
17 | * we cannot make the same assumptions about visibility order of writes. Using a | |
18 | * mutex is slower, but also simpler. | |
19 | * | |
20 | * We make the assumption that messages are only enqueued on the main thread | |
21 | * and consumed on the worker thread. Because we don't want to block the main | |
22 | * thread, EnqueueMessage will return zero if the message could not be enqueued. | |
23 | * | |
24 | * DequeueMessage will block until a message is available using a condition | |
25 | * variable. Again, this may not be as fast as spin-waiting, but will consume | |
26 | * much less CPU (and battery), which is important to consider for ChromeOS | |
27 | * devices. */ | |
28 | ||
29 | struct q_ele { | |
30 | char **argv; | |
31 | uint32_t argc; | |
32 | }; | |
33 | ||
34 | void InitializeMessageQueue(void); | |
35 | bool EnqueueMessage(char **argv, uint32_t argc); | |
36 | struct q_ele *DequeueMessage(); | |
37 | ||
38 | #endif /* QUEUE_H_ */ |