自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(181)
  • 资源 (38)
  • 收藏
  • 关注

原创 Promise.cpp

同一宏下,`Promise-inl.h` 声明 `extern template class Promise<Unit>;这个 TU 在启用 extern-template 优化时,为最常见的 `Promise<Unit>` 提供唯一显式实例化定义,集中模板代码生成并与 `Promise-inl.h` 的 extern declaration 配对。- `Promise<void>`、任意业务 T 以及 `Future<Unit>`/`Core<Unit>` 是独立模板特化,由各自源文件或使用点负责。

2026-08-10 09:54:38 81

原创 SharedPromise.cpp

SharedPromise-inl.h 在同一宏下提供对应的 extern template 声明,使包含头文件的其他翻译单元不必各自发射这组常用成员;这个优化要求库与使用方对宏的取值一致:使用方若只看见 extern 声明而库中没有相应定义,使用到的非内联符号可能无法链接;理解它的关键不在“执行了什么”,而在它与头文件中的 extern template 声明怎样共同改变各翻译单元的代码生成。- 它只覆盖 Unit 特化,不替代 SharedPromise<T> 对其他业务类型的按需实例化。

2026-08-10 09:52:13 85

原创 BenchmarkCompare.cpp

第 56 行只取 `argv[1]`、`argv[2]`,额外参数被忽略。函数先创建字符串并调用 `readFile(filename.c_str(), content)`,再 `parseJson(content)` 得到 dynamic,最后由 `benchmarkResultsFromDynamic` 填入 `vector<detail::BenchmarkResult>`。`json/json.h` 提供 `parseJson`。## 第 36–45 行:`resultsFromFile`

2026-08-10 08:22:59 89

原创 ScopedTraceSection.h

名字拼成 `folly_sdt_semaphore_provider_name`,C linkage、volatile unsigned short、used且置于 `.probes`,使tracer能按地址修改。`StaticTracepointTest`读取最终可执行文件note,`SectionTest`确认链接后 `.stapsdt.base` 仍存在,二者正好覆盖产物层。`FOLLY_SDT` 将provider/name、无semaphore标志、0–9参数数目传给底层宏。

2026-08-10 08:21:28 136

原创 AsyncStack.h

大幅图示是设计核心:TLS 指向最内层 `AsyncStackRoot`,root 的 `nextRoot` 串联嵌套 event loop;`tryGet` 可空,`getCurrent` 要求 root 存在;内部 `ScopedAsyncStackRoot` 构造时把自身压到 TLS root 链,析构要求它仍是当前 root且已无 top frame,再恢复 nextRoot。root 同样不可移动。frame 往往嵌入堆上的 coroutine frame,所以逻辑链可以跨越线程栈生命周期。

2026-08-10 08:19:52 147

原创 AsyncStack.cpp

Indestructible持有 `Synchronized<unordered_set<Frame*>>`,首次建立时把集合裸地址写给extern C符号,保证进程终止阶段也不析构。它只作标记,绝不能解引用。双层noinline函数取得能解析到 `detached_task` 的地址,并用 compiler_must_not_elide阻止尾调用。实现文件负责三件不能只靠结构体完成的事:建立调试器可发现的 TLS root、构造 detached frame 的可符号化地址,以及维护挂起叶全局集合。

2026-08-10 08:19:18 176

原创 AsyncStack-inl.h

checkAsyncStackFrameIsActive` 要求 frame 有 root、root 等于当前线程TLS root、root 的 top正是 frame。pop先保存caller/root,把root写回caller,再 release发布caller为top,最后清callee.root。它的重点不是普通 getter,而是 push/pop 时 `stackRoot` 所有权在链顶 frame 间转移,以及 `topFrame` 以 release 发布。- 源文件:156 行。

2026-08-10 08:18:45 139

原创 uuid.h

本文件把规范文本 UUID `8-4-4-4-12` 的 36 个 ASCII 字符解析为 16 个原始字节,提供 scalar、SSSE3、AVX2 三条路径。连字符验证通过比较第一加载块中的 `'-'` 位图,再与“非连字符期望 mask”异或,构造全 1 的正确性 mask。先取每 byte 高半字节,用 16 项 shuffle 表选择 `'0'`、`'A'-10` 或 `'a'-10` 偏移,相减得到 0..15 nibble。两个解析寄存器各产 8 字节,两个验证 mask 合成 32 位;

2026-08-10 08:14:55 197

原创 hex.h

hex_decoded_digit_is_valid(v)` 检查高位未置位。`hex_is_digit`、`hex_decode_digit_raw`、`hex_decode_digit` 使用编译期 `kIsArchAArch64` 选择 flavor;安全 decode 可用 `hex_decoded_digit_is_valid` 检查 sentinel。判定分别计算 `h-'0'` 与 `(h|0x20)-'a'`,unsigned 下溢自然变大,比较 `<10/<6` 同时完成上下界检查;

2026-08-10 08:14:19 153

原创 Conv.h

整数目标丢弃子秒,但负值要向 0 截断:`{-5,123456ns}` 表示 -4.999876544 秒,转 seconds 应为 -4,因此第 431–438 行给负 sec 加 1。本文件在 POSIX `timespec/timeval` 与 `std::chrono::duration/time_point` 之间做带溢出检查的双向转换。范围溢出返回 `Expected<...,ConversionCode>`,而 `to<T>` 再把错误提升为 `range_error`。

2026-08-09 10:00:42 15

原创 Hardware.h

Clang 11+ 支持 `asm volatile inline`,旧版退回 `asm volatile`。`SharedMutex`、`DistributedMutex` 和 `TurnSequencer` 用它计算自旋/等待经过 tick;measurement_start/stop 则使用编译器屏障、LFENCE 和 RDTSC/RDTSCP,构造适合微基准的测量边界。MSVC 路径在 RDTSC 前后放 `_ReadWriteBarrier` 与 `_mm_lfence`。

2026-08-09 10:00:07 113

原创 Clock.h

第 21–27 行解释为什么使用 `folly::chrono` 而非直接在 folly 根命名空间定义 SteadyClock/SystemClock:大量代码可能同时 `using namespace folly` 并定义 chrono 别名,独立命名空间减少名字冲突。接口没有暴露 duration、is_steady 等完整 Clock concept 成员,因此它是依赖注入对象,不是可直接替换 `std::chrono::steady_clock` 模板参数的静态 clock 类型。

2026-08-09 09:59:32 59

原创 StableRadixSort.h

注释第 43/355 行把 pass 数写成 `sizeof(key)/8`,实际代码 `kRadixPasses=sizeof(Key)`,即每字节一 pass;`extractRadixDigit(key,pass)` 右移 `pass*8` 后取低 8 位,pass 0 因而是最低有效字节。浮点公开文档明确是 augmented ordering:普通不等值遵循 `<`,相等时负 signbit 排在前,因此 `-0.0` 在 `+0.0` 前。每个元素保存一次投影 key,向前与前项比较。

2026-08-09 09:57:04 84

原创 MoveMask.h

原因是 `_mm_movemask_epi8` 每字节提取一个最高位:一个 16 位比较 lane 的两个字节都会是 `0xff`,因此产生两个相邻 1。`bitsPerElement` 是 `integral_constant`,调用 `bitsPerElement()` 得到常量,编译器可直接折叠后续乘除。第 175–179 行处理已经是 64 位总宽度的向量:直接抽取 64 位,并用 `sizeof(Scalar)*8` 表示每 lane 占用的位数。第 38 行进入 `folly::simd`。

2026-08-09 09:56:30 147

原创 Ignore.h

第 46–47 行默认都为 0,使默认构造对象语义上等价于“不忽略任何 lane”,但类型仍是 `ignore_extrema`,下游会走可裁剪的通用路径。- `ignore_extrema`:最前面的 `first` 个和最后面的 `last` 个 lane 是填充或区间外数据。若 `[f,l)` 完全落在同一寄存器块内,第 2 步不会发生,最终对象会同时保留 `first` 和 `last`。字段用 `int` 而非 `size_t`,与 SIMD cardinal 及差值计算的接口保持一致。

2026-08-09 09:55:58 156

原创 FindFixed.h

示例第 68 行注释把变量写成 `m0`,应为 `m1`,不影响代码。若 N=13、元素 1 byte、寄存器上限 16 byte:`bit_floor(13)=8`,搜索 `[0,8)` 和 `[5,13)`。`find8bytes` 先 memcpy 到 uint64,随后用 `_mm_set1_epi64x` 将这 8 字节复制到 128 位两半,再复用 16-byte 比较。复制不会改变最低半部的首结果。先搜索头部 `[0,kRegSize)`,未命中再搜索尾部 `[N-kRegSize,N)`。

2026-08-09 09:55:27 157

原创 find_first_of.h

stdfind_scalar_finder_first_of` 保存 alphabet span,调用 `std::find_first_of(input[pos..],alphabet)`,再用迭代器差返回相对原 input 的索引。搜索时取输入低 4 位作为 `_mm_shuffle_epi8`/`vqtbl1q_u8` 索引,再将查到的完整 byte 与原输入比较,避免只比较低半字节造成碰撞。退出 detail 后,为每种策略发布 `basic_*<CharT>` 和 char 专用别名。

2026-08-09 09:54:53 167

原创 find_first_of_extra.h

rngfind_vector_finder_first_of` 同样保存 alphabet;调用 `crange(input).find_first_of(crange(alphabet_),pos)`,利用 Range 内部 x86 加速。Range 以 `size_t(-1)` 表示未找到,本适配器转换为 finder 体系统一的 `input.size()`。它只支持 first-of,因为标准库没有对应 execution-policy `find_first_not_of` 接口。

2026-08-09 09:54:13 231

原创 BinaryHeap.h

第 44–46 行用 `comp(right,left)` 选择更符合堆顶方向的孩子:默认 less 下,若 right<left 选 left,否则选 right,即选较大者。若 `comp(heap_top,chosenChild)`,说明保存的根比孩子优先级低:把孩子 move 到当前洞,洞下移到 child。对无孩子节点,`--child<size` 为 false;`parent` 始于 0,`child` 将保存右孩子索引。数组堆的左、右孩子分别为 `2p+1`、`2p+2`。

2026-08-09 09:53:21 140

原创 Contains.h Contains.cpp

folly/algorithm/simd/Contains.cpp 提供四个固定宽度的非模板调用边界。使用 if constexpr 很重要:如果 haystack 本身不合法,后面的 std_range_value_t<R> 不会被实例化,避免产生额外模板错误。即使后面的固定类型入口是 noexcept,从函数类型角度看,公共 operator() 仍是潜在抛出函数。对于临时范围,这里通常是安全的:转换出的 span 只在当前调用内使用,搜索结束前临时范围仍然存活,不会像“返回 span”那样发生悬空。

2026-08-08 10:22:07 87

原创 UnrollUtils.h

因为数组是 const,所以 op 实际收到的是 const T& 或由它转换出的值,不能通过该接口修改输入数组元素。第三个函数参数本身不保存数据,只用于让编译器从其类型中推导 i...,所以没有参数名,并标注 /*unused*/。注释指出:即使循环次数是一个很小的编译期常量,编译器有时仍然不会展开循环,或者展开结果不理想。初始化列表元素按从左到右的顺序求值,所以 op(x[0])、op(x[1]) 等调用顺序明确。这与真实调用 op(x[i]) 的参数性质一致,因为 x 是 const 数组。

2026-08-08 10:18:25 173

原创 SIMD Traits.h

对于相等比较等按位操作,符号不影响正确性。3. unsigned_simd_friendly_equivalent_scalar_t 把整数、枚举和指针统一成等宽无符号整数。后面的类型别名会先使用 std::remove_const_t<T>,因此普通的顶层 const 会被移除后再传入。simd_friendly_equivalent_scalar_t<MyStruct> // 替换失败。simd_friendly_equivalent_scalar_t<int> // 有效。

2026-08-08 10:15:04 182

原创 SimdPlatform.h

公共层目前只允许 `uint8_t` 使用 `less_equal`。`SimdAnyOf.h` 和 `ContainsImpl.h` 因此不需要直接区分 `_mm_*`、`_mm256_*` 和 `v*` NEON 指令。5. NEON Specific 层实现了四种宽度的 `less_equal`,但 Common 层为了跨平台一致性只开放 `uint8_t`。`ContainsImpl.h` 就借此避免实例化 SIMD 分支,改用 `memchr`、`wmemchr` 或 `std::find`。

2026-08-08 10:11:57 163

原创 SimdAnyof.h

所以 SimdAnyOf.h 的核心职责是:把 SimdForEach 提供的“寄存器遍历能力”,包装成具有 any_of 语义的“加载—谓词—合并—归约—提前退出”流程。这种设计还有一个性能优势:对于 N 个寄存器,只执行一次相对昂贵的横向 any/movemask 操作,而不是每个寄存器执行一次。在 SSE/AVX 中,这通常不是四个 C++ bool,而是一个整数 SIMD 寄存器,其中匹配 lane 的所有位为 1。是安全的,因为一旦结果为 true,下一行就会要求遍历立即终止;

2026-08-08 10:00:17 221

原创 SimdForEach.h

如果原始地址有效,把它向下对齐到一个较小 SIMD 边界,通常仍位于同一页,因此硬件读取不会跨入未映射页面。区间外的 SIMD lane 不会单独避免读取,而是通过 ignore_extrema 标记为无效,让 delegate 在计算结果时忽略它们。这些内部模板被强制内联,目的是让最终算法集中在一个明确的顶层函数边界中,避免编译器意外留下多层 SIMD 辅助函数调用。如果 af == al,代码不会进入此分支,所以同一块同时作为首尾块时,原来的 ignore.first 会保留下来。

2026-08-08 09:56:42 223

原创 ContainsImpl.h

值得注意:注释说的是 FOLLY_ERASE,但本文件实际使用的是 FOLLY_ALWAYS_INLINE。这里的 static_cast<T>(needle) 从类型上看是冗余的,因为 needle 已经是 T,可能是为了明确匹配平台接口的标量类型。- Platform::reg_t 在 SSE/AVX 上通常是 __m128i/__m256i,在 ARM 上是对应 NEON 向量类型。这是一个偏底层的优化技巧,依赖目标平台相同宽度整数与 wchar_t 的对象表示和库实现行为。

2026-08-08 09:52:33 234

转载 [zz】分布式系统的raft算法

原帖地址:https://www.jdon.com/artichect/raft.html 分布式系统的Raft算法  过去, Paxos一直是分布式协议的标准,但是Paxos难于理解,更难以实现,Google的分布式锁系统Chubby作为Paxos实现曾经遭遇到很多坑。  来自Stanford的新的分布式协议研究称为Raft,它是一个为真实世界应用建立的协议,主要注重协议的落地性...

2018-09-21 16:12:12 506 1

转载 【zz】Recv-Q&Send-Q

 原帖地址:https://blog.youkuaiyun.com/acmer1183/article/details/52014216 最近线上某些服务器老是报cpu load高,同机房其他机器却没有问题。排查发现以下异常ss -nlRecv-Q Send-Q                 Local Address:Port                   Peer Addr...

2018-09-18 11:05:27 562

转载 【zz】dpdk全面分析

文章转载自https://www.cnblogs.com/bakari/p/8404650.htmlPS:欢迎大家关注我的公众号:aCloudDeveloper,专注技术分享,努力打造干货分享平台,二维码在文末可以扫,谢谢大家。高性能网络技术随着云计算产业的异军突起,网络技术的不断创新,越来越多的网络设备基础架构逐步向基于通用处理器平台的架构方向融合,从传统的物理网络到虚拟网络,从...

2018-09-10 08:55:32 6939

原创 brpc:countdown event acquire release

 acquire 是要求下面的语句不能优化后跑到上面来;release是要求上面的语句优化后,不能跑到下面去; // bthread - A M:N threading library to make applications more concurrent.// Copyright (c) 2016 Baidu, Inc.// // Licensed under the A...

2018-09-07 11:15:25 663

转载 [zz]Acquire and Release Semantics

http://preshing.com/20120913/acquire-and-release-semantics/Acquire and Release SemanticsGenerally speaking, in lock-free programming, there are two ways in which threads can manipulate shared memo...

2018-08-13 18:53:32 342

转载 [zz]The Synchronizes-With Relation

 from:http://preshing.com/20130823/the-synchronizes-with-relation/ The Synchronizes-With RelationIn an earlier post, I explained how atomic operations let you manipulate shared variables con...

2018-08-13 18:52:51 576

转载 【zz】浅析C++多线程内存模型

 原地址:http://www.parallellabs.com/2011/08/27/c-plus-plus-memory-model/ 浅析C++多线程内存模型注:本文发表于《程序员》2011年第6期并行编程专栏,略有删改。在即将到来的C++1x标准中,一个重大的更新就是引入了C++多线程内存模型。本文的主要目的在于介绍C++多线程内存模型涉及到的一些原理和概念,以帮助...

2018-08-13 18:17:09 885

转载 log2ceiling and log2floor from brpc bits.h

// Copyright (c) 2009 The Chromium Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.// This file defines some bit ...

2018-08-08 16:42:51 431

转载 【zz】借助backtrace和demangle实现异常类Exception

转载自:http://www.codeweblog.com/%E5%80%9F%E5%8A%A9backtrace%E5%92%8Cdemangle%E5%AE%9E%E7%8E%B0%E5%BC%82%E5%B8%B8%E7%B1%BBexception/ C++的异常类是没有栈痕迹的,如果需要获取栈痕迹,需要使用以下函数:#include &lt;execinfo.h&gt;...

2018-08-08 16:30:29 314

原创 brpc DoublyBufferedData

ScopedPtr  析构时自动释放,本线程的锁。  保存一个wrapper到本地线程的私有变量里,析构时删除。双缓冲,空间换时间,一个用来读,一个用来写,写完后切换一下。_index 保存了读取的对象的下标。bg_index为写的对象的下标。分别为0和1,所以bg_index=!_indexWrapper 每个读线程一个。读取时,从线程本地变量中读取,如果有,则直接获取。如果没有...

2018-08-07 09:31:29 1679

原创 rdkafka 使用案例

main.cpp#include &lt;iostream&gt;#include &lt;ctype.h&gt;#include &lt;signal.h&gt;#include &lt;string.h&gt;#include &lt;unistd.h&gt;#include &lt;stdlib.h&gt;#include &lt;syslog.h&gt;#include

2018-07-30 13:46:41 3380

原创 gzip 压缩解压代码示例

#include &lt;zlib.h&gt;#include &lt;iostream&gt;#include &lt;stdint.h&gt;#include &lt;string.h&gt;#include &lt;stdlib.h&gt;using namespace std;#define RD_GZ_CHUNK  262144#define RD_ZERO_INIT...

2018-07-25 11:45:46 1441

转载 Linux Dynamic Shared Library && LD Linker

原帖地址: https://www.cnblogs.com/LittleHann/p/4244863.htmlLinux Dynamic Shared Library &amp;&amp; LD Linker目录1. 动态链接的意义2. 地址无关代码: PIC3. 延迟版定(PLT Procedure Linkage Table)4. 动态链接相关结构5. 动态链接的步骤和实现6. Li...

2018-07-10 08:29:06 722

转载 [zz]美团点评智能支付核心交易系统的可用性实践

原文地址: https://www.cnblogs.com/xiexj/p/8886356.html 背景每个系统都有它最核心的指标。比如在收单领域:进件系统第一重要的是保证入件准确,第二重要的是保证上单效率。清结算系统第一重要的是保证准确打款,第二重要的是保证及时打款。我们负责的系统是美团点评智能支付的核心链路,承担着智能支付100%的流量,内部习惯称为核心交易。因为涉及美团点评所有线下交易商家...

2018-06-08 12:19:03 522

evpp based echo server

simple net framework , echo server use qihoo360 open source code evpp

2018-05-03

thrift server support db operation and rest protocol

modified thrift server , support rest , http protocol with json content . support multi oracle db

2018-01-18

simple exchange platform client

a simple exchange platform client, not used. experimental product

2018-06-01

lua and acl example

lua call c++, c++ call lua, c++ call lua with lua call c++ so

2018-02-06

nonblocking switch server

fix bugs when packets are too large. improve performance too

2018-06-07

event_server

event server with high performance logger ,async write

2018-05-09

pddl thrift AccessServer

p distributed database framework AccessServer is the wrapper

2018-01-23

nonblocking async transfer server

nonblocking using lock_free queue , evpp framework

2018-05-30

thrift example

thrift server. use client connection pool. singleton conf , async logger and utility classes

2018-01-04

tdx market quotes getter

tdx market quotes caller, test which quote is faster

2017-11-21

AnalyzeServer 20180109 with DBConnPool

thrift with DBConnPool using Pro*C ThriftClientPool mem_func logger

2018-01-09

libevent echo server

libevent example. echo server. use c++11 gcc 4.8.5 thread_pool singleton , io thread , servant thread layer

2018-04-24

BinaryRecorder

Binary protocol implemented。 just an example. async logger

2017-11-21

log file tailer

like linux tail -f command. tail file and format to another line

2017-11-21

quick fix tester

use quick fix framework to test step protocol. an example for fun

2017-11-21

Logic business module Tester

lbm caller exapmle use kcbpapi dll just for an test.

2017-11-21

exchange processor

middle ware for soft . exchange processer just a queue

2017-11-21

20180111 ieap

use TNonblockingServer framework. getsnap to see which func servant is running

2018-01-11

thrift with memfunc and uid generator

thrift with uid generator , 28bits wide uuid , 100 year does not be same

2018-01-30

snappy library

libsnappy.so C++ library examples. it can work on cmake 2.8.12

2018-07-25

reliable rabbitmq c++ client

reliable reconnect rabbitmq-c client. basic get and publish. reconnect when fail

2018-07-16

packet parser

fast k_c_x_p client , fast k_c_b_p parser just for test

2018-06-12

transparent proxy

transparent proxy like haproxy. auto testing broken conn tps 300000

2018-09-29

brpc doubly_buffered_data test

modify brpc library doubly_buffered_data class. test performancy. 100000000 test Get total : 16557607309 ns, avg 165 ns Set total : 21681584661 ns, avg 216 ns

2018-08-07

get class name c++

get class's name. include namespace. use abi damangle

2018-08-08

trade server use evpp test

use callprogram sys to call other system. modify vlogger

2018-07-04

coroutine using phxrpc

coroutine example, using phxrpc coroutine framework, receive data from upstream and set redis, qps 12w

2018-11-01

prpc_20181109

using multi event loop in client api. using one channel all client stub share it.

2018-11-09

soft like haproxy

hello world program just for test. using evpp for transparent proxy

2018-09-19

trade middle ware

trade system. load so and run it. max qps 20000. server listen and send. subprocess connect and recv. should be placed on one machine. linux gcc 4.8

2018-06-29

nonblocking server

use murmurhash3 and http status print out delete logs

2018-06-11

rabbitmq-c client publish get example

rabbitmq exapmles。 declare exchange and queue. the articles in baidu do not help, I have to write examples that can work. basic_publish and basic_tet

2018-07-13

evpp so load system

load so and run. server listen, subprocess connect .

2018-07-02

remote procedure call using protobuffer

protobuffer server remote procedure call framework. using evpp and brpc library

2018-08-21

beanstalkd test client

beanstalkd test client. press test producer and consumer

2018-08-01

modp_base64

chrome's base64 encode and decode cpp classes. high performancy

2018-08-08

prpc_20181112

adding multi server and echo function to prpc framework

2018-11-12

prpc rpc framework

modify memory leak bugs. and multithread client press case. 40 w qps

2018-08-28

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除