Skip to contentSkip to conversation

Xenomai-forge: psos: extended object names

PATCH In review Kim De Mey 2 participants 3 messages Oct 22, 2013

lore
Share & tools
lore

Kim De Mey

author
#0 lore raw

PATCH 1/1 Xenomai-forge: psos: extended object names

Extend object names with number to make them unique

---

Although this is not a requirement for pSOS, it would be nice to have unique names for debugging purposes. This comes especially in the picture with the implementation of registry for pSOS. Without unique names no object with duplicate name will be added to registry. Unless changes are made to the creation of the files.

 lib/psos/queue.c |  5 ++++-
 lib/psos/rn.c    |  5 ++++-
 lib/psos/sem.c   |  5 ++++-
 lib/psos/task.c  |  5 ++++-
 4 files changed, 16 insertions(+), 4 deletions(-)
lib/psos/queue.c +4 -1
@@ -99,7 +99,10 @@ static u_long __q_create(const char *nam
 		sprintf(q->name, "q%lu", ++anon_qids);
 	else {
 		name = __psos_maybe_short_name(short_name, name);
-		strncpy(q->name, name, sizeof(q->name));
+		if (cluster_findobj(&psos_queue_table, name) != NULL)
+			snprintf(q->name,sizeof(q->name), "%s_%lu", name, ++anon_qids);
+		else
+			strncpy(q->name, name, sizeof(q->name));
 		q->name[sizeof(q->name) - 1] = '\0';
 	}
 
lib/psos/rn.c +4 -1
@@ -115,7 +115,10 @@ u_long rn_create(const char *name, void 
 		sprintf(rn->name, "rn%lu", ++anon_rnids);
 	else {
 		name = __psos_maybe_short_name(short_name, name);
-		strncpy(rn->name, name, sizeof(rn->name));
+		if (cluster_findobj(&psos_rn_table, name) != NULL)
+			snprintf(rn->name,sizeof(rn->name), "%s_%lu", name, ++anon_rnids);
+		else
+			strncpy(rn->name, name, sizeof(rn->name));
 		rn->name[sizeof(rn->name) - 1] = '\0';
 	}
 
lib/psos/sem.c +4 -1
@@ -93,7 +93,10 @@ u_long sm_create(const char *name,
 		sprintf(sem->name, "sm%lu", ++anon_smids);
 	else {
 		name = __psos_maybe_short_name(short_name, name);
-		strncpy(sem->name, name, sizeof(sem->name));
+		if (cluster_findobj(&psos_sem_table, name) != NULL)
+			snprintf(sem->name,sizeof(sem->name), "%s_%lu", name, ++anon_smids);
+		else
+			strncpy(sem->name, name, sizeof(sem->name));
 		sem->name[sizeof(sem->name) - 1] = '\0';
 	}
 
lib/psos/task.c +4 -1
@@ -285,7 +285,10 @@ u_long t_create(const char *name, u_long
 		sprintf(task->name, "t%lu", ++anon_tids);
 	else {
 		name = __psos_maybe_short_name(short_name, name);
-		strncpy(task->name, name, sizeof(task->name));
+		if (cluster_findobj(&psos_task_table, name) != NULL)
+			snprintf(task->name,sizeof(task->name), "%s_%lu", name, ++anon_tids);
+		else
+			strncpy(task->name, name, sizeof(task->name));
 		task->name[sizeof(task->name) - 1] = '\0';
 	}
 
#1 lore raw
Quoted 6 lines · Kim De Mey

Extend object names with number to make them unique

Quoted 8 lines

---

Although this is not a requirement for pSOS, it would be nice to have unique names for debugging purposes. This comes especially in the picture with the implementation of registry for pSOS. Without unique names no object with duplicate name will be added to registry. Unless changes are made to the creation of the files.

I'm ok with the intent, not with the implementation. Please check how the alchemy API does this via alchemy_build_name().

This will keep the name generation in a single place, and also fix a race in the current pSOS emulator code, which post-increments anon_*ids in a sloppy non-atomic way.

Signature · 1 line
Philippe.
author
#2 lore raw

2013/10/22 Philippe Gerum <[email protected]>

Quoted 18 lines · Kim De Mey
Quoted 8 lines

Extend object names with number to make them unique

gmail.com <[email protected]>>

Quoted 9 lines

---

Although this is not a requirement for pSOS, it would be nice to have unique names for debugging purposes. This comes especially in the picture with the implementation of registry for pSOS. Without unique names no object with duplicate name will be added to registry. Unless changes are made to the creation of the files.

Quoted 8 lines

I'm ok with the intent, not with the implementation. Please check how the alchemy API does this via alchemy_build_name().

This will keep the name generation in a single place, and also fix a race in the current pSOS emulator code, which post-increments anon_*ids in a sloppy non-atomic way.

Okay, I will adjust the patch to have a similar implementation as the one of alchemy.