Skip to content

Commit 90feb1c

Browse files
cursoragentmyungjoo
authored andcommitted
Refactor node table to use gint64 hash and keys
Co-authored-by: myungjoo.ham <myungjoo.ham@samsung.com>
1 parent 7f7ff95 commit 90feb1c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

daemon/mlops-agent-node.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ _mlops_node_get (const int64_t id)
4343
mlops_node_s *node = NULL;
4444

4545
G_LOCK (mlops_node_table);
46-
node = (mlops_node_s *) g_hash_table_lookup (g_mlops_node_table,
47-
GINT_TO_POINTER (id));
46+
node = (mlops_node_s *) g_hash_table_lookup (g_mlops_node_table, &id);
4847
G_UNLOCK (mlops_node_table);
4948

5049
if (!node) {
@@ -121,8 +120,8 @@ mlops_node_initialize (void)
121120
{
122121
G_LOCK (mlops_node_table);
123122
if (!g_mlops_node_table) {
124-
g_mlops_node_table = g_hash_table_new_full (g_direct_hash, g_direct_equal,
125-
NULL, _mlops_node_free);
123+
g_mlops_node_table = g_hash_table_new_full (g_int64_hash, g_int64_equal,
124+
g_free, _mlops_node_free);
126125
}
127126
g_assert (g_mlops_node_table != NULL);
128127
G_UNLOCK (mlops_node_table);
@@ -150,6 +149,7 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
150149
{
151150
mlops_node_s *node = NULL;
152151
gint result = -EIO;
152+
gint64 *node_id = NULL;
153153
gchar *desc = NULL;
154154
GstElement *pipeline = NULL;
155155
GError *err = NULL;
@@ -200,8 +200,11 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
200200
node->description = g_strdup (desc);
201201
g_mutex_init (&node->lock);
202202

203+
node_id = g_new (gint64, 1);
204+
*node_id = node->id;
205+
203206
G_LOCK (mlops_node_table);
204-
g_hash_table_insert (g_mlops_node_table, GINT_TO_POINTER (node->id), node);
207+
g_hash_table_insert (g_mlops_node_table, node_id, node);
205208
G_UNLOCK (mlops_node_table);
206209

207210
*id = node->id;
@@ -251,7 +254,7 @@ mlops_node_destroy (const int64_t id)
251254
node = _mlops_node_get (id);
252255
if (node) {
253256
G_LOCK (mlops_node_table);
254-
g_hash_table_remove (g_mlops_node_table, GINT_TO_POINTER (id));
257+
g_hash_table_remove (g_mlops_node_table, &id);
255258
G_UNLOCK (mlops_node_table);
256259
}
257260

0 commit comments

Comments
 (0)