Skip to content

Commit eed17b5

Browse files
committed
小白学习workflow-中篇-源码
1 parent 2ec0fb0 commit eed17b5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## STL 源码剖析之 vector
2+
3+
`vector` 是一种常用的容器,基本能够支持任何类型的对象,同时也是一个可以动态增长的数组,它的背后蕴含着怎样精妙的设计呢?话不多说,马上就来分析关于`vector`是怎么实现这些功能.
4+

C++Notes/小白眼中的workflow-中篇.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define POLLER_EVENTS_MAX 256
2929
#define POLLER_NODE_ERROR ((struct __poller_node *)-1)
3030

31+
/*
32+
poll 节点
33+
*/
3134
struct __poller_node
3235
{
3336
int state;
@@ -47,6 +50,9 @@ struct __poller_node
4750
struct __poller_node *res;
4851
};
4952

53+
/*
54+
poller 数据结构
55+
*/
5056
struct __poller
5157
{
5258
size_t max_open_files;
@@ -69,9 +75,43 @@ struct __poller
6975
pthread_mutex_t mutex;
7076
char buf[POLLER_BUFSIZE];
7177
};
78+
#ifdef __linux__
7279

80+
//封装 epoll_create 创建文件描述符 指向内核创建的描述符集 之后的操作都通过描述符来操作
81+
static inline int __poller_create_pfd() {
82+
return epoll_create(1);
83+
}
7384

85+
//添加文件描述符
86+
static inline int __poller_add_fd(int fd, int event, void *data,
87+
poller_t *poller)
88+
{
89+
struct epoll_event ev = {
90+
.events = event;
91+
.data = {
92+
.ptr = data
93+
}
94+
};
95+
return epoll_ctl(poller->pfd, EPOLL_CTL_ADD, fd, &ev);
96+
}
7497

98+
static inline int __poller_del_fd(int fd, int event, poller_t *poller)
99+
{
100+
return epoll_ctl(poller->pfd, EPOLL_CTL_DEL, fd, NULL);
101+
}
102+
103+
static inline int __poller_mod_fd(int fd, int old_event,
104+
int new_event, void *data,
105+
poller_t *poller)
106+
{
107+
struct epoll_event ev = {
108+
.events = new_event,
109+
.data = {
110+
.ptr = data
111+
}
112+
};
113+
return epoll_ctl(poller->pfd, EPOLL_CTL_MOD, fd, &ev);
114+
}
75115

76116

77117

0 commit comments

Comments
 (0)