木头云
91e4489a55
refactor(buffer): rename 'additional' parameter to 'mem_to_free' for clarity
...
Header changes (include/libipc/buffer.h):
- Rename: additional → mem_to_free (better semantic name)
- Add documentation comments explaining the parameter's purpose
- Clarifies that mem_to_free is passed to destructor instead of p
- Use case: when data pointer is offset into a larger allocation
Implementation changes (src/libipc/buffer.cpp):
- Update parameter name in constructor implementation
- No logic changes, just naming improvement
Test changes (test/test_buffer.cpp):
- Fix TEST_F(BufferTest, ConstructorWithMemToFree)
- Previous test caused crash: passed stack variable address to destructor
- New test correctly demonstrates the parameter's purpose:
* Allocate 100-byte block
* Use offset portion (bytes 25-75) as data
* Destructor receives original block pointer for proper cleanup
- Prevents double-free and invalid free errors
Semantic explanation:
buffer(data_ptr, size, destructor, mem_to_free)
On destruction:
destructor(mem_to_free ? mem_to_free : data_ptr, size)
This allows:
char* block = new char[100];
char* data = block + 25;
buffer buf(data, 50, my_free, block); // Frees 'block', not 'data'
2025-11-30 05:09:56 +00:00
木头云
de76cf80d5
fix(buffer): remove const from char constructor to prevent UB
...
- Change: explicit buffer(char const & c) → explicit buffer(char & c)
- Remove dangerous const_cast in implementation
- Before: buffer(const_cast<char*>(&c), 1) [UB if c is truly const]
- After: buffer(&c, 1) [safe, requires non-const char]
- Prevents undefined behavior from modifying compile-time constants
- Constructor now correctly requires mutable char reference
- Aligns with buffer's mutable data semantics
The previous implementation with const_cast could lead to:
- Modifying string literals (undefined behavior)
- Modifying const variables (undefined behavior)
- Runtime crashes or data corruption
Example of prevented misuse:
buffer buf('X'); // Now: compile error ✓
char c = 'X';
buffer buf(c); // Now: works correctly ✓
const char cc = 'Y';
buffer buf(cc); // Now: compile error ✓
2025-11-30 05:00:57 +00:00
木头云
8103c117f1
fix(buffer): remove redundant const qualifier in array constructor
...
- Change: byte_t const (& data)[N] → byte_t (& data)[N]
- Allows non-const byte arrays to be accepted by the constructor
- Fixes defect discovered by TEST_F(BufferTest, ConstructorFromByteArray)
- The const qualifier on array elements was too restrictive
- Keep char const & c unchanged as it's correct for single char reference
2025-11-30 04:56:02 +00:00
木头云
fdcc9340be
Update rw_lock.h for #143
2025-04-20 13:58:42 +08:00
mutouyun
5e5b347636
Complete the implementation of the clean interface and add unit tests
2024-12-01 19:06:50 +08:00
mutouyun
28fdf17279
Added cleanup interfaces for ipc chan
2024-12-01 17:49:34 +08:00
mutouyun
e1f377d7f6
Added a cleanup interface for the synchronization facilities
2024-11-17 17:39:03 +08:00
mutouyun
5071fb5db6
Added a cleanup interface for shared memory handles
2024-11-17 17:35:29 +08:00
mutouyun
fab3f6fffe
Add a user interface with a custom name prefix.
2023-10-28 16:44:16 +08:00
mutouyun
a46773bbd5
微调注释
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
f6bd578c8a
reduce the number of recheck times for the sleep function
2021-09-20 23:29:30 +08:00
mutouyun
ed8b1fd608
fix some bugs for linux-mutex
2021-09-20 20:31:08 +08:00
mutouyun
04fda1cc3d
use sync to refactor waiter
2021-09-20 15:59:44 +08:00
mutouyun
0cccdac868
merge issue-61; add condition for linux
2021-09-19 17:21:39 +08:00
mutouyun
d37a6740ea
add ut for sync::semaphore
2021-09-12 21:48:22 +08:00
mutouyun
d0e2a4d80c
add semaphore for win
2021-09-12 15:59:44 +08:00
木头云
78be14be37
Merge branch 'develop' into master
2021-08-29 11:05:24 +08:00
木头云
d80bea9b5d
fix: unexpected crash
...
An unexpected crash caused by an unconnected exit.
2021-08-23 13:10:03 +08:00
mutouyun
98a3449865
fix some bugs, adjust the test cases
2021-07-11 13:13:30 +08:00
mutouyun
69e1586b5a
remove tls
2021-07-10 14:22:31 +08:00
mutouyun
cca4664e84
option(LIBIPC_BUILD_SHARED_LIBS 'Build shared libraries (DLLs).' OFF)
2021-07-10 13:50:46 +08:00
mutouyun
455c0b479d
add sync::mutex for windows/linux
2021-06-20 23:50:39 +08:00
木头云
681f8e6736
add large_msg_align for cache memory alignment
2021-05-07 15:48:31 +08:00
mutouyun
6163618433
针对不同类型的策略,增加不同的sender/receiver个数检查。
...
- is_multi_producer:sender无限制;否则仅允许一个
- is_multi_consumer:receiver个数上限依赖is_broadcast指定;否则仅允许一个
- is_broadcast:receiver个数上限为32(uint_t<32>位数);否则无限制(uint_t<32>大小)
行为变更:
1. 在连接时根据模式检查sender/receiver是否超出上限,超出则返回false
2. 在send时确认是否允许发送(对receiver模式来说,send之前不会尝试确认sender个数)
3. 修正若干bug
2021-01-03 12:52:03 +08:00
mutouyun
af6ac84110
add comments
2021-01-01 12:39:32 +08:00
mutouyun
2255ae685a
调整接口;添加 msg_que demo
2020-09-20 14:55:47 +08:00
mutouyun
85c9eecdfd
避免编译时的命名冲突
2020-09-20 12:37:47 +08:00
mutouyun
7545e17084
简化接口
2020-09-20 12:20:55 +08:00
mutouyun
bce3894707
添加正常退出的机制(win)
2020-09-19 17:37:33 +08:00
mutouyun
523d38d247
调整目录结构,隔离include路径,修正tls在win下的问题
2020-09-13 17:29:14 +08:00
mutouyun
326bc10b2d
优化ut,修正tls中的bug
2020-09-13 15:06:47 +08:00
木头云
e87d516b1d
Update tls_pointer.h
2020-03-20 12:20:28 +08:00
mutouyun
b9cc885568
adjust constant definition
2020-03-04 13:24:43 +08:00
mutouyun
17c0bc76c3
buffer::data<T>()->T* => buffer::get<T>()->T
2020-03-04 12:37:48 +08:00
zhangyi
dbe6d6d3c6
fix bugs of large message buffer cache & recycle
2019-10-24 12:23:52 +08:00
zhangyi
d4bf94c2a3
use big message cache
2019-10-23 16:23:07 +08:00
zhangyi
8da0b32d0b
optimize memory management and recycle strategy
2019-10-21 13:32:07 +08:00
mutouyun
56484c0c8f
optimize the memory allocator
2019-10-05 03:48:24 +00:00
mutouyun
659989fd31
fix tls's defect
2019-09-21 14:21:57 +00:00
zhangyi
6b7c561496
fix tls bugs (win); modify data structure
2019-07-04 16:37:00 +08:00
mutouyun
fbf3c622e8
fine-tune
2019-07-02 23:07:39 +08:00
zhangyi
cf0028bf09
don't use std::function
2019-06-18 23:42:34 +08:00
zhangyi
a2d918dec2
try using ipc::string
2019-06-18 19:29:58 +08:00
zhangyi
30fa347f56
use shm::id_t instead of shm::handle in conn_info_head
2019-06-18 11:53:43 +08:00
zhangyi
ce3e9869fb
use one shm-block for big message (>= 4096)
2019-05-06 16:19:19 +08:00
mutouyun
ad9818a89b
move concept & pimpl helpers to single header respectively
2019-04-04 23:25:51 +08:00
mutouyun
2079c8eafb
rename parameter
2019-04-04 23:15:53 +08:00
mutouyun
5784b29521
update tls
2019-04-01 23:00:00 +08:00