CurrentThread 类 主要实现 获取当前线程的tid,并在类中保存,后续在ThreadPool中查询时,做一次判断即可。不用每次都查询tid.
Linux多线程编程工具库liblmp_tool github: https://github.com/Dwyane05/liblmp_tool
头文件实现:
/*
* Use of this source code is governed by a BSD-style license
* that can be found in the License file.
*
* CurrentThread.h
* Created on: May 30, 2019
* Author: cuiyongfei
*/
#ifndef LMP_TOOL_CURRENTTHREAD_H
#define LMP_TOOL_CURRENTTHREAD_H
#include "Common.h"
namespace lmp_tool
{
namespace CurrentThread
{
// internal
extern __thread int t_cachedTid;
extern __thread char t_tidString[32];
extern __thread int t_tidStringLength;
extern __thread const char* t_threadName;
void cacheTid();
inline int ti