想看源码,宏太多,看着累,宏展开,再看,功力时间不够,先放下

放上宏展开后的代码。

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部分代码

  1. struct ev_loop;
  2. enum {
  3. EV_UNDEF = (int)0xFFFFFFFF,
  4. EV_NONE = 0x00,
  5. EV_READ = 0x01,
  6. EV_WRITE = 0x02,
  7. EV__IOFDSET = 0x80,
  8. EV_IO = EV_READ,
  9. EV_TIMER = 0x00000100,
  10.  
  11. EV_TIMEOUT = EV_TIMER,
  12.  
  13. EV_PERIODIC = 0x00000200,
  14. EV_SIGNAL = 0x00000400,
  15. EV_CHILD = 0x00000800,
  16. EV_STAT = 0x00001000,
  17. EV_IDLE = 0x00002000,
  18. EV_PREPARE = 0x00004000,
  19. EV_CHECK = 0x00008000,
  20. EV_EMBED = 0x00010000,
  21. EV_FORK = 0x00020000,
  22. EV_CLEANUP = 0x00040000,
  23. EV_ASYNC = 0x00080000,
  24. EV_CUSTOM = 0x01000000,
  25. EV_ERROR = (int)0x80000000
  26. };
  27. typedef struct ev_watcher
  28. {
  29. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher *w, int revents);
  30. } ev_watcher;
  31.  
  32. typedef struct ev_watcher_list
  33. {
  34. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher_list *w, int revents);
  35.  
  36. struct ev_watcher_list *next;
  37. } ev_watcher_list;
  38.  
  39. typedef struct ev_watcher_time
  40. {
  41. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_watcher_time *w, int revents);
  42.  
  43. ev_tstamp at;
  44. } ev_watcher_time;
  45.  
  46. typedef struct ev_io
  47. {
  48. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_io *w, int revents);
  49.  
  50. struct ev_watcher_list *next;
  51.  
  52. int fd;
  53. int events;
  54. } ev_io;
  55.  
  56. typedef struct ev_timer
  57. {
  58. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_timer *w, int revents);
  59. ev_tstamp at;
  60.  
  61. ev_tstamp repeat;
  62. } ev_timer;
  63.  
  64. typedef struct ev_periodic
  65. {
  66. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_periodic *w, int revents); ev_tstamp at;
  67.  
  68. ev_tstamp offset;
  69. ev_tstamp interval;
  70. ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) ;
  71. } ev_periodic;
  72.  
  73. typedef struct ev_signal
  74. {
  75. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_signal *w, int revents);
  76.  
  77. struct ev_watcher_list *next;
  78.  
  79. int signum;
  80. } ev_signal;
  81.  
  82. typedef struct ev_child
  83. {
  84. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_child *w, int revents);
  85.  
  86. struct ev_watcher_list *next;
  87.  
  88. int flags;
  89. int pid;
  90. int rpid;
  91. int rstatus;
  92. } ev_child;
  93.  
  94. typedef struct stat ev_statdata;
  95.  
  96. typedef struct ev_stat
  97. {
  98. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_stat *w, int revents);
  99.  
  100. struct ev_watcher_list *next;
  101.  
  102. ev_timer timer;
  103. ev_tstamp interval;
  104. const char *path;
  105. ev_statdata prev;
  106. ev_statdata attr;
  107.  
  108. int wd;
  109. } ev_stat;
  110.  
  111. typedef struct ev_idle
  112. {
  113. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_idle *w, int revents);
  114. } ev_idle;
  115.  
  116. typedef struct ev_prepare
  117. {
  118. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_prepare *w, int revents);
  119. } ev_prepare;
  120.  
  121. typedef struct ev_check
  122. {
  123. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_check *w, int revents);
  124. } ev_check;
  125.  
  126. typedef struct ev_fork
  127. {
  128. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_fork *w, int revents);
  129. } ev_fork;
  130.  
  131. typedef struct ev_cleanup
  132. {
  133. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_cleanup *w, int revents);
  134. } ev_cleanup;
  135.  
  136. typedef struct ev_embed
  137. {
  138. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_embed *w, int revents);
  139.  
  140. struct ev_loop *other;
  141. ev_io io;
  142. ev_prepare prepare;
  143. ev_check check;
  144. ev_timer timer;
  145. ev_periodic periodic;
  146. ev_idle idle;
  147. ev_fork fork;
  148.  
  149. ev_cleanup cleanup;
  150.  
  151. } ev_embed;
  152.  
  153. typedef struct ev_async
  154. {
  155. int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_async *w, int revents);
  156.  
  157. sig_atomic_t volatile sent;
  158. } ev_async;
  159.  
  160. union ev_any_watcher
  161. {
  162. struct ev_watcher w;
  163. struct ev_watcher_list wl;
  164.  
  165. struct ev_io io;
  166. struct ev_timer timer;
  167. struct ev_periodic periodic;
  168. struct ev_signal signal;
  169. struct ev_child child;
  170.  
  171. struct ev_stat stat;
  172.  
  173. struct ev_idle idle;
  174.  
  175. struct ev_prepare prepare;
  176. struct ev_check check;
  177.  
  178. struct ev_fork fork;
  179.  
  180. struct ev_cleanup cleanup;
  181.  
  182. struct ev_embed embed;
  183.  
  184. struct ev_async async;
  185.  
  186. };
  187.  
  188. enum {
  189.  
  190. EVFLAG_AUTO = 0x00000000U,
  191.  
  192. EVFLAG_NOENV = 0x01000000U,
  193. EVFLAG_FORKCHECK = 0x02000000U,
  194.  
  195. EVFLAG_NOINOTIFY = 0x00100000U,
  196.  
  197. EVFLAG_NOSIGFD = ,
  198.  
  199. EVFLAG_SIGNALFD = 0x00200000U,
  200. EVFLAG_NOSIGMASK = 0x00400000U
  201. };
  202.  
  203. enum {
  204. EVBACKEND_SELECT = 0x00000001U,
  205. EVBACKEND_POLL = 0x00000002U,
  206. EVBACKEND_EPOLL = 0x00000004U,
  207. EVBACKEND_KQUEUE = 0x00000008U,
  208. EVBACKEND_DEVPOLL = 0x00000010U,
  209. EVBACKEND_PORT = 0x00000020U,
  210. EVBACKEND_ALL = 0x0000003FU,
  211. EVBACKEND_MASK = 0x0000FFFFU
  212. };
  213.  
  214. extern int ev_version_major (void) ;
  215. extern int ev_version_minor (void) ;
  216.  
  217. extern unsigned int ev_supported_backends (void) ;
  218. extern unsigned int ev_recommended_backends (void) ;
  219. extern unsigned int ev_embeddable_backends (void) ;
  220.  
  221. extern ev_tstamp ev_time (void) ;
  222. extern void ev_sleep (ev_tstamp delay) ;
  223.  
  224. extern void ev_set_allocator (void *(*cb)(void *ptr, long size) ) ;
  225.  
  226. extern void ev_set_syserr_cb (void (*cb)(const char *msg) ) ;
  227.  
  228. extern struct ev_loop *ev_default_loop (unsigned int flags ) ;
  229.  
  230. static inline struct ev_loop *
  231. ev_default_loop_uc_ (void)
  232. {
  233. extern struct ev_loop *ev_default_loop_ptr;
  234.  
  235. return ev_default_loop_ptr;
  236. }
  237.  
  238. static inline int
  239. ev_is_default_loop (struct ev_loop *loop)
  240. {
  241. return loop == ev_default_loop_uc_ ();
  242. }
  243.  
  244. extern struct ev_loop *ev_loop_new (unsigned int flags ) ;
  245.  
  246. static inline void
  247. idle_reify (struct ev_loop *loop)
  248. {
  249. if (__builtin_expect ((!!(((loop)->idleall))),()))
  250. {
  251. int pri;
  252.  
  253. for (pri = ((((0x7f) & ) ? + : ) - (((0x7f) & ) ? - : ) + ); pri--; )
  254. {
  255. if (((loop)->pendingcnt) [pri])
  256. break;
  257.  
  258. if (((loop)->idlecnt) [pri])
  259. {
  260. queue_events (loop, (W *)((loop)->idles) [pri], ((loop)->idlecnt) [pri], EV_IDLE);
  261. break;
  262. }
  263. }
  264. }
  265. }
  266.  
  267. static inline void
  268. timers_reify (struct ev_loop *loop)
  269. {
  270. do { } while ();
  271.  
  272. if (((loop)->timercnt) && (((loop)->timers) [( - )]).at < ((loop)->mn_now))
  273. {
  274. do
  275. {
  276. ev_timer *w = (ev_timer *)(((loop)->timers) [( - )]).w;
  277.  
  278. if (w->repeat)
  279. {
  280. ((WT)(w))->at += w->repeat;
  281. if (((WT)(w))->at < ((loop)->mn_now))
  282. ((WT)(w))->at = ((loop)->mn_now);
  283.  
  284. (__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));
  285.  
  286. (((loop)->timers) [( - )]).at = (((loop)->timers) [( - )]).w->at;
  287. downheap (((loop)->timers), ((loop)->timercnt), ( - ));
  288. }
  289. else
  290. ev_timer_stop (loop, w);
  291.  
  292. do { } while ();
  293. feed_reverse (loop, (W)w);
  294. }
  295. while (((loop)->timercnt) && (((loop)->timers) [( - )]).at < ((loop)->mn_now));
  296.  
  297. feed_reverse_done (loop, EV_TIMER);
  298. }
  299. }
  300.  
  301. static void __attribute__ ((__noinline__))
  302. periodic_recalc (struct ev_loop *loop, ev_periodic *w)
  303. {
  304. ev_tstamp interval = w->interval > 0.0001220703125 ? w->interval : 0.0001220703125;
  305. ev_tstamp at = w->offset + interval * floor ((((loop)->ev_rt_now) - w->offset) / interval);
  306.  
  307. while (at <= ((loop)->ev_rt_now))
  308. {
  309. ev_tstamp nat = at + w->interval;
  310.  
  311. if (__builtin_expect ((!!(nat == at)),()))
  312. {
  313. at = ((loop)->ev_rt_now);
  314. break;
  315. }
  316.  
  317. at = nat;
  318. }
  319.  
  320. ((WT)(w))->at = at;
  321. }
  322.  
  323. static inline void
  324. periodics_reify (struct ev_loop *loop)
  325. {
  326. do { } while ();
  327.  
  328. while (((loop)->periodiccnt) && (((loop)->periodics) [( - )]).at < ((loop)->ev_rt_now))
  329. {
  330. do
  331. {
  332. ev_periodic *w = (ev_periodic *)(((loop)->periodics) [( - )]).w;
  333.  
  334. if (w->reschedule_cb)
  335. {
  336. ((WT)(w))->at = w->reschedule_cb (w, ((loop)->ev_rt_now));
  337.  
  338. (__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));
  339.  
  340. (((loop)->periodics) [( - )]).at = (((loop)->periodics) [( - )]).w->at;
  341. downheap (((loop)->periodics), ((loop)->periodiccnt), ( - ));
  342. }
  343. else if (w->interval)
  344. {
  345. periodic_recalc (loop, w);
  346. (((loop)->periodics) [( - )]).at = (((loop)->periodics) [( - )]).w->at;
  347. downheap (((loop)->periodics), ((loop)->periodiccnt), ( - ));
  348. }
  349. else
  350. ev_periodic_stop (loop, w);
  351.  
  352. do { } while ();
  353. feed_reverse (loop, (W)w);
  354. }
  355. while (((loop)->periodiccnt) && (((loop)->periodics) [( - )]).at < ((loop)->ev_rt_now));
  356.  
  357. feed_reverse_done (loop, EV_PERIODIC);
  358. }
  359. }
  360.  
  361. static void __attribute__ ((__noinline__))
  362. periodics_reschedule (struct ev_loop *loop)
  363. {
  364. int i;
  365.  
  366. for (i = ( - ); i < ((loop)->periodiccnt) + ( - ); ++i)
  367. {
  368. ev_periodic *w = (ev_periodic *)(((loop)->periodics) [i]).w;
  369.  
  370. if (w->reschedule_cb)
  371. ((WT)(w))->at = w->reschedule_cb (w, ((loop)->ev_rt_now));
  372. else if (w->interval)
  373. periodic_recalc (loop, w);
  374.  
  375. (((loop)->periodics) [i]).at = (((loop)->periodics) [i]).w->at;
  376. }
  377.  
  378. reheap (((loop)->periodics), ((loop)->periodiccnt));
  379. }
  380.  
  381. static void __attribute__ ((__noinline__))
  382. timers_reschedule (struct ev_loop *loop, ev_tstamp adjust)
  383. {
  384. int i;
  385.  
  386. for (i = ; i < ((loop)->timercnt); ++i)
  387. {
  388. ANHE *he = ((loop)->timers) + i + ( - );
  389. (*he).w->at += adjust;
  390. (*he).at = (*he).w->at;
  391. }
  392. }
  393.  
  394. static inline void
  395. time_update (struct ev_loop *loop, ev_tstamp max_block)
  396. {
  397. {
  398. ((loop)->ev_rt_now) = ev_time ();
  399.  
  400. if (__builtin_expect ((!!(((loop)->mn_now) > ((loop)->ev_rt_now) || ((loop)->ev_rt_now) > ((loop)->mn_now) + max_block + .)),()))
  401. {
  402.  
  403. timers_reschedule (loop, ((loop)->ev_rt_now) - ((loop)->mn_now));
  404.  
  405. periodics_reschedule (loop);
  406.  
  407. }
  408.  
  409. ((loop)->mn_now) = ((loop)->ev_rt_now);
  410. }
  411. }

还没看,以后可能也不会看了

libev 宏展开的更多相关文章

  1. C语言中的宏展开

    #include<stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf(,) ...

  2. Visual Studio 查看宏展开

    使用Visual Studio 开发c++项目,中遇到项目中宏定义套宏定义,难以阅读源代码的时候. 可在 项目-->右键-->配置属性-->c/c++ -->预处理器 --&g ...

  3. gcc将c源文件中的宏展开

    1: sudo gcc -P -I. -I../instrument/stubs -I../instrument/stubs -I../ -E ctrl_xfer32.cc -o preprocess ...

  4. C\C++语言中的宏多重展开和递归展开

    宏定义中的#,## 1. 宏中的参数前面使用一个#,预处理器会把这个参数转换为一个字符数组     2.记号粘贴操作符(token paste operator): ##            “## ...

  5. 可变参数宏__VA_ARGS__

    在 GNU C 中,宏可以接受可变数目的参数,就象函数一样,例如:#define pr_debug(fmt,arg...) \printk(KERN_DEBUG fmt,##arg) 用可变参数宏(v ...

  6. C/C++ 宏中的 #、#@、##的作用

    宏中的# 功能是将其后面的宏参数进行字符串化操作(Stringizing operator), 简单说就是在它引用的宏变量的左右各加上一个双引号. #define STRING(x) #x 下面二条语 ...

  7. linux内核宏container_of

    首先来个简单版本 /* given a pointer @ptr to the field @member embedded into type (usually * struct) @type, r ...

  8. C,C++宏中#与##的讲解[转]

    MoreWindows 专注于Windows编程 C,C++宏中#与##的讲解 文中__FILE__与示例1可以参见<使用ANSI C and Microsoft C++中常用的预定义宏> ...

  9. 宏定义中的##操作符和... and _ _VA_ARGS_ _

    1.Preprocessor Glue: The ## Operator 预处理连接符:##操作符 Like the # operator, the ## operator can be used i ...

随机推荐

  1. Python入门1

    简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为ABC 语言的一种继承.Python ...

  2. 报错:严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [/index.jsp (line: 13, column: 20) No tag "textfiled" defined in tag library imported with prefix

    严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [ ...

  3. Oracle存储过程 输出参数赋值异常:“Oracle.DataAccess.Types.OracleString”的类型初始值设定项引发异常。

    场景: 写了一个有返回参数的存储过程,在个另开发人员机器上都正常.其它机器报如题错误.让人郁闷的是,所有调用方都是客户端,根本不存在网上众贴所说的版本不一致问题. 分析: 虽然网上的帖子没有根本解决问 ...

  4. IE10、IE11解决不能播放Flash的问题!

    http://jingyan.baidu.com/article/154b46315421b528ca8f41e4.html ie的问题向来是windows系统的传统问题之一.几乎每个版本的windo ...

  5. MEF load plugin from directory

    var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(".")); var ...

  6. 异常:Message 850 not found; No message file for product=network, facility=NL解决方案

    一.异常信息:   Message 850 not found; No message file for product=network, facility=NL    二.解决方案:     后来在 ...

  7. [翻译]用神经网络做回归(Using Neural Networks With Regression)

    本文英文原文出自这里, 这个博客里面的内容是Java开源, 分布式深度学习项目deeplearning4j的介绍学习文档. 简介: 一般来说, 神经网络常被用来做无监督学习, 分类, 以及回归. 也就 ...

  8. Thinkphp源码分析系列(一)–入口文件

    正如官方文档上所介绍的,thinkphp使用单一入口,所有的请求都从默认的index.php文件进入.当然不是说一定非得从index.php进入,这应该取决于你的服务器配置,一般服务器都会有默认的首页 ...

  9. swift 常见报错及解决方案

    当你初学swift,或者你从2.0转到3.0,见点红是在所难免再寻常不过的事情,其实一般也都是一些小的语法问题,度娘一般都有能力告诉你答案,但是凡事做个总结做到心中有数毕竟是比度娘靠谱的. 1.can ...

  10. 【229】Raster Calculator - 栅格计算器

    参考:分段函数进行复制,利用语句 参考:ArcGIS栅格计算器 - CSDN 参考:ArcGIS栅格计算器con条件函数使用 参考:ArcGIS栅格计算器 - 电脑玩物 ("lyr" ...