1
+ /*
2
+ Copyright (c) 2020 Arduino. All right reserved.
3
+
4
+ This library is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU Lesser General Public
6
+ License as published by the Free Software Foundation; either
7
+ version 2.1 of the License, or (at your option) any later version.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ #ifdef __cplusplus
20
+
21
+ #ifndef _SAFE_RING_BUFFER_
22
+ #define _SAFE_RING_BUFFER_
23
+
24
+ #include < api/RingBuffer.h>
25
+ #include " sync.h"
26
+
27
+ namespace arduino {
28
+
29
+ template <int N>
30
+ class SafeRingBufferN : public RingBufferN <N>
31
+ {
32
+ public:
33
+ int read_char ();
34
+ void store_char ( uint8_t c ) ;
35
+ };
36
+
37
+ typedef SafeRingBufferN<SERIAL_BUFFER_SIZE> SafeRingBuffer;
38
+
39
+ template <int N>
40
+ int SafeRingBufferN<N>::read_char() {
41
+ synchronized {
42
+ return RingBufferN<N>::read_char ();
43
+ }
44
+ }
45
+
46
+ template <int N>
47
+ void SafeRingBufferN<N>::store_char(uint8_t c) {
48
+ synchronized {
49
+ RingBufferN<N>::store_char (c);
50
+ }
51
+ }
52
+
53
+ }
54
+
55
+ #endif /* _SAFE_RING_BUFFER_ */
56
+ #endif /* __cplusplus */
0 commit comments