-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIO.h
More file actions
68 lines (46 loc) · 1.4 KB
/
IO.h
File metadata and controls
68 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by pengyibo on 2019-09-06.
//
#ifndef QUEUESTORE_IO_H
#define QUEUESTORE_IO_H
#include <iostream>
#include <vector>
#include <thread>
#include <utility>
#include <chrono>
#include <unistd.h>
#include <fcntl.h>
#include "BlockingQueue.h"
#include "Cache.h"
#include "ConcurrentHash.h"
namespace IO{
class FixedBuffer;
class File;
using BufferPtr = std::unique_ptr<FixedBuffer>;
using FilePtr = std::unique_ptr<File>;
class IOContext{
public:
IOContext();
~IOContext();
// 将一个指定page读入到内存里面
void loadPage(PageCache* cache, int idx, uint64_t offset, uint32_t bytes);
void flushPage(size_t paged_msg_size, PageCache* page, uint16_t& file_idx, uint64_t& file_offset);
private:
void flushHandler();
void wakeUpIoThreads();
void flushCurBuffer();
void setCurBuffer(uint64_t origin_file_off, uint16_t origin_file_idx);
CONCURRENT::MutexLock BufferVectorMutex;
CONCURRENT::Condition notify;
CONCURRENT::MutexLock FileMutex;
CONCURRENT::SpinLock CurBufferMutex;
std::vector<BufferPtr> fullBuffers;
std::vector<BufferPtr> emptyBuffers;
FilePtr Files[1024];
BufferPtr curBuffer;
std::atomic_bool running_;
std::vector<std::thread> flushThreads;
};
IOContext& getIoContext();
}
#endif //QUEUESTORE_IO_H