Optimize Media Layer Proxy
This commit is contained in:
parent
a925463fdf
commit
80d5674781
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**2.1.6**
|
||||
* Optimize Media Layer Proxy
|
||||
|
||||
**2.1.5**
|
||||
* Print Error Message If RakNet Fails To Start
|
||||
|
||||
|
@ -147,30 +147,16 @@ static std::unordered_map<std::string, unsigned char> &get_unique_ids() {
|
||||
void _assign_unique_id(const char *name, unsigned char id) {
|
||||
get_unique_ids()[name] = id;
|
||||
}
|
||||
// Only Compare Strings The First Time, Then Cache C String Addresses
|
||||
static std::unordered_map<const char *, unsigned char> &get_unique_ids_cache() {
|
||||
static std::unordered_map<const char *, unsigned char> unique_ids;
|
||||
return unique_ids;
|
||||
}
|
||||
static unsigned char get_unique_id(const char *name) {
|
||||
// Check If C String Is Cached
|
||||
if (get_unique_ids_cache().find(name) != get_unique_ids_cache().end()) {
|
||||
// Use Cache
|
||||
return get_unique_ids_cache()[name];
|
||||
} else {
|
||||
// Compare Strings
|
||||
unsigned char id = get_unique_ids()[name]; // Assume ID Exists
|
||||
get_unique_ids_cache()[name] = id;
|
||||
return id;
|
||||
}
|
||||
unsigned char _get_unique_id(const char *name) {
|
||||
return get_unique_ids()[name]; // Assume ID Exists
|
||||
}
|
||||
|
||||
// The Proxy Is Single-Threaded
|
||||
static pthread_mutex_t proxy_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
void _start_proxy_call(const char *call_name) {
|
||||
void _start_proxy_call(unsigned char call_id) {
|
||||
// Lock Proxy
|
||||
pthread_mutex_lock(&proxy_mutex);
|
||||
write_byte(get_unique_id(call_name));
|
||||
write_byte(call_id);
|
||||
}
|
||||
void end_proxy_call() {
|
||||
// Flush Write Cache
|
||||
|
@ -4,10 +4,20 @@
|
||||
|
||||
// Assign Unique ID To Function
|
||||
__attribute__((visibility("internal"))) void _assign_unique_id(const char *name, unsigned char id);
|
||||
__attribute__((visibility("internal"))) unsigned char _get_unique_id(const char *name);
|
||||
|
||||
// Must Call After Every Call
|
||||
__attribute__((visibility("internal"))) void _start_proxy_call(const char *name);
|
||||
#define start_proxy_call() _start_proxy_call(__func__)
|
||||
__attribute__((visibility("internal"))) void _start_proxy_call(unsigned char call_id);
|
||||
#define start_proxy_call() \
|
||||
{ \
|
||||
static int _loaded_id = 0; \
|
||||
static unsigned char _call_id; \
|
||||
if (!_loaded_id) { \
|
||||
_loaded_id = 1; \
|
||||
_call_id = _get_unique_id(__func__); \
|
||||
} \
|
||||
_start_proxy_call(_call_id); \
|
||||
}
|
||||
__attribute__((visibility("internal"))) void end_proxy_call();
|
||||
|
||||
#define CALL(unique_id, name, return_type, args) \
|
||||
|
Loading…
Reference in New Issue
Block a user