Closed Mr-JingShi closed 2 years ago
https://github.com/bytedance/bhook/blob/19f99d96c5e561b8e3598498024ef1285ee59c83/bytehook/src/main/cpp/bytesig.c#L319 已经做了compare,为什么 https://github.com/bytedance/bhook/blob/19f99d96c5e561b8e3598498024ef1285ee59c83/bytehook/src/main/cpp/bytesig.c#L322 还要使用__atomic_compare_exchange_n?
这段逻辑是无锁的,所以要用cas来保证“比较和赋值”是一个原子操作。前面的预先判断只是为了减少一些cas操作,提升性能。
https://github.com/bytedance/bhook/blob/19f99d96c5e561b8e3598498024ef1285ee59c83/bytehook/src/main/cpp/bytesig.c#L319 已经做了compare,为什么 https://github.com/bytedance/bhook/blob/19f99d96c5e561b8e3598498024ef1285ee59c83/bytehook/src/main/cpp/bytesig.c#L322 还要使用__atomic_compare_exchange_n?