Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1453)

Unified Diff: platforms/stm/disco_fletch/src/circular_buffer.cc

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: platforms/stm/disco_fletch/src/circular_buffer.cc
diff --git a/platforms/stm/disco_fletch/src/circular_buffer.cc b/platforms/stm/disco_fletch/src/circular_buffer.cc
deleted file mode 100755
index d0ba1efdc22397ccab930fe55d1e68317a78008d..0000000000000000000000000000000000000000
--- a/platforms/stm/disco_fletch/src/circular_buffer.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-#include "platforms/stm/disco_fletch/src/circular_buffer.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-CircularBuffer::CircularBuffer(size_t capacity) {
- monitor_ = fletch::Platform::CreateMonitor();
- // One additional byte needed to distinguish between empty and full.
- capacity_ = capacity + 1;
- buffer_ = new uint8_t[capacity_];
- head_ = tail_ = 0;
-}
-
-CircularBuffer::~CircularBuffer() {
- delete[] buffer_;
-}
-
-bool CircularBuffer::IsEmpty() {
- fletch::ScopedMonitorLock locker(monitor_);
- return head_ == tail_;
-}
-
-bool CircularBuffer::IsFull() {
- fletch::ScopedMonitorLock locker(monitor_);
- return ((head_ + 1) % capacity_) == tail_;
-}
-
-size_t CircularBuffer::Read(uint8_t* data, size_t count, Blocking block) {
- fletch::ScopedMonitorLock locker(monitor_);
-
- // If buffer is empty wait for data.
- if (block == kBlock) {
- if (head_ == tail_) {
- monitor_->Wait();
- }
- }
-
- int bytes;
- int read = 0;
-
- if (tail_ > head_) {
- bytes = MIN(capacity_ - tail_, count);
- memcpy(data, buffer_ + tail_, bytes);
- read = bytes;
- tail_ = (tail_ + bytes) % capacity_;
- }
-
- if (tail_ < head_) {
- bytes = MIN(head_ - tail_, count - read);
- memcpy(data + read, buffer_ + tail_, bytes);
- read += bytes;
- tail_ = (tail_ + bytes) % capacity_;
- }
-
- monitor_->Notify();
-
- return read;
-}
-
-size_t CircularBuffer::Write(
- const uint8_t* data, size_t count, Blocking block) {
- fletch::ScopedMonitorLock locker(monitor_);
-
- // If buffer is full wait for room.
- if (block == kBlock) {
- if (((head_ + 1) % capacity_) == tail_) {
- monitor_->Wait();
- }
- }
-
- int bytes;
- int written = 0;
-
- if (head_ >= tail_) {
- bytes = (capacity_ - head_) - (tail_ == 0 ? 1 : 0);
- bytes = MIN(bytes, count);
- memcpy(buffer_ + head_, data, bytes);
- written = bytes;
- head_ = (head_ + bytes) % capacity_;
- }
-
- if (head_ < tail_) {
- bytes = MIN(tail_ - head_ - 1, count - written);
- memcpy(buffer_ + head_, data + written, bytes);
- written += bytes;
- head_ = (head_ + bytes) % capacity_;
- }
-
- monitor_->Notify();
-
- return written;
-}
« no previous file with comments | « platforms/stm/disco_fletch/src/circular_buffer.h ('k') | platforms/stm/disco_fletch/src/circular_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698