4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "InputQueue.hpp"
25 #include "InputEvents.hpp"
26 #include "Protection.hpp"
27 #include "Thread/Mutex.hpp"
28 #include "Thread/Debug.hpp"
32 static Mutex mutexEventQueue
;
34 #define MAX_GCE_QUEUE 10
35 static int GCE_Queue
[MAX_GCE_QUEUE
];
36 #define MAX_NMEA_QUEUE 10
37 static int NMEA_Queue
[MAX_NMEA_QUEUE
];
40 InputEvents::ClearQueues()
42 ScopeLock
protect(mutexEventQueue
);
44 std::fill(GCE_Queue
, GCE_Queue
+ MAX_GCE_QUEUE
, -1);
45 std::fill(NMEA_Queue
, NMEA_Queue
+ MAX_NMEA_QUEUE
, -1);
49 InputEvents::processNmea(unsigned ne_id
)
51 assert(InMainThread());
53 // add an event to the bottom of the queue
54 for (int i
= 0; i
< MAX_NMEA_QUEUE
; i
++) {
55 if (NMEA_Queue
[i
] == -1) {
56 NMEA_Queue
[i
] = ne_id
;
66 InputEvents::DoQueuedEvents()
68 assert(InMainThread());
70 int GCE_Queue_copy
[MAX_GCE_QUEUE
];
73 // copy the queue first, blocking
74 mutexEventQueue
.Lock();
75 std::copy(GCE_Queue
, GCE_Queue
+ MAX_GCE_QUEUE
, GCE_Queue_copy
);
76 std::fill(GCE_Queue
, GCE_Queue
+ MAX_GCE_QUEUE
, -1);
77 mutexEventQueue
.Unlock();
79 // process each item in the queue
80 for (i
= 0; i
< MAX_GCE_QUEUE
; i
++) {
81 if (GCE_Queue_copy
[i
] != -1) {
82 processGlideComputer_real(GCE_Queue_copy
[i
]);
85 for (i
= 0; i
< MAX_NMEA_QUEUE
; i
++) {
86 if (NMEA_Queue
[i
] != -1)
87 processNmea_real(NMEA_Queue
[i
]);
92 InputEvents::processGlideComputer(unsigned gce_id
)
94 // add an event to the bottom of the queue
95 mutexEventQueue
.Lock();
96 for (int i
= 0; i
< MAX_GCE_QUEUE
; i
++) {
97 if (GCE_Queue
[i
] == -1) {
98 GCE_Queue
[i
] = gce_id
;
102 mutexEventQueue
.Unlock();