Procházet zdrojové kódy

use uthash hash table instead of posix htable which mingw doesn't have

Samuel Thibault před 13 roky
rodič
revize
561fd3d7d3
1 změnil soubory, kde provedl 21 přidání a 30 odebrání
  1. 21 30
      src/debug/traces/starpu_fxt.c

+ 21 - 30
src/debug/traces/starpu_fxt.c

@@ -16,6 +16,7 @@
 
 #include <starpu.h>
 #include <common/config.h>
+#include <common/uthash.h>
 
 #ifdef STARPU_USE_FXT
 #include "starpu_fxt.h"
@@ -124,46 +125,41 @@ static float get_event_time_stamp(struct fxt_ev_64 *ev, struct starpu_fxt_option
 
 static int nworkers = 0;
 
+struct worker_entry
+{
+	UT_hash_handle hh;
+	unsigned long tid;
+	int workerid;
+} *worker_ids;
+
 static int register_worker_id(unsigned long tid)
 {
 	int workerid = nworkers++;
+	struct worker_entry *entry;
 
-	/* create a new key in the htable */
-	char *tidstr = malloc(16*sizeof(char));
-	sprintf(tidstr, "%lu", tid);
-
-	ENTRY item;
-		item.key = tidstr;
-		item.data = (void *)(uintptr_t)workerid;
-
-	ENTRY *res;
-	res = hsearch(item, FIND);
+	HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
 
 	/* only register a thread once */
-	STARPU_ASSERT(res == NULL);
+	STARPU_ASSERT(entry == NULL);
+
+	entry = malloc(sizeof(*entry));
+	entry->tid = tid;
+	entry->workerid = workerid;
 
-	res = hsearch(item, ENTER);
-	STARPU_ASSERT(res);
+	HASH_ADD(hh, worker_ids, tid, sizeof(tid), entry);
 
 	return workerid;
 }
 
 static int find_worker_id(unsigned long tid)
 {
-	char tidstr[16];
-	sprintf(tidstr, "%lu", tid);
-
-	ENTRY item;
-		item.key = tidstr;
-		item.data = NULL;
-	ENTRY *res;
-	res = hsearch(item, FIND);
-	if (!res)
-		return -1;
+	struct worker_entry *entry;
 
-	int id = (uintptr_t)(res->data);
+	HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
+	if (!entry)
+		return -1;
 
-	return id;
+	return entry->workerid;
 }
 
 static void update_accumulated_time(int worker, double sleep_time, double exec_time, double current_timestamp, int forceflush)
@@ -832,9 +828,6 @@ void starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *opt
 	fxt_blockev_t block;
 	block = fxt_blockev_enter(fut);
 
-	/* create a htable to identify each worker(tid) */
-	hcreate(STARPU_NMAXWORKERS);
-
 	symbol_list = _starpu_symbol_name_list_new();
 	communication_list = _starpu_communication_list_new();
 
@@ -1041,8 +1034,6 @@ void starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *opt
 		}
 	}
 
-	hdestroy();
-
 	/* Close the trace file */
 	if (close(fd_in))
 	{