Home | History | Annotate | Download | only in protozero
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "perfetto/protozero/scattered_stream_null_delegate.h"
     18 
     19 namespace protozero {
     20 
     21 // An implementation of ScatteredStreamWriter::Delegate which always returns
     22 // the same piece of memory.
     23 // This is used when we need to no-op the writers (e.g. during teardown or in
     24 // case of resource exhaustion), avoiding that the clients have to deal with
     25 // nullptr checks.
     26 ScatteredStreamWriterNullDelegate::ScatteredStreamWriterNullDelegate(
     27     size_t chunk_size)
     28     : chunk_size_(chunk_size),
     29       chunk_(std::unique_ptr<uint8_t[]>(new uint8_t[chunk_size_])){};
     30 
     31 ScatteredStreamWriterNullDelegate::~ScatteredStreamWriterNullDelegate() {}
     32 
     33 ContiguousMemoryRange ScatteredStreamWriterNullDelegate::GetNewBuffer() {
     34   return {chunk_.get(), chunk_.get() + chunk_size_};
     35 }
     36 
     37 }  // namespace protozero
     38