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

Side by Side Diff: mojo/public/bindings/lib/scratch_buffer.h

Issue 220243007: Mojo: Move mojo/public/bindings/lib to mojo/public/cpp/bindings/lib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/lib/router.cc ('k') | mojo/public/bindings/lib/scratch_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #ifndef MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_
7
8 #include <deque>
9
10 #include "mojo/public/cpp/bindings/buffer.h"
11 #include "mojo/public/cpp/system/macros.h"
12
13 namespace mojo {
14 namespace internal {
15
16 // The following class is designed to be allocated on the stack. If necessary,
17 // it will failover to allocating objects on the heap.
18 class ScratchBuffer : public Buffer {
19 public:
20 ScratchBuffer();
21 virtual ~ScratchBuffer();
22
23 virtual void* Allocate(size_t num_bytes, Destructor func = NULL)
24 MOJO_OVERRIDE;
25
26 private:
27 enum { kMinSegmentSize = 512 };
28
29 struct Segment {
30 Segment* next;
31 char* cursor;
32 char* end;
33 };
34
35 void* AllocateInSegment(Segment* segment, size_t num_bytes);
36 void AddOverflowSegment(size_t delta);
37
38 char fixed_data_[kMinSegmentSize];
39 Segment fixed_;
40 Segment* overflow_;
41
42 struct PendingDestructor {
43 Destructor func;
44 void* address;
45 };
46 std::deque<PendingDestructor> pending_dtors_;
47
48 MOJO_DISALLOW_COPY_AND_ASSIGN(ScratchBuffer);
49 };
50
51 } // namespace internal
52 } // namespace mojo
53
54 #endif // MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_
OLDNEW
« no previous file with comments | « mojo/public/bindings/lib/router.cc ('k') | mojo/public/bindings/lib/scratch_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698