Add thread safety documentation

This commit is contained in:
2025-08-19 17:20:36 -04:00
parent b8d735f074
commit b7282a2f03
6 changed files with 347 additions and 9 deletions

View File

@@ -56,6 +56,7 @@ Key features:
- Proper alignment handling for all types
- Move semantics for efficient transfers
- Requires trivially destructible types only
- Thread-safe per-connection usage via exclusive ownership model
#### 2. **Commit Request Data Model** (`src/commit_request.hpp`)
- **Format-agnostic data structure** for representing transactional commits
@@ -265,6 +266,7 @@ The modular design allows each component to be optimized independently while mai
### Important Implementation Details
- **Server Creation**: Always use `Server::create()` factory method - direct construction is impossible
- **Connection Creation**: Only the Server can create connections - no public constructor or factory method
- **Connection Ownership**: Use unique_ptr semantics for safe ownership transfer between components
- **Arena Allocator Pattern**: Always use `ArenaAllocator` for temporary allocations within request processing
- **String View Usage**: Prefer `std::string_view` over `std::string` when pointing to arena-allocated memory
@@ -323,7 +325,9 @@ The modular design allows each component to be optimized independently while mai
## Common Patterns
### Server Creation Pattern
### Factory Method Patterns
#### Server Creation
```cpp
// Server must be created via factory method
auto server = Server::create(config, handler);
@@ -333,6 +337,20 @@ auto server = Server::create(config, handler);
// auto server = std::make_shared<Server>(config, handler); // Compiler error
```
#### Connection Creation (Server-Only)
```cpp
// Only Server can create connections (using private friend method)
class Server {
private:
auto conn = Connection::createForServer(addr, fd, id, handler, weak_from_this());
};
// No public way to create connections - all these fail:
// auto conn = Connection::create(...); // ERROR: no such method
// Connection conn(addr, fd, id, handler, server); // ERROR: private constructor
// auto conn = std::make_unique<Connection>(...); // ERROR: private constructor
```
### ConnectionHandler Implementation Patterns
#### Simple Synchronous Handler