tuaris opened a new pull request, #3224:
URL: https://github.com/apache/brpc/pull/3224

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Problem Summary:
   
   brpc has partial FreeBSD support (27 source files already contain 
`OS_FREEBSD`/`__FreeBSD__` references), but it does not compile or run on 
FreeBSD. This PR completes that support.
   
   The most critical issue is a **static initialization deadlock**: bthread 
interposes `pthread_mutex_lock` for contention profiling. On FreeBSD, during 
early process init, `libc++.so`'s `ios_base::Init::Init()` calls 
`pthread_mutex_lock` to initialize `std::locale::classic()`. bthread's 
interposed version calls `pthread_once(init_sys_mutex_lock)`, which itself 
needs `pthread_mutex_lock` — causing infinite recursion. Without the 
`NO_PTHREAD_MUTEX_HOOK` fix in this PR, **any FreeBSD application linking brpc 
will deadlock at startup**.
   
   This is PR 2 of 3 for FreeBSD support:
   1. PR #XXXX — Remove dead `tracked_objects.h` references
   2. **This PR** — FreeBSD platform support
   3. PR 3 (upcoming) — FreeBSD CI workflow via GitHub Actions
   
   ### What is changed and the side effects?
   
   Changed:
   
   **All source changes are guarded by `#if defined(OS_FREEBSD)` — zero impact 
on Linux or macOS builds.** Most changes piggyback on existing macOS/Darwin 
code paths since both use kqueue.
   
   CMakeLists.txt:
   - Add `NO_PTHREAD_MUTEX_HOOK` on FreeBSD to prevent static init deadlock 
caused by bthread's `pthread_mutex_lock` interposition conflicting with 
`libc++` `ios_base::Init` during early process initialization
   - Add `-lexecinfo` for backtrace support
   - Add FreeBSD-specific source files (`platform_thread_freebsd.cc`, 
`sys_string_conversions_posix.cc`)
   
   Source changes:
   - `butil/compat.h`: Add FreeBSD kqueue path and `pthread_getthreadid_np()`
   - `butil/process_util.cc`: FreeBSD `ReadCommandLine` via `ps` (like macOS)
   - `butil/fd_utility.cpp`: kqueue fd handling
   - `butil/logging.cc`: Rename `FLAGS_v`/`vmodule`/`minloglevel` to avoid 
gflags duplicate registration with system glog on FreeBSD
   - `brpc/socket.cpp`: FreeBSD `TCP_INFO` support
   - `bthread/`: FreeBSD futex emulation, context switching, fd handling
   - `bvar/default_variables.cpp`: FreeBSD `/proc` fallback
   
   Side effects:
   - Performance effects:
   None — all changes are behind `OS_FREEBSD` guards and do not affect existing 
platforms.
   
   - Breaking backward compatibility:
   None — this is additive FreeBSD support only.
   
   ---
   ### Check List:
   - Please make sure your changes are compatible.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to