feat: 优化CPU检测、增强线程安全并导出CPU特性#23
Open
xunxun1982 wants to merge 1 commit into
Open
Conversation
本次提交包含对核心库的多项重要优化,旨在提升性能、健壮性和模块化能力。
主要变更如下:
1. CPU特性检测与缓存 (cpu_info.c/h):
- 引入CPU特性缓存结构 `cpu_features_cache_t`,通过一次性检测并缓存结果,避免了对 `CPUID` 指令的重复调用。
- 通过导出的 `g_cpu_features` 指针,允许其他依赖模块安全、高效地复用CPU检测结果。
2. 线程安全与初始化顺序 (portable.c):
- 调整了初始化逻辑,在 `do_it()` 函数的开头强制调用 `cpu_info_initialize()`,确保在设置任何API Hook(特别是 `memset`)之前,CPU相关的资源已准备就绪,从根本上解决了多线程环境下的竞态条件风险。
- 保留了对 `creator_hook` 和 `remove_hook` 的关键段保护,确保了Hook操作的原子性。
3. 健壮性 (`portable.c`):
- 保留了对 `undo_it` 清理函数的结构化异常处理(`__try`/`__except`)和重入保护,确保了在各种异常情况下,程序都能尽可能干净地释放所有资源。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本次提交包含对核心库的多项重要优化,旨在提升性能、健壮性和模块化能力。
主要变更如下:
CPU特性检测与缓存 (cpu_info.c/h):
cpu_features_cache_t,通过一次性检测并缓存结果,避免了对CPUID指令的重复调用。g_cpu_features指针,允许其他依赖模块安全、高效地复用CPU检测结果。线程安全与初始化顺序 (portable.c):
do_it()函数的开头强制调用cpu_info_initialize(),确保在设置任何API Hook(特别是memset)之前,CPU相关的资源已准备就绪,从根本上解决了多线程环境下的竞态条件风险。creator_hook和remove_hook的关键段保护,确保了Hook操作的原子性。健壮性 (
portable.c):undo_it清理函数的结构化异常处理(__try/__except)和重入保护,确保了在各种异常情况下,程序都能尽可能干净地释放所有资源。