mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Giving threadsafety in client registry with semaphore
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include "uuidtree.h"
|
||||
#include "client.h"
|
||||
@@ -31,13 +32,16 @@ guac_client_registry* guac_create_client_registry() {
|
||||
guac_client_registry* registry = malloc(sizeof(guac_client_registry));
|
||||
|
||||
registry->root = guac_create_uuid_tree();
|
||||
sem_init(&(registry->tree_lock), 0, 1);
|
||||
|
||||
return registry;
|
||||
|
||||
}
|
||||
|
||||
void guac_register_client(guac_client_registry* registry, guac_client* client) {
|
||||
sem_wait(&(registry->tree_lock));
|
||||
guac_uuid_tree_put(registry->root, client->uuid, client);
|
||||
sem_post(&(registry->tree_lock));
|
||||
}
|
||||
|
||||
guac_client* guac_find_client(guac_client_registry* registry, uuid_t uuid) {
|
||||
@@ -45,11 +49,15 @@ guac_client* guac_find_client(guac_client_registry* registry, uuid_t uuid) {
|
||||
}
|
||||
|
||||
void guac_remove_client(guac_client_registry* registry, uuid_t uuid) {
|
||||
sem_wait(&(registry->tree_lock));
|
||||
guac_uuid_tree_remove(registry->root, uuid);
|
||||
sem_post(&(registry->tree_lock));
|
||||
}
|
||||
|
||||
void guac_cleanup_registry(guac_client_registry* registry) {
|
||||
sem_wait(&(registry->tree_lock));
|
||||
guac_cleanup_uuid_tree(registry->root);
|
||||
sem_destroy(&(registry->tree_lock));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user