cxx11emu.h 和 logprint.h
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
cxx11emu.h 和 logprint.h的更多相关文章
- sys/types.h fcntl.h unistd.h sys/stat.h
sys/types.h 是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型. 在应用程序源文件中包含 <sys/types.h> 以访问 ...
- 单片机中用c编程时头文件reg51.h及reg52.h解析
单片机中用c编程时头文件reg51.h及reg52.h解析 我们在用c语言编程是往往第一行就是reg51.h或者其他的自定义头文件,我们怎么样来理解呢? 1)“文件包含”处理. 程序的第一行是一个“文 ...
- windows.h和winsock2.h包含顺序问题(转)
windows.h和winsock2.h有类型重定义我是知道的,本来就一个库来说没问题,把winsock2放到windows.h前或先定义WIN32_LEAN_AND_MEAN都能解决问题但现的出了问 ...
- VS2013使用winsock.h和winsock2.h发生冲突后的终极解决方法
问题:彻底无语了,不小心某个文件包含了windows.h头文件,而windows.h文件里面包含着winsock.h文件, 如果你下次使用winsock2.h文件时,位置不对,然后编译器会给你一大堆重 ...
- [转]rpcndr.h和wtypes.h冲突Bug的解决方案
[转]rpcndr.h和wtypes.h冲突Bug的解决方案 http://blog.csdn.net/tzwh_86/article/details/9495133 rpcndr.h和wtypes. ...
- 已经包含了#include <atlcom.h> #include <comutil.h>还是报错
在WTL工程的.h中 #include <atlbase.h>#include <atlcom.h>#include <atlcomcli.h>#include & ...
- c语言string.h和memory.h某些函数重复问题
在C语言中,为了使用memset()函数,你是选择#include <string.h>还是<memory.h>?两个都可以,如何选择? <string.h>,标准 ...
- 解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载
解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载 当这两个头文件顺序颠倒时,编译会出现许多莫名其妙的错误,错误如下: 1>…\include\ws2def.h( ...
- 清北学堂入学测试P4751 H’s problem(h)
P4751 H’s problem(h) 时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 小H是一个喜欢逛街的女孩子,但是由于上了大学 ...
随机推荐
- HttpClient介绍和简单使用流程
HttpClient SpringCloud中服务和服务之间的调用全部是使用HttpClient,还有前面使用SolrJ中就封装了HttpClient,在调用SolrTemplate的saveBean ...
- Dubbo+zookeeper实现单表的增删改查
1.数据库准备 建表语句 CREATE TABLE `tb_brand` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) DEFAULT NULL COMMENT ...
- 怎么对ORACLE里的CLOB字段进行模糊查询
select b.* from oss_service_log a left join oss_service_log_detail b on a.pk_log = b.pk_log where a. ...
- mocha单元测试简易教程
mocha单元测试简易教程 写在前面 其实mocha单元测试的教程网上有很多,也都很简单易懂,但是每个人对同一份的教程也会产生不同的理解,像我这种大概就是走遍了所有弯路才到达终点的人,想通过给大家分享 ...
- sqlite3 线程模型
官网:https://www.sqlite.org/c3ref/open.html 转载:https://blog.csdn.net/yifanernei/article/details/564212 ...
- oracle系列九 SET运算符查询
将多个查询用 SET 操作符连接组成一个新的查询 UNION/UNION ALL INTERSECT MINUS 排序:ORDER BY UNION 操作符 UNION 操作符返回两个查询的结果集的并 ...
- too many positional arguments错误
在window下mongodb默认安装在c盘的Program Files文件下 这个文件名中间有个空格 就导致了接下来too many positional arguments错误的产生
- Spring cloud微服务安全实战-6-10sentinel之热点和系统规则
热点规则 热点就是经常访问的数据.很多时候我们希望争对某一些热点数据,然后来进行限制.比如说商品的信息这个服务,我们给它做一个限流,qps是100,某一天我想做一个秒杀活动,可能会有很大的流量,这个时 ...
- 【JS】AJAX跨域-JSONP解决方案(一)
AJAX跨域介绍 AJAX 跨域访问是用户访问A网站时所产生的对B网站的跨域访问请求均提交到A网站的指定页面 由于安全方面的原因, 客户端js使用xmlhttprequest只能用来向来源网站发送请求 ...
- 【Redis】Redis 事务
Redis 事务介绍 Redis 事务可以一次执行多个命令, 并且带有以下三个重要的保证: 批量操作在发送 EXEC 命令前被放入队列缓存. 收到 EXEC 命令后进入事务执行,事务中任意命令执行失败 ...