1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-04 02:27:46 +01:00
libtgvoip/MessageThread.h
Grishka 5380aaba0d 2.2
- Refactored audio I/O to allow sharing a common context between input and output, for those OSes that require this
- Rewritten periodic operation handling to use a "run loop" thingy instead of an ugly loop formerly known as tick thread
- Fixed a bunch of compiler warnings (closes #13)
- Added automake so you no longer need to use the GYP file for standalone builds (closes #43)
2018-07-17 19:48:21 +03:00

51 lines
887 B
C++
Executable File

//
// Created by Grishka on 17.06.2018.
//
#ifndef LIBTGVOIP_MESSAGETHREAD_H
#define LIBTGVOIP_MESSAGETHREAD_H
#include "threading.h"
#include <vector>
#include <functional>
namespace tgvoip{
class MessageThread : public Thread{
public:
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* arg);
void InsertMessageInternal(Message& m);
bool running=true;
std::vector<Message> queue;
Mutex queueMutex;
uint32_t lastMessageID=1;
bool cancelCurrent=false;
#ifdef _WIN32
HANDLE event;
#else
pthread_cond_t cond;
#endif
};
}
#endif //LIBTGVOIP_MESSAGETHREAD_H