example.c
00044: static
pthread_t g_module_owner = INVALID_THREAD;
00045:
00046: errno_t
module_api (int _parameter)
example.c
00044: static
pthread_t g_module_owner = INVALID_THREAD;
00045:
00046: errno_t
module_api (int _parameter)
00047: {
00048: if (g_module_owner
== INVALID_THREAD) {
00049: g_module_owner = pthread_self ();
00050: }
00051: else if (g_module_owner != pthread_self ()) {
00052: return ERRNO_CODE (ERRNO_NOTOWNER);
00053: }
00054:
00055: ...
00056: }
example.c
00299: typedef
struct tag_timer
00300: {
00301: expiration_cb_t cb_;
00302: char name_ [TIMER_NAME_MAX
+ 1];
00303: ...
00304: } timer_t;
00305:
00306: timer_t
timer_alloc (timer_handler_t
*_p_handler, msecond_t
00307: _duration, expiration_cb_t
_cb, const
char *_name, void *_p_arg)
00308: {
00309: timer_t *p_timer = malloc (sizeof (timer_t));
00310: ...
00311: return p_timer;
00312: }
00313:
00314: error_t
timer_free (timer_t
*_p_timer)
00315: {
00316: ...
00317: free (_p_timer);
00318: return 0;
00319: }
00320:
00321: void timer_fire ()
00322: {
00323: timer_t *p_timer;
00324: ...
00325: p_timer->cb_(p_timer, p_timer->arg_);
00326: ...
00327: }
example.c
00299: typedef
struct tag_timer
00300: {
00301: expiration_cb_t cb_;
00302: char name_ [TIMER_NAME_MAX
+ 1];
00303: bool deletion_pending_;
00304: bool is_in_callback_;
00305: ...
00306: } timer_t;
00307:
00308: timer_t
timer_alloc (timer_handler_t
*_p_handler, msecond_t
00309: _duration,expiration_cb_t
_cb, const
char *_name, void *_p_arg)
00310: {
00311: timer_t *p_timer =
malloc (sizeof
(timer_t));
00312: ...
00313: return p_timer;
00314: }
00315:
00316: error_t
timer_free (timer_t
*_p_timer)
00317: {
00318: ...
00319: if (_p_timer->is_in_callback_) {
00320: _p_timer->deletion_pending_ = true;
00321: }
00322: else {
00323: free (_p_timer);
00324: }
00325: return 0;
00326: }
00327:
00328: void timer_fire ()
00329: {
00330: timer_t *p_timer;
00331: ...
00332: p_timer->is_in_callback_ = true;
00333: p_timer->cb_(p_timer, p_timer->arg_);
00334: p_timer->is_in_callback_ = false;
00335: if (p_timer->deletion_pending_) {
00336: free (p_timer);
00337: }
00338: ...
00339: }
下一篇:出色技术团队的关键要素
有时候我们不想让其他网站链接我们的
看到社区很多都在讨论如何调试,如何高级的调试,以及一些调试的奇技淫巧,今天我想和大家聊聊,怎么禁止调试,禁止他人调试我们的程序~
(目录) 前言 最近在学习慕课网Geely老师的设计模式课程,做下笔记 概念 开闭原则的定义:软件实现对扩展开放,修改关闭
文章目录1.迪米特法则2.高内聚3.松耦合4.代码5.总结1.迪米特法则迪米特法则的英文翻译是:Law of Demeter,缩写是 LOD。单从这个名字上来看
了解一些经典的设计原则,并且将其应用到我们的日常开发中,会大大提高代码的优雅性、可扩展
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M