Rewrite planemap and idalloc in pure C++
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
//
|
||||
// idalloc.initmaster() - reinitialize the ID allocator in master mode.
|
||||
// idalloc.initsynch() - reinitialize the ID allocator in synchronous mode.
|
||||
// idalloc.setqueuefill() - override the default queue fill level.
|
||||
// idalloc.setqueue_fill() - override the default queue fill level.
|
||||
// idalloc.refill(bq) - get batches from the global pool until the batch queue is full.
|
||||
// idalloc.unqueue(bq) - push batches from the batch queue back into the global pool.
|
||||
// idalloc.preparethread(bq, co) - transfer a batch from the batch queue to the coroutine
|
||||
@@ -50,15 +50,50 @@
|
||||
#ifndef IDALLOC_HPP
|
||||
#define IDALLOC_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include "luastack.hpp"
|
||||
|
||||
int idalloc_initmaster(lua_State *L);
|
||||
int idalloc_initsynch(lua_State *L);
|
||||
int idalloc_refill(lua_State *L);
|
||||
int idalloc_unqueue(lua_State *L);
|
||||
int idalloc_preparethread(lua_State *L);
|
||||
int idalloc_salvagethread(lua_State *L);
|
||||
int idalloc_allocid(lua_State *L);
|
||||
class IdGlobalPool {
|
||||
private:
|
||||
std::vector<int64_t> salvaged_;
|
||||
int64_t next_batch_;
|
||||
int64_t next_id_;
|
||||
int queue_fill_;
|
||||
friend int cunittests_idalloc(lua_State *L);
|
||||
|
||||
public:
|
||||
IdGlobalPool();
|
||||
~IdGlobalPool();
|
||||
|
||||
void init_master(int qf);
|
||||
void init_synch(int qf);
|
||||
int64_t get_batch();
|
||||
int64_t get_one();
|
||||
void salvage(int64_t batch);
|
||||
int queue_fill() const { return queue_fill_; }
|
||||
void salvage_thread(lua_State *L);
|
||||
int64_t alloc_id_for_thread(lua_State *L);
|
||||
};
|
||||
|
||||
class IdPlayerPool {
|
||||
private:
|
||||
IdGlobalPool *global_;
|
||||
std::deque<int64_t> ranges_;
|
||||
friend int cunittests_idalloc(lua_State *L);
|
||||
|
||||
public:
|
||||
IdPlayerPool(IdGlobalPool *gp);
|
||||
~IdPlayerPool();
|
||||
|
||||
void refill();
|
||||
void unqueue();
|
||||
void purge();
|
||||
int64_t get_batch();
|
||||
void salvage_thread(lua_State *L);
|
||||
void prepare_thread(lua_State *L);
|
||||
};
|
||||
|
||||
#endif // IDALLOC_HPP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user