-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequeue_imp.h
More file actions
97 lines (74 loc) · 1.75 KB
/
Copy pathequeue_imp.h
File metadata and controls
97 lines (74 loc) · 1.75 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef EQUEUE_IMP_H
#define EQUEUE_IMP_H
#include "equeue_type.h"
#include <list>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
namespace eq{
enum{
DEFAULT_BLOCK_SIZE = 512 * 1024 * 1024,
};
enum{
OP_ADD = 1,
OP_DEL = 2,
};
struct op{
int m_cmd;
int64 m_op_id;
int m_log_file_id;
task m_t;
};
class eq_imp{
public:
eq_imp();
~eq_imp();
int init(int64 maxsize, int64 maxnum,
const std::string& storepath);
int uninit();
int add_back(const std::string& t);
int get_front(task& t);
//del is only del from disk
int del(int64 id);
int del(const task& t);
int64 size(){
return m_size;
}
int64 count(){
return m_cnt;
}
//when the size is small,dump to file
int dump();
private:
int load_from_bin_log_files();
int load_one_bin_log_file(const std::string& f,
int64 startopid);
//add or del from mem
int add_task(const op& t);
int del_task(const op& t);
//save to disk
int save_task_to_file(const op& t);
int del_task_from_file(const op& t);
int check_if_open_new_file();
int64 inc_and_get_id();
int64 inc_and_get_op_id();
int64 m_maxsize;
int64 m_maxcnt;
int64 m_size;
int64 m_cnt;
std::string m_store_path;
volatile int64 m_current_op_id;
volatile int64 m_current_task_id;
int m_current_file_id;
time_t m_last_dump_time;
FILE* m_current_file;
std::list<op> m_tasks;
pthread_mutex_t m_cs;
sem_t m_sem;
};
////return left len, -1 error
int load_op_from_buf(const char* buf,int len, op& o);
//return left len, -1 error
int save_op_to_buf(const op& o, char* buf, int len);
}
#endif/*EQUEUE_IMP_H*/