Skip to content

Conversation

@mutouyun
Copy link
Owner

Summary

This PR adds FreeBSD platform support to cpp-ipc by reusing the existing POSIX pthread implementation.

Changes

  • Platform Detection: Added IPC_OS_FREEBSD_ macro to src/libipc/platform/detail.h
  • Conditional Compilation: Updated all sync modules to include FreeBSD alongside QNX for POSIX implementation
  • Documentation: Updated README.md to reflect FreeBSD platform support

Technical Details

FreeBSD uses the existing POSIX implementation (src/libipc/platform/posix/) which provides:

  • Process-shared mutexes (PTHREAD_PROCESS_SHARED)
  • Robust mutexes (PTHREAD_MUTEX_ROBUST)
  • Timed lock operations (pthread_mutex_timedlock, pthread_cond_timedwait)
  • POSIX shared memory (shm_open, shm_unlink)

Why This Approach?

  1. Minimal Changes: Only 8 files modified, 10 lines of code changed
  2. Low Risk: Reuses mature POSIX implementation already proven by QNX platform
  3. Complete Functionality: FreeBSD's POSIX implementation fully supports all required features
  4. Easy Maintenance: FreeBSD and QNX share the same implementation

Testing

The changes are minimal and non-invasive:

  • No changes to existing platform implementations (Linux, Windows, QNX)
  • No API changes
  • FreeBSD will use the same POSIX code path as QNX

Ideally, this should be tested on a FreeBSD system to verify:

  • Compilation succeeds
  • Unit tests pass
  • Demo programs work correctly

Files Modified

  • README.md - Added FreeBSD to platform list
  • src/libipc/platform/detail.h - Added FreeBSD platform detection
  • src/libipc/platform/platform.c - Updated conditional compilation
  • src/libipc/platform/platform.cpp - Updated conditional compilation
  • src/libipc/sync/condition.cpp - Updated conditional compilation
  • src/libipc/sync/mutex.cpp - Updated conditional compilation
  • src/libipc/sync/semaphore.cpp - Updated conditional compilation
  • src/libipc/sync/waiter.cpp - Updated conditional compilation

References

Related

Closes #156

- Add IPC_OS_FREEBSD_ platform detection macro
- Enable FreeBSD to use POSIX pthread implementation (shared with QNX)
- Update all conditional compilation directives to include FreeBSD
- Update README to reflect FreeBSD platform support

FreeBSD uses the existing POSIX implementation which supports:
- Process-shared mutexes (PTHREAD_PROCESS_SHARED)
- Robust mutexes (PTHREAD_MUTEX_ROBUST)
- Timed lock operations
- POSIX shared memory

This is a minimal change that reuses the mature POSIX implementation
already proven by QNX platform support.
@mutouyun mutouyun mentioned this pull request Nov 29, 2025
@cristian64
Copy link

cristian64 commented Dec 2, 2025

I quickly made a version update on the branch feature/issue-156. You can test it to see if it works properly. If there are no issues, I'll merge this pr.

I have been able to build on FreeBSD with GCC 13.3.0. However, although it builds everything (static library, shared library, demos, and tests) without any errors, unit tests are failing:

$ ./test-ipc
Running main() from /w/cpp-ipc/3rdparty/gtest/src/gtest_main.cc
[==========] Running 31 tests from 5 test suites.
[----------] Global test environment set-up.
[----------] 8 tests from IPC
[ RUN      ] IPC.clear
[       OK ] IPC.clear (1 ms)
[ RUN      ] IPC.basic_ssu
fail: send, there is no receiver on this connection.
fail: send, there is no receiver on this connection.
[       OK ] IPC.basic_ssu (1 ms)
[ RUN      ] IPC.basic_smb
fail: send, que->ready_sending() == false
fail: send, que->ready_sending() == false
fail: send, que->ready_sending() == false
/w/cpp-ipc/test/test_ipc.cpp:79: Failure
Value of: que1.send(test1)
  Actual: false
Expected: true
[  FAILED  ] IPC.basic_smb (0 ms)
[ RUN      ] IPC.basic_mmb
fail: send, there is no receiver on this connection.
fail: send, there is no receiver on this connection.
[       OK ] IPC.basic_mmb (0 ms)
[ RUN      ] IPC.1v1
[1-1,   10000] ssu      15.5061 us
fail: send, que->ready_sending() == false
/w/cpp-ipc/test/test_ipc.cpp:116: Failure
Value of: que.send(data_set__.get()[i])
  Actual: false
Expected: true
fail: send, que->ready_sending() == false

(And the process seems to stall at that point; I have not debugged it.)

Were you expecting any issue? (I'm using a VM to run FreeBSD 14.3, so I'm not sure if that could be the problem.)

EDIT: The chat demo does work.

@mutouyun
Copy link
Owner Author

mutouyun commented Dec 3, 2025

The test cases on the current master branch were all refactored by me just last weekend. How about this: I'll first merge this PR into the master branch, and then you can run the unit tests (UT) using the latest master branch to see if they all pass. If any test cases fail, please share them so we can take a look together.

@cristian64
Copy link

I think that's a good plan. It's definitely an improvement, as it can be built now, and at least some functionality works.

(For what it is worth, I had tried this branch also on a Linux system, and unit tests succeed.)

@mutouyun mutouyun merged commit 006a46e into master Dec 3, 2025
3 checks passed
@mutouyun mutouyun deleted the feature/issue-156 branch December 6, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for FreeBSD

3 participants