cxx11emu.h 和 logprint.h

/* Start of cxx11emu.h */

#ifndef STDBP_CXX11EMU_H_
#define STDBP_CXX11EMU_H_ #if defined(__cplusplus) || defined(c_plusplus) /// @todo Value may not be correct, because as of writing C++17 isn't official
#if __cplusplus >= 201703L
#define CPP17
#endif
#if __cplusplus >= 201402L
#define CPP14
#endif
#if __cplusplus >= 201103L
#define CPP11
#endif /* Namespace macros. It's sometimes necessary to put something into the "std"
* namespace. For example, a specialization of std::hash. These macros can be
* used to put the code in the correct namespace.
*/
#ifdef CPP17
#define CPP17_NAMESPACE std
#else
#define CPP17_NAMESPACE cpp17
#endif
#ifdef CPP14
#define CPP14_NAMESPACE std
#else
#define CPP14_NAMESPACE cpp14
#endif
#ifdef CPP11
#define CPP11_NAMESPACE std
#else
#define CPP11_NAMESPACE cpp11
#endif namespace cpp11
{
} #ifndef CPP11
namespace cpp11
{
class nullptr_t
{
public:
nullptr_t(): pad_()
{
} template< class T >
operator T*() const
{
return ;
} template< class C, class T >
operator T C::*( ) const
{
return ;
}
private:
void* pad_; /* std requires : sizeof(nullptr_t) == sizeof(void*) */
void operator&() const;
}; const cpp11::nullptr_t nullptr;
} namespace cpp11
{
/* Static assertions */
#ifndef static_assert
#define XXJOIN(x, y) XXJOIN_AGAIN(x, y)
#define XXJOIN_AGAIN(x, y) x##y
#define static_assert(exp) typedef char \
CONCATE(assertion_failed_at_line_, __LINE__)[(exp) ? : -]
#define static_assert2(exp, str) typedef char \
CONCATE(str##_at_Line, __LINE__)[(exp) ? : -]
#endif /* End of static_assert */
} // namespace cpp11 #endif /* End of CPP11 */ namespace cpp14
{
} namespace cpp17
{
} /* cpp points to either std or cpp11/14/17 as appropriate
*/
namespace cpp
{
using namespace ::std;
using namespace ::cpp11;
using namespace ::cpp14;
using namespace ::cpp17;
} #endif /* End of defined(__cplusplus) || defined(c_plusplus) */ #endif /* End of STDBP_CXX11EMU_H_ */ /* End of cxx11emu.h */
/* Start of logprint.h */

#ifndef UTIL_LOGPRINT_H_
#define UTIL_LOGPRINT_H_ #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h> /**
* 在使用 FreeBSD 平台上, 使用 -pthread (注意,没有'l') 参数,
* gcc 会自动链接系统当前版本推荐的 thread lib 以及对应的 thread safe 的 c func。
* 参考: http://www.zeroc.com/forums/help-center/4334-ice-freebsd.html
* 参考: http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html
*
* 注意:FreeBSD 中,其实包含了 libc_r, libthr, libpthread(libkse) 三个版本的多线程库。
* lib_r, Reentrant C Library,最老的版本,基本废弃。
* libthr, 1:1 thread model,8.0 开始,它就是默认的库。
* libpthread(libkse), M:N thread model,6.x, 7.x 下的默认库。
* 其中 libpthread 默认使用的是 PTHREAD_SCOPE_PROCESS,而 libthr 用的是 PTHREAD_SCOPE_SYSTEM。
* 理论上来说,libthr 在多核状态下,且服务器主要就跑你的程序的时候,能更好的利用 cpu。
* 参考: http://kasicass.blog.163.com/blog/static/395619200911289639311
*
*/
#include <pthread.h> #if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif /* End of defined(__cplusplus) || defined(c_plusplus) */ #define LOGPRINT_PATHNAME "logprint.log"
#define LOGPRINT_STRING_LEN (1024u) int g_log_fd;
char g_msg_buf[LOGPRINT_STRING_LEN];
pthread_mutex_t g_log_mutex; #ifdef _LOGPRINT_ #define LOGPRINT(fmt, args...) \
do \
{ \
pthread_mutex_lock(&g_log_mutex); \
g_log_fd = open(LOGPRINT_PATHNAME, O_WRONLY | O_CREAT | O_APPEND, ); \
sprintf(g_msg_buf, "pid(%d):tid(%lu):file(%s):func(%s):line(%d) - " fmt, \
(int)getpid(), (unsigned long int)pthread_self(), \
__FILE__, __func__, __LINE__, ##args); \
write(g_log_fd, g_msg_buf, strlen(g_msg_buf)); \
close(g_log_fd); \
pthread_mutex_unlock(&g_log_mutex); \
} while () #else #define LOGPRINT(fmt, args...) NULL #endif /* End of _LOGPRINT_ */ #if defined(__cplusplus) || defined(c_plusplus)
} // End of extern "C"
#endif /* End of defined(__cplusplus) || defined(c_plusplus) */ #endif /* End of UTIL_LOGPRINT_H_ */

================ End

最新文章

  1. Python自动化 【第四篇】:Python基础-装饰器 生成器 迭代器 Json &amp; pickle
  2. PAAS平台的web应用性能测试与分析
  3. 怎样用ZBrush中复数对象进行工作
  4. JavaScript案例四:全选练习
  5. Gearman 安装使用教程
  6. EditPlus自动补全、模板配置
  7. 【Windows 8】pid为4的system进程占用80端口的解决办法
  8. BZOJ1653: [Usaco2006 Feb]Backward Digit Sums
  9. BZOJ 1191: [HNOI2006]超级英雄Hero(二分图匹配)
  10. 探索WebKit核心(一)------ 新秀开始
  11. 微信小程序前置课程:flex布局(二)
  12. 前端基本知识(二):JS的原始链的理解
  13. DotNetCore跨平台~EFCore连接Mysql的方式
  14. Sublime Text3快捷键
  15. 【一天一道LeetCode】#344. Reverse String
  16. JS window对象的top、parent、opener含义介绍(转载)
  17. Ducci 队列 -基础queue,set
  18. SpringBoot系列: 所有配置属性和官方文档
  19. Java进程&线程(整理)
  20. C#面向对象之封装。

热门文章

  1. Android中创建自定义控件
  2. 更改matlab默认精度
  3. ELK平台搭建及日志监控
  4. hdu5438 Ponds[DFS,STL vector二维数组]
  5. [源码分析]LinkedHashMap
  6. python-使用阿里云镜像加速
  7. java查看线程的堆栈信息
  8. SUSE操作系统,如何查看操作系统版本?
  9. 【Linux】宝塔服务器磁盘爆满处理方法
  10. OutOfMemoryError异常——Java堆溢出。