libev 宏展开
想看源码,宏太多,看着累,宏展开,再看,功力时间不够,先放下
放上宏展开后的代码。
libev4.20
展开方示为
./configure
修改makefile文件,字符串 替换CC为 CPP
注意要把基础的CC定义保留
make
mv ev.o ev.c
mv event.o event.c
make clean
修改makefile文件,字符串替换CPP-》CC
注意要把基础的CPP定义保留
宏展开后#号注释的代码,可以修改CPP的定义 加个参数
ev.c,event.c
及为展开后的代码
测试可编译通过
附ev.c部分代码
struct ev_loop;
enum {
EV_UNDEF = (int)0xFFFFFFFF,
EV_NONE = 0x00,
EV_READ = 0x01,
EV_WRITE = 0x02,
EV__IOFDSET = 0x80,
EV_IO = EV_READ,
EV_TIMER = 0x00000100, EV_TIMEOUT = EV_TIMER, EV_PERIODIC = 0x00000200,
EV_SIGNAL = 0x00000400,
EV_CHILD = 0x00000800,
EV_STAT = 0x00001000,
EV_IDLE = 0x00002000,
EV_PREPARE = 0x00004000,
EV_CHECK = 0x00008000,
EV_EMBED = 0x00010000,
EV_FORK = 0x00020000,
EV_CLEANUP = 0x00040000,
EV_ASYNC = 0x00080000,
EV_CUSTOM = 0x01000000,
EV_ERROR = (int)0x80000000
};
typedef struct ev_watcher
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher *w, int revents);
} ev_watcher; typedef struct ev_watcher_list
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher_list *w, int revents); struct ev_watcher_list *next;
} ev_watcher_list; typedef struct ev_watcher_time
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher_time *w, int revents); ev_tstamp at;
} ev_watcher_time; typedef struct ev_io
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_io *w, int revents); struct ev_watcher_list *next; int fd;
int events;
} ev_io; typedef struct ev_timer
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_timer *w, int revents);
ev_tstamp at; ev_tstamp repeat;
} ev_timer; typedef struct ev_periodic
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_periodic *w, int revents); ev_tstamp at; ev_tstamp offset;
ev_tstamp interval;
ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) ;
} ev_periodic; typedef struct ev_signal
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_signal *w, int revents); struct ev_watcher_list *next; int signum;
} ev_signal; typedef struct ev_child
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_child *w, int revents); struct ev_watcher_list *next; int flags;
int pid;
int rpid;
int rstatus;
} ev_child; typedef struct stat ev_statdata; typedef struct ev_stat
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_stat *w, int revents); struct ev_watcher_list *next; ev_timer timer;
ev_tstamp interval;
const char *path;
ev_statdata prev;
ev_statdata attr; int wd;
} ev_stat; typedef struct ev_idle
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_idle *w, int revents);
} ev_idle; typedef struct ev_prepare
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_prepare *w, int revents);
} ev_prepare; typedef struct ev_check
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_check *w, int revents);
} ev_check; typedef struct ev_fork
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_fork *w, int revents);
} ev_fork; typedef struct ev_cleanup
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_cleanup *w, int revents);
} ev_cleanup; typedef struct ev_embed
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_embed *w, int revents); struct ev_loop *other;
ev_io io;
ev_prepare prepare;
ev_check check;
ev_timer timer;
ev_periodic periodic;
ev_idle idle;
ev_fork fork; ev_cleanup cleanup; } ev_embed; typedef struct ev_async
{
int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_async *w, int revents); sig_atomic_t volatile sent;
} ev_async; union ev_any_watcher
{
struct ev_watcher w;
struct ev_watcher_list wl; struct ev_io io;
struct ev_timer timer;
struct ev_periodic periodic;
struct ev_signal signal;
struct ev_child child; struct ev_stat stat; struct ev_idle idle; struct ev_prepare prepare;
struct ev_check check; struct ev_fork fork; struct ev_cleanup cleanup; struct ev_embed embed; struct ev_async async; }; enum { EVFLAG_AUTO = 0x00000000U, EVFLAG_NOENV = 0x01000000U,
EVFLAG_FORKCHECK = 0x02000000U, EVFLAG_NOINOTIFY = 0x00100000U, EVFLAG_NOSIGFD = , EVFLAG_SIGNALFD = 0x00200000U,
EVFLAG_NOSIGMASK = 0x00400000U
}; enum {
EVBACKEND_SELECT = 0x00000001U,
EVBACKEND_POLL = 0x00000002U,
EVBACKEND_EPOLL = 0x00000004U,
EVBACKEND_KQUEUE = 0x00000008U,
EVBACKEND_DEVPOLL = 0x00000010U,
EVBACKEND_PORT = 0x00000020U,
EVBACKEND_ALL = 0x0000003FU,
EVBACKEND_MASK = 0x0000FFFFU
}; extern int ev_version_major (void) ;
extern int ev_version_minor (void) ; extern unsigned int ev_supported_backends (void) ;
extern unsigned int ev_recommended_backends (void) ;
extern unsigned int ev_embeddable_backends (void) ; extern ev_tstamp ev_time (void) ;
extern void ev_sleep (ev_tstamp delay) ; extern void ev_set_allocator (void *(*cb)(void *ptr, long size) ) ; extern void ev_set_syserr_cb (void (*cb)(const char *msg) ) ; extern struct ev_loop *ev_default_loop (unsigned int flags ) ; static inline struct ev_loop *
ev_default_loop_uc_ (void)
{
extern struct ev_loop *ev_default_loop_ptr; return ev_default_loop_ptr;
} static inline int
ev_is_default_loop (struct ev_loop *loop)
{
return loop == ev_default_loop_uc_ ();
} extern struct ev_loop *ev_loop_new (unsigned int flags ) ; static inline void
idle_reify (struct ev_loop *loop)
{
if (__builtin_expect ((!!(((loop)->idleall))),()))
{
int pri; for (pri = ((((0x7f) & ) ? + : ) - (((0x7f) & ) ? - : ) + ); pri--; )
{
if (((loop)->pendingcnt) [pri])
break; if (((loop)->idlecnt) [pri])
{
queue_events (loop, (W *)((loop)->idles) [pri], ((loop)->idlecnt) [pri], EV_IDLE);
break;
}
}
}
} static inline void
timers_reify (struct ev_loop *loop)
{
do { } while (); if (((loop)->timercnt) && (((loop)->timers) [( - )]).at < ((loop)->mn_now))
{
do
{
ev_timer *w = (ev_timer *)(((loop)->timers) [( - )]).w; if (w->repeat)
{
((WT)(w))->at += w->repeat;
if (((WT)(w))->at < ((loop)->mn_now))
((WT)(w))->at = ((loop)->mn_now); (__builtin_expect(!(("libev: negative ev_timer repeat value found while processing timers", w->repeat > .)), ) ? __assert_rtn(__func__, "ev.c", , "(\"libev: negative ev_timer repeat value found while processing timers\", w->repeat > 0.)") : (void)); (((loop)->timers) [( - )]).at = (((loop)->timers) [( - )]).w->at;
downheap (((loop)->timers), ((loop)->timercnt), ( - ));
}
else
ev_timer_stop (loop, w); do { } while ();
feed_reverse (loop, (W)w);
}
while (((loop)->timercnt) && (((loop)->timers) [( - )]).at < ((loop)->mn_now)); feed_reverse_done (loop, EV_TIMER);
}
} static void __attribute__ ((__noinline__))
periodic_recalc (struct ev_loop *loop, ev_periodic *w)
{
ev_tstamp interval = w->interval > 0.0001220703125 ? w->interval : 0.0001220703125;
ev_tstamp at = w->offset + interval * floor ((((loop)->ev_rt_now) - w->offset) / interval); while (at <= ((loop)->ev_rt_now))
{
ev_tstamp nat = at + w->interval; if (__builtin_expect ((!!(nat == at)),()))
{
at = ((loop)->ev_rt_now);
break;
} at = nat;
} ((WT)(w))->at = at;
} static inline void
periodics_reify (struct ev_loop *loop)
{
do { } while (); while (((loop)->periodiccnt) && (((loop)->periodics) [( - )]).at < ((loop)->ev_rt_now))
{
do
{
ev_periodic *w = (ev_periodic *)(((loop)->periodics) [( - )]).w; if (w->reschedule_cb)
{
((WT)(w))->at = w->reschedule_cb (w, ((loop)->ev_rt_now)); (__builtin_expect(!(("libev: ev_periodic reschedule callback returned time in the past", ((WT)(w))->at >= ((loop)->ev_rt_now))), ) ? __assert_rtn(__func__, "ev.c", , "(\"libev: ev_periodic reschedule callback returned time in the past\", ev_at (w) >= ev_rt_now)") : (void)); (((loop)->periodics) [( - )]).at = (((loop)->periodics) [( - )]).w->at;
downheap (((loop)->periodics), ((loop)->periodiccnt), ( - ));
}
else if (w->interval)
{
periodic_recalc (loop, w);
(((loop)->periodics) [( - )]).at = (((loop)->periodics) [( - )]).w->at;
downheap (((loop)->periodics), ((loop)->periodiccnt), ( - ));
}
else
ev_periodic_stop (loop, w); do { } while ();
feed_reverse (loop, (W)w);
}
while (((loop)->periodiccnt) && (((loop)->periodics) [( - )]).at < ((loop)->ev_rt_now)); feed_reverse_done (loop, EV_PERIODIC);
}
} static void __attribute__ ((__noinline__))
periodics_reschedule (struct ev_loop *loop)
{
int i; for (i = ( - ); i < ((loop)->periodiccnt) + ( - ); ++i)
{
ev_periodic *w = (ev_periodic *)(((loop)->periodics) [i]).w; if (w->reschedule_cb)
((WT)(w))->at = w->reschedule_cb (w, ((loop)->ev_rt_now));
else if (w->interval)
periodic_recalc (loop, w); (((loop)->periodics) [i]).at = (((loop)->periodics) [i]).w->at;
} reheap (((loop)->periodics), ((loop)->periodiccnt));
} static void __attribute__ ((__noinline__))
timers_reschedule (struct ev_loop *loop, ev_tstamp adjust)
{
int i; for (i = ; i < ((loop)->timercnt); ++i)
{
ANHE *he = ((loop)->timers) + i + ( - );
(*he).w->at += adjust;
(*he).at = (*he).w->at;
}
} static inline void
time_update (struct ev_loop *loop, ev_tstamp max_block)
{
{
((loop)->ev_rt_now) = ev_time (); if (__builtin_expect ((!!(((loop)->mn_now) > ((loop)->ev_rt_now) || ((loop)->ev_rt_now) > ((loop)->mn_now) + max_block + .)),()))
{ timers_reschedule (loop, ((loop)->ev_rt_now) - ((loop)->mn_now)); periodics_reschedule (loop); } ((loop)->mn_now) = ((loop)->ev_rt_now);
}
}
还没看,以后可能也不会看了
libev 宏展开的更多相关文章
- C语言中的宏展开
#include<stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf(,) ...
- Visual Studio 查看宏展开
使用Visual Studio 开发c++项目,中遇到项目中宏定义套宏定义,难以阅读源代码的时候. 可在 项目-->右键-->配置属性-->c/c++ -->预处理器 --&g ...
- gcc将c源文件中的宏展开
1: sudo gcc -P -I. -I../instrument/stubs -I../instrument/stubs -I../ -E ctrl_xfer32.cc -o preprocess ...
- C\C++语言中的宏多重展开和递归展开
宏定义中的#,## 1. 宏中的参数前面使用一个#,预处理器会把这个参数转换为一个字符数组 2.记号粘贴操作符(token paste operator): ## “## ...
- 可变参数宏__VA_ARGS__
在 GNU C 中,宏可以接受可变数目的参数,就象函数一样,例如:#define pr_debug(fmt,arg...) \printk(KERN_DEBUG fmt,##arg) 用可变参数宏(v ...
- C/C++ 宏中的 #、#@、##的作用
宏中的# 功能是将其后面的宏参数进行字符串化操作(Stringizing operator), 简单说就是在它引用的宏变量的左右各加上一个双引号. #define STRING(x) #x 下面二条语 ...
- linux内核宏container_of
首先来个简单版本 /* given a pointer @ptr to the field @member embedded into type (usually * struct) @type, r ...
- C,C++宏中#与##的讲解[转]
MoreWindows 专注于Windows编程 C,C++宏中#与##的讲解 文中__FILE__与示例1可以参见<使用ANSI C and Microsoft C++中常用的预定义宏> ...
- 宏定义中的##操作符和... and _ _VA_ARGS_ _
1.Preprocessor Glue: The ## Operator 预处理连接符:##操作符 Like the # operator, the ## operator can be used i ...
随机推荐
- 微信公众平台开发教程(八)Session处理
微信公众平台开发教程(八)Session处理 在微信窗口,输入的信息有限,我们需要将一些信息分多次请求. 比如:在进行用户绑定时,我们需要输入用户的相关信息,比如:用户名.密码,或者姓名.电话号码,服 ...
- Shell 显示带颜色字体
格式: echo "/033[字背景颜色;字体颜色m字符串/033[控制码"如果单纯显示字体颜色可以固定控制码位0m.格式: echo "/033[字背景颜色;字体颜色m ...
- Install Slax on USB device (Slax U 盘安装)
Slax is a modern, portable, small and fast Linux operating system with a modular approach and outsta ...
- Newtonsoft.Json(Json.net)的基本用法
Newtonsoft.Json(Json.net)的基本用法 其它资料 JSON详解 添加引用: 使用NuGet,命令:install-package Newtonsoft.Json 实体类: pub ...
- go1.6.2 linux/amd64 的一个bug: gcc: 无法识别的选项‘-no-pie’
如果你的linux是中文版的. 即:执行 # echo $LANG 命令,返回的是 zh_CN.UTF-8 则会出现这个bug, 如果是 en_US.UTF-8 则没有这个问题. 这个bug的一个 ...
- htaccess高级应用:防盗链阻止迅雷下载以及限制访问
导读: 合理利用htaccess文件,即使没有服务器的管理权限可以解决很多问题:比如用htaccess防盗链,阻止迅雷下载,限制用户访问指定类型的文件.判断User-agent阻止迅雷下载. Rewr ...
- 飞凌OK6410开发板SDIO无线8189WIFI模块驱动移植
为什么要移植?开发板不是已经提供了无线驱动吗? 貌似是这样的..本来是好用的.加入自己第三方驱动后发现WIFI用不了...最后发现飞凌提供的内核里面没有8189芯片的代码...问售后他们说那边是好的. ...
- java获取服务器所有信息
package com.sinosoft.outher.listener; import java.net.InetAddress;import java.net.UnknownHostExcepti ...
- a标签鼠标经过,字颜色和下划线的颜色都变红
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- window删除文件时提示: 源文件名长度大于系统支持的长度
有时候删除windows中的目录的时候,会出现"源文件名长度大于系统支持的长度", 而导致不能删除, 作为一个程序猿, 怎么可以被这个折服呢, 原理: 利用 Java 递归删除文 ...