-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithreaded_packet_processor.h
More file actions
42 lines (30 loc) · 930 Bytes
/
multithreaded_packet_processor.h
File metadata and controls
42 lines (30 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef MULTITHREADED_PACKET_PROCESSOR_H
#define MULTITHREADED_PACKET_PROCESSOR_H
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <vector>
#include <string>
class MultithreadedPacketProcessor {
public:
MultithreadedPacketProcessor(size_t threadCount, const std::function<void(const std::string&)>& processPacket);
void start();
// Add a new packet for processing
void enqueuePacket(const std::string& packetData);
void stop();
private:
size_t threadCount;
std::vector<std::thread> threads;
// Packet queue and synchronization primitives
std::queue<std::string> packetQueue;
std::mutex queueMutex;
std::condition_variable condition;
bool stopFlag;
// Packet processing callback
std::function<void(const std::string&)> processPacket;
// Thread worker function
void workerThread();
};
#endif