Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
finalizable_data.h
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
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 file.
4
5#ifndef RUNTIME_VM_FINALIZABLE_DATA_H_
6#define RUNTIME_VM_FINALIZABLE_DATA_H_
7
8#include "include/dart_api.h"
10#include "vm/globals.h"
11
12namespace dart {
13
20
22 public:
24 : records_(0), get_position_(0), take_position_(0), external_size_(0) {}
25
27 for (intptr_t i = take_position_; i < records_.length(); i++) {
28 records_[i].callback(nullptr, records_[i].peer);
29 }
30 }
31
32 /// If [successful_write_callback] is provided, it's invoked when message
33 /// was serialized successfully.
34 /// [callback] is invoked when serialization failed.
35 void Put(intptr_t external_size,
36 void* data,
37 void* peer,
39 Dart_HandleFinalizer successful_write_callback = nullptr) {
40 FinalizableData finalizable_data;
41 finalizable_data.data = data;
42 finalizable_data.peer = peer;
43 finalizable_data.callback = callback;
44 finalizable_data.successful_write_callback = successful_write_callback;
45 records_.Add(finalizable_data);
46 external_size_ += external_size;
47 }
48
49 // Retrieve the next FinalizableData, but still run its finalizer when |this|
50 // is destroyed.
52 ASSERT(get_position_ < records_.length());
53 return records_[get_position_++];
54 }
55
56 // Retrieve the next FinalizableData, and skip its finalizer when |this| is
57 // destroyed.
59 ASSERT(take_position_ < records_.length());
60 return records_[take_position_++];
61 }
62
64 for (intptr_t i = 0; i < records_.length(); i++) {
65 if (records_[i].successful_write_callback != nullptr) {
66 records_[i].successful_write_callback(nullptr, records_[i].peer);
67 }
68 }
69 }
70
72 records_.Clear();
73 get_position_ = 0;
74 take_position_ = 0;
75 external_size_ = 0;
76 }
77
78 intptr_t external_size() const { return external_size_; }
79
80 private:
82 intptr_t get_position_;
83 intptr_t take_position_;
84 intptr_t external_size_;
85
87};
88
89} // namespace dart
90
91#endif // RUNTIME_VM_FINALIZABLE_DATA_H_
void Put(intptr_t external_size, void *data, void *peer, Dart_HandleFinalizer callback, Dart_HandleFinalizer successful_write_callback=nullptr)
void(* Dart_HandleFinalizer)(void *isolate_callback_data, void *peer)
Definition dart_api.h:265
#define ASSERT(E)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static int8_t data[kExtLength]
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581
Dart_HandleFinalizer callback
Dart_HandleFinalizer successful_write_callback