| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #ifndef PLATFORMS_STM_DISCO_FLETCH_SRC_CIRCULAR_BUFFER_H_ | 5 #ifndef PLATFORMS_STM_DISCO_DARTINO_SRC_CIRCULAR_BUFFER_H_ |
| 6 #define PLATFORMS_STM_DISCO_FLETCH_SRC_CIRCULAR_BUFFER_H_ | 6 #define PLATFORMS_STM_DISCO_DARTINO_SRC_CIRCULAR_BUFFER_H_ |
| 7 | 7 |
| 8 #include <inttypes.h> | 8 #include <inttypes.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| 11 #include "src/shared/platform.h" | 11 #include "src/shared/platform.h" |
| 12 | 12 |
| 13 #define MIN(a, b) ((a) < (b) ? (a) : (b)) | 13 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 14 | 14 |
| 15 // Circular buffer holding bytes. | 15 // Circular buffer holding bytes. |
| 16 class CircularBuffer { | 16 class CircularBuffer { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Read up to count bytes into buffer. If block is kBlock the call | 34 // Read up to count bytes into buffer. If block is kBlock the call |
| 35 // will not return until at least one byte is read. | 35 // will not return until at least one byte is read. |
| 36 size_t Read(uint8_t* buffer, size_t count, Blocking block); | 36 size_t Read(uint8_t* buffer, size_t count, Blocking block); |
| 37 | 37 |
| 38 // Write up to count bytes from buffer. If block is kBlock the call | 38 // Write up to count bytes from buffer. If block is kBlock the call |
| 39 // will not return until at least one byte is written. | 39 // will not return until at least one byte is written. |
| 40 size_t Write(const uint8_t* buffer, size_t count, Blocking block); | 40 size_t Write(const uint8_t* buffer, size_t count, Blocking block); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 fletch::Monitor* monitor_; | 43 dartino::Monitor* monitor_; |
| 44 int waiting_; | 44 int waiting_; |
| 45 uint8_t* buffer_; | 45 uint8_t* buffer_; |
| 46 size_t capacity_; | 46 size_t capacity_; |
| 47 int head_; | 47 int head_; |
| 48 int tail_; | 48 int tail_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 #endif // PLATFORMS_STM_DISCO_FLETCH_SRC_CIRCULAR_BUFFER_H_ | 51 #endif // PLATFORMS_STM_DISCO_DARTINO_SRC_CIRCULAR_BUFFER_H_ |
| OLD | NEW |