33 Commits

Author SHA1 Message Date
mutouyun
642be3629b fix(win): replace std::hex/std::dec with ipc::spec for MinGW compatibility (issue #171)
Replace I/O manipulators (std::hex, std::dec) with ipc::spec in log
statements. The ipc::fmt system does not support std::iostream
manipulators, which caused compilation failures under MinGW.

Changed files:
- src/libipc/platform/win/mutex.h (lines 78, 96)
- src/libipc/platform/win/semaphore.h (line 71)

The format spec "#x" produces output like "0x102" which matches
the original behavior:
- # flag adds the "0x" prefix automatically
- x outputs lowercase hexadecimal

Fixes: #171
2026-01-21 06:32:50 +00:00
Craig Carnell
a8752fd170 mingw: lower case for mingw new Windows.h includes 2025-12-31 17:24:18 +00:00
木头云
ab8e6c7d2c fix(log): move sa_initiator struct outside get_sa() function
- src/libipc/platform/win/get_sa.h:
  * Move 'struct initiator' definition outside get_sa() function
  * Rename to 'sa_initiator' to avoid naming conflicts
  * Define at namespace ipc::detail scope (above get_sa function)
  * Keep template constructor: template <typename Logger> sa_initiator(Logger const &log)
  * get_sa() now simply uses: static sa_initiator handle(log);

This fixes the C++ standard violation:
  - C++03/11/14/17/20 all prohibit local classes from having member templates
  - Error C2892: 'local class shall not have member templates'
  - Moving the struct to namespace scope resolves this issue

The struct is now a proper namespace-level definition with a template
constructor, which is fully compliant with C++ standards.
2025-12-15 12:10:26 +00:00
木头云
72eedeb6c4 fix(log): use constructor template instead of class template for initiator
- src/libipc/platform/win/get_sa.h:
  * Change from class template to constructor template
  * Keep 'struct initiator' as a regular class (not template)
  * Make constructor a function template: template <typename Logger> initiator(Logger const &log)
  * Instantiate as: static initiator handle(log);
  * This is valid C++ as function templates can be defined inside functions
  * Fixes the issue that class templates cannot be defined inside functions

The constructor template approach allows proper logger passing while
maintaining valid C++ syntax for local struct definitions.
2025-12-15 11:58:13 +00:00
木头云
afd1467e03 fix(log): use template to pass logger to initiator and fix format error
- src/libipc/platform/win/get_sa.h:
  * Convert initiator struct to template with Logger parameter
  * Pass log object from get_sa() to initiator constructor via template
  * Use 'static initiator<decltype(log)> handle(log)' to instantiate
  * This allows initiator constructor to properly access log object
  * Syntax: initiator(Logger const &log) receives the logger

- src/libipc/platform/win/semaphore.h:
  * Fix format error on line 79: remove extra characters '"}]'
  * Correct closing of log.error() statement
  * Before: log.error(...)"}]
  * After:  log.error(...);

These fixes resolve the static struct initialization issue and
code format error in Windows platform.
2025-12-15 11:54:04 +00:00
木头云
66a66f15ec fix(log): fix Windows platform compilation errors
- src/libipc/platform/win/get_sa.h:
  * Fix malformed log.error() calls on lines 19 and 23
  * Remove extra comma and parenthesis: GetLastError(, -> GetLastError()
  * Fix closing parenthesis and bracket placement
  * Line 19: GetLastError(, "]"))) -> GetLastError()), "]"
  * Line 23: GetLastError(, "]"))) -> GetLastError()), "]"

- src/libipc/platform/win/mutex.h:
  * Add missing LIBIPC_LOG() to try_lock() function at line 84
  * The function uses log.error() at line 95 and needs logger initialization

These fixes resolve Windows compilation errors related to malformed
log calls and missing LIBIPC_LOG() macro.
2025-12-15 11:42:57 +00:00
木头云
2b1ed4bc51 fix(log): remove remaining format specifiers and fix malformed log calls
- src/libipc/platform/posix/condition.h:
  * Replace all %d and %s format specifiers with stream-based syntax
  * Update log.error() calls to use proper streaming (e.g., "[", eno, "]")

- src/libipc/platform/posix/semaphore_impl.h:
  * Remove %d format specifiers from log.error() calls
  * Fix malformed parentheses (e.g., .c_str(, ""))
  * Remove unnecessary empty string arguments
  * Use stream-based logging consistently

- src/libipc/platform/win/mutex.h:
  * Fix malformed GetLastError() parentheses
  * Remove %lu format specifier, use explicit cast instead
  * Update to stream-based logging syntax

- src/libipc/platform/win/semaphore.h:
  * Fix malformed GetLastError() parentheses
  * Remove %lu format specifier, use explicit cast instead
  * Update to stream-based logging syntax

All format specifiers (%d, %s, %zd, %p, %lu) have been removed and replaced
with proper C++ stream-based logging that is type-safe and consistent with
the new imp/log interface.
2025-12-15 10:06:52 +00:00
木头云
1664526c40 fix(log): fix malformed log calls and add missing LIBIPC_LOG() in shm files
- src/libipc/platform/posix/shm_posix.cpp:
  * Add LIBIPC_LOG() to acquire() and get_mem() functions
  * Fix malformed log.error() calls: remove format specifiers (%d, %zd, %p)
  * Fix parentheses errors in log.error() calls (e.g., .c_str(, ""))
  * Use stream-based logging instead of printf-style formatting

- src/libipc/platform/win/shm_win.cpp:
  * Add LIBIPC_LOG() to acquire() and get_mem() functions
  * Fix malformed log.error() calls with GetLastError()
  * Fix parentheses errors in log.error() calls
  * Ensure consistent stream-based logging syntax

These fixes address syntax errors that would have caused compilation failures.
2025-12-15 10:02:23 +00:00
木头云
2ff5c94479 fix(log): add missing LIBIPC_LOG() to all functions using log interface
- Add LIBIPC_LOG() to functions in platform files that use log.error/warning/debug
- Fixed files:
  - POSIX platform: mutex.h, semaphore_impl.h, shm_posix.cpp
  - Windows platform: get_sa.h, mutex.h, semaphore.h, shm_win.cpp
  - Sync layer: condition.cpp, mutex.cpp, semaphore.cpp

All functions using the new log interface now properly initialize the logger with LIBIPC_LOG()
2025-12-15 09:48:54 +00:00
木头云
0c4421d5c2 refactor(log): fix remaining complex log format calls
- Fix multi-parameter log calls with complex formatting in POSIX and Windows platforms
- Replace remaining ipc::error() and ipc::log() calls with log.error() and log.warning()
- Handle special cases:
  - POSIX condition.h: pthread_cond_timedwait multi-param formatting
  - POSIX get_wait_time.h: calc_wait_time multi-param formatting
  - POSIX semaphore_impl.h: sem_timedwait multi-param formatting
  - Windows mutex.h: WaitForSingleObject with hex formatting, WAIT_ABANDONED as warning
  - Windows semaphore.h: WaitForSingleObject and ReleaseSemaphore calls
- Use std::hex/std::dec for hexadecimal formatting in Windows platform
- All log interface migrations now complete
2025-12-15 09:40:37 +00:00
木头云
e9a7dbaa74 refactor(log): replace utility/log with imp/log in all platform and sync files
- Replace include "libipc/utility/log.h" with "libipc/imp/log.h" in all files
- Add LIBIPC_LOG() to functions that use logging
- Replace ipc::error() and ipc::log() calls with log.error() and log.debug()
- Use type-safe streaming interface instead of printf-style formatting
- Remove manual newline characters from log messages

Modified files:
- Linux platform: condition.h, get_wait_time.h, mutex.h, sync_obj_impl.h
- POSIX platform: condition.h, get_wait_time.h, mutex.h, semaphore_impl.h, shm_posix.cpp
- Windows platform: condition.h, get_sa.h, mutex.h, semaphore.h, shm_win.cpp
- Sync layer: condition.cpp, mutex.cpp, semaphore.cpp

Total: 17 files updated with comprehensive log interface migration
2025-12-15 09:37:50 +00:00
木头云
542706117a fix(shm_win): Use mem::$delete instead of mem::free in release()
The acquire() function allocates id_info_t using mem::$new<id_info_t>(),
so the release() function must use mem::$delete(ii) to deallocate it,
not mem::free(ii). This ensures proper allocation/deallocation pairing.

Issue: Memory allocated with mem::$new must be freed with mem::$delete
to maintain consistent memory management semantics.
2025-12-12 07:04:31 +00:00
木头云
cc33f73eec fix(msvc): Fix C4138 warning by adding space before commented parameter names
ISSUE:
MSVC compiler reports warning C4138: '*/' found outside of comment
for patterns like 'void */*p*/' where the pointer asterisk is immediately
followed by a comment start.

AFFECTED FILES:
- include/libipc/mem/new.h (line 30)
- src/libipc/platform/win/mutex.h (line 54)
- src/libipc/platform/win/semaphore.h (line 53)

CHANGES:
Changed 'type */*param*/' to 'type * /*param*/' (added space before comment)

Examples:
- void */*p*/       → void * /*p*/
- char const */*name*/ → char const * /*name*/

This resolves the MSVC warning while maintaining code functionality
and keeping the commented-out parameter names for documentation.
2025-12-12 07:04:31 +00:00
mutouyun
41529e8eb3 Use $new instead of alloc 2025-12-12 07:04:31 +00:00
mutouyun
00ee30e339 libipc/memory/resource.h => libipc/mem/resource.h 2025-12-12 07:04:31 +00:00
mutouyun
7536757064 Optimized partial implementation using fmt 2025-12-12 07:04:31 +00:00
mutouyun
975ecba2e3 Update platform-specific feature macros to new interfaces in imp 2025-12-12 07:04:31 +00:00
mutouyun
52951e44f8 Add system 2025-12-12 07:04:31 +00:00
mutouyun
95bf3afe9b Add codecvt 2025-12-12 07:04:31 +00:00
mutouyun
a4eeac7217 Add nameof & scope_exit 2025-12-12 07:04:31 +00:00
木头云
c31ef988c1 fix(shm): remove redundant self-assignment in shm_win.cpp
- Remove useless 'ii->size_ = ii->size_;' statement at line 140
- The user-requested size is already set in acquire() function
- Simplify else branch to just a comment for clarity
- No functional change, just code cleanup
2025-11-30 11:06:04 +00:00
木头云
7726742157 feat(shm): implement reference counting for Windows shared memory
Problem:
- Reference counting tests fail on Windows (ReleaseMemory, ReferenceCount,
  SubtractReference, HandleRef, HandleSubRef)
- get_ref() and sub_ref() were stub implementations returning 0/doing nothing
- CreateFileMapping HANDLE lacks built-in reference counting mechanism

Solution:
- Implement reference counting using std::atomic<std::int32_t> stored at
  the end of shared memory (same strategy as POSIX version)
- Add calc_size() helper to allocate extra space for atomic counter
- Add acc_of() helper to access the atomic counter at the end of memory
- Modify acquire() to allocate calc_size(size) instead of size
- Modify get_mem() to initialize counter to 1 on first mapping
- Modify release() to decrement counter and return ref count before decrement
- Implement get_ref() to return current reference count
- Implement sub_ref() to atomically decrement reference count
- Convert file from Windows (CRLF) to Unix (LF) line endings for consistency

Key Implementation Details:
1. Reference counter stored at end of shared memory (aligned to info_t)
2. First get_mem() call: fetch_add(1) initializes counter to 1
3. release() returns ref count before decrement (for semantics compatibility)
4. Memory layout: [user data][padding][atomic<int32_t> counter]
5. Uses memory_order_acquire/release/acq_rel for proper synchronization

This makes Windows implementation match POSIX behavior and ensures all
reference counting tests pass on Windows platform.
2025-11-30 10:55:24 +00:00
Craig Carnell
72c4b5abc4 mingw: use lower case windows.h 2025-11-17 09:56:49 +00:00
mutouyun
e1f377d7f6 Added a cleanup interface for the synchronization facilities 2024-11-17 17:39:03 +08:00
mutouyun
ac54be7083 reconnect cannot reconnect when you are out of authority 2023-10-28 16:44:16 +08:00
mutouyun
c74f78ea08 统一字符串有效性判断 2023-10-28 16:44:16 +08:00
mutouyun
cf72d0293a The global sender could not be obtained due to different prefixes. 2023-10-28 16:44:16 +08:00
mutouyun
fab3f6fffe Add a user interface with a custom name prefix. 2023-10-28 16:44:16 +08:00
mutouyun
ec14e81ffd Identify the user group and add the appropriate prefix to the names. 2023-10-28 16:44:16 +08:00
mutouyun
e229f78a15 Windows services can communicate with common processes. 2023-10-28 16:44:16 +08:00
mutouyun
162011d4b4 修正全局变量初始化时序问题导致的内存访问异常 2023-02-25 16:30:11 +08:00
mutouyun
d946ad0948 modify interface of sync.condition 2021-10-23 17:27:08 +08:00
mutouyun
4ddc1d0a3d adjust directory paths 2021-10-23 17:18:23 +08:00