1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | // Licensed under the MIT license. |
3 | |
4 | #pragma once |
5 | |
6 | #include <atomic> |
7 | #include <cstdint> |
8 | #include "address.h" |
9 | #include "async.h" |
10 | #include "native_buffer_pool.h" |
11 | |
12 | #ifdef _WIN32 |
13 | #include <concurrent_queue.h> |
14 | |
15 | template <typename T> |
16 | using concurrent_queue = concurrency::concurrent_queue<T>; |
17 | #endif |
18 | |
19 | namespace FASTER { |
20 | namespace core { |
21 | |
22 | class AsyncIOContext : public IAsyncContext { |
23 | public: |
24 | AsyncIOContext(void* faster_, Address address_, |
25 | IAsyncContext* caller_context_, |
26 | concurrent_queue<AsyncIOContext*>* thread_io_responses_, |
27 | uint64_t io_id_) |
28 | : faster{ faster_ } |
29 | , address{ address_ } |
30 | , caller_context{ caller_context_ } |
31 | , thread_io_responses{ thread_io_responses_ } |
32 | , io_id{ io_id_ } { |
33 | } |
34 | /// No copy constructor. |
35 | AsyncIOContext(const AsyncIOContext& other) = delete; |
36 | /// The deep-copy constructor. |
37 | AsyncIOContext(AsyncIOContext& other, IAsyncContext* caller_context_) |
38 | : faster{ other.faster } |
39 | , address{ other.address } |
40 | , caller_context{ caller_context_ } |
41 | , thread_io_responses{ other.thread_io_responses } |
42 | , record{ std::move(other.record) } |
43 | , io_id{ other.io_id } { |
44 | } |
45 | protected: |
46 | Status DeepCopy_Internal(IAsyncContext*& context_copy) final { |
47 | return IAsyncContext::DeepCopy_Internal(*this, caller_context, context_copy); |
48 | } |
49 | public: |
50 | void* faster; |
51 | Address address; |
52 | IAsyncContext* caller_context; |
53 | concurrent_queue<AsyncIOContext*>* thread_io_responses; |
54 | uint64_t io_id; |
55 | |
56 | SectorAlignedMemory record; |
57 | }; |
58 | |
59 | } |
60 | } // namespace FASTER::core |