-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
61 lines (56 loc) · 1.32 KB
/
main.cc
File metadata and controls
61 lines (56 loc) · 1.32 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
#include <iostream>
#include <endian.h>
#include <functional>
#include <stdio.h>
#include "test/sharedPointer.h"
#include "test/pool.h"
#include <queue>
union quint16 {
// 2 bit
uint16_t u16;
uint8_t arr[2];
};
// 大小端测试
void TestEndian() {
quint16 x;
x.arr[0] = 0x11;
x.arr[1] = 0x22;
// 大端模式
uint16_t be_x = htobe16(x.u16);
printf("big edian: x.u16 = %#x\n", be_x);
// 小端数据(硬件上的数据)
uint32_t le_x = htole32(x.u16);
printf("little edian: x.u16 = %#x\n", le_x);
}
// 测试任务队列
class TestQueue {
typedef std::function<void()> TestCallBack;
public:
void addTask(TestCallBack &&func) {
tasks.push(func);
}
void run() {
while (!tasks.empty())
{
TestCallBack callback = tasks.front();
tasks.pop();
callback();
}
}
private:
std::queue<TestCallBack> tasks;
};
int main(int argc,char** argv) {
// test 1
TestQueue taskPool;
taskPool.addTask(TestEndian);
// test 2
TestSharedError testObj1;
taskPool.addTask(std::bind(&TestSharedError::run,testObj1,SharedErrorSolver::ENABLE_FROM_THIS));
// test 3
PoolTest testObj2;
taskPool.addTask(std::bind(&PoolTest::testWait,testObj2));
// start process
taskPool.run();
return 0;
}