Files
sdk/runtime/bin/io_buffer.h
T
asiva@google.com e380b175f8 Pass in the isolate parameter to the weak persistent callback handler so that
there is no need to access the current isolate in the callback and delete
path (this code is run while a GC is in progress).

See https://codereview.chromium.org/185643003/ for corresponding changes
in dartium

R=iposva@google.com

Review URL: https://codereview.chromium.org//186003002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33282 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-04 18:11:19 +00:00

50 lines
1.3 KiB
C++

// Copyright (c) 2012, the Dart 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 file.
#ifndef BIN_IO_BUFFER_H_
#define BIN_IO_BUFFER_H_
#include "platform/globals.h"
#include "include/dart_api.h"
namespace dart {
namespace bin {
class IOBuffer {
public:
// Allocate an IO buffer dart object (of type Uint8List) backed by
// an external byte array.
static Dart_Handle Allocate(intptr_t size, uint8_t **buffer);
// Allocate IO buffer storage.
static uint8_t* Allocate(intptr_t size);
// Function for disposing of IO buffer storage. All backing storage
// for IO buffers must be freed using this function.
static void Free(void* buffer) {
delete[] reinterpret_cast<uint8_t*>(buffer);
}
// Function for finalizing external byte arrays used as IO buffers.
static void Finalizer(Dart_Isolate isolate,
Dart_WeakPersistentHandle handle,
void* buffer) {
Free(buffer);
if (handle != NULL) {
Dart_DeleteWeakPersistentHandle(isolate, handle);
}
}
private:
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer);
};
} // namespace bin
} // namespace dart
#endif // BIN_IO_BUFFER_H_