1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-02 17:51:06 +01:00
libtgvoip/MessageThread.h
Igor Zhukov 5ada0717ef Improved FEC, thread blocking
Merge bugfixes from VoIP-Contest Stage 2:
https://contest.com/voip-contest-2/entry1273
2020-03-05 14:04:22 +04:00

55 lines
1001 B
C++
Executable File

//
// Created by Grishka on 17.06.2018.
//
#ifndef LIBTGVOIP_MESSAGETHREAD_H
#define LIBTGVOIP_MESSAGETHREAD_H
#include "threading.h"
#include "utils.h"
#include <vector>
#include <functional>
#include <atomic>
namespace tgvoip{
class MessageThread : public Thread{
public:
TGVOIP_DISALLOW_COPY_AND_ASSIGN(MessageThread);
MessageThread();
virtual ~MessageThread();
uint32_t Post(std::function<void()> func, double delay=0, double interval=0);
void Cancel(uint32_t id);
void CancelSelf();
void Stop();
enum{
INVALID_ID=0
};
private:
struct Message{
uint32_t id;
double deliverAt;
double interval;
std::function<void()> func;
};
void Run();
void InsertMessageInternal(Message& m);
std::atomic<bool> running;
std::vector<Message> queue;
Mutex queueMutex;
Mutex queueAccessMutex;
uint32_t lastMessageID=1;
bool cancelCurrent=false;
#ifdef _WIN32
HANDLE event;
#else
pthread_cond_t cond;
#endif
};
}
#endif //LIBTGVOIP_MESSAGETHREAD_H