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