mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-20 13:15:16 -04:00
sse client to listen commands (from mapedit)
This commit is contained in:
parent
13f6c05c60
commit
bb5be10adc
10 changed files with 336 additions and 29 deletions
44
platform/mtqueue.cpp
Normal file
44
platform/mtqueue.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "mtqueue.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <malloc.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
struct StringDeleter {
|
||||
void operator()(char *x) {
|
||||
free(x);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<char, StringDeleter> alloc_string(const char *x) {
|
||||
return std::unique_ptr<char, StringDeleter>(strdup(x));
|
||||
}
|
||||
|
||||
|
||||
typedef struct tag_mtqueue {
|
||||
std::queue<std::unique_ptr<char, StringDeleter> > _q;
|
||||
std::mutex _mx;
|
||||
|
||||
|
||||
} MTQUEUE;
|
||||
|
||||
MTQUEUE *mtqueue_create() {
|
||||
return new MTQUEUE();
|
||||
}
|
||||
void mtqueue_push(MTQUEUE *q, const char *message) {
|
||||
std::lock_guard _(q->_mx);
|
||||
q->_q.push(alloc_string(message));
|
||||
}
|
||||
char *mtqueue_pop(MTQUEUE *q) {
|
||||
std::lock_guard _(q->_mx);
|
||||
if (q->_q.empty()) return NULL;
|
||||
else {
|
||||
char *c = q->_q.front().release();
|
||||
q->_q.pop();
|
||||
return c;
|
||||
}
|
||||
}
|
||||
void mtqueue_destroy(MTQUEUE *q) {
|
||||
delete q;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue