[Darshan-commits] [Darshan] branch, dev-modular, updated. 0da31a588b438cc6905b94d6923ba90d51f3f964

Service Account git at mcs.anl.gov
Fri Oct 31 16:05:49 CDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".

The branch, dev-modular has been updated
       via  0da31a588b438cc6905b94d6923ba90d51f3f964 (commit)
       via  40c8ed2eb34f503dcfcc184890854412ef2b24ad (commit)
      from  b1ae796cb558e93b5de96bd3d46077319a4acac9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0da31a588b438cc6905b94d6923ba90d51f3f964
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Fri Oct 31 15:59:54 2014 -0500

    initial darshan core shutdown logic
    
    -also, darshan core uses utlist to keep track of modules

commit 40c8ed2eb34f503dcfcc184890854412ef2b24ad
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Fri Oct 31 12:22:35 2014 -0500

    updat todos, instrumentation for posix open/close

-----------------------------------------------------------------------

Summary of changes:
 darshan-modularization-design-notes.txt |    5 +
 darshan-runtime/darshan-core.h          |    2 +-
 darshan-runtime/lib/darshan-core.c      |  128 +++++----
 darshan-runtime/lib/darshan-posix.c     |  244 +++++++++++-----
 uthash.h => darshan-runtime/uthash.h    |    0
 darshan-runtime/utlist.h                |  490 +++++++++++++++++++++++++++++++
 6 files changed, 751 insertions(+), 118 deletions(-)
 rename uthash.h => darshan-runtime/uthash.h (100%)
 create mode 100644 darshan-runtime/utlist.h


Diff of changes:
diff --git a/darshan-modularization-design-notes.txt b/darshan-modularization-design-notes.txt
index 632f676..0023903 100644
--- a/darshan-modularization-design-notes.txt
+++ b/darshan-modularization-design-notes.txt
@@ -115,3 +115,8 @@ TODO NOTES:
     - why are darshan mutexes recursive?
     - how do we allow modules to specify there necessary linker/wrapper flags
     - configurable amount of max runtime memory
+    - how do we associate handles with file/object records?
+        - easily doable within module, but can we refactor and make this common code?
+    - fs mount information -- should we export this info from darshan-core?
+        - would the posix module be the only one to leverage this info?
+        - it is used to correlate filenames with mount points, but not sure what is needed where
diff --git a/darshan-runtime/darshan-core.h b/darshan-runtime/darshan-core.h
index c0fbc06..c94ac9d 100644
--- a/darshan-runtime/darshan-core.h
+++ b/darshan-runtime/darshan-core.h
@@ -29,7 +29,7 @@ struct darshan_core_module
 {
     char name[DARSHAN_MOD_NAME_LEN+1];
     struct darshan_module_funcs mod_funcs;
-    struct darshan_core_module *next_mod;
+    struct darshan_core_module *next;
 };
 
 /* in memory structure to keep up with job level data */
diff --git a/darshan-runtime/lib/darshan-core.c b/darshan-runtime/lib/darshan-core.c
index 1aa0918..8b273e4 100644
--- a/darshan-runtime/lib/darshan-core.c
+++ b/darshan-runtime/lib/darshan-core.c
@@ -19,6 +19,7 @@
 #include <mpi.h>
 
 #include "darshan-core.h"
+#include "utlist.h"
 
 extern char* __progname_full;
 
@@ -26,12 +27,21 @@ static void darshan_core_initialize(int *argc, char ***argv);
 static void darshan_core_shutdown(void);
 
 /* internal variables */
-static struct darshan_core_job_runtime *darshan_global_job = NULL;
+static struct darshan_core_job_runtime *darshan_core_job = NULL;
 static pthread_mutex_t darshan_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 #define DARSHAN_LOCK() pthread_mutex_lock(&darshan_mutex)
 #define DARSHAN_UNLOCK() pthread_mutex_unlock(&darshan_mutex)
 
+#define DARSHAN_MOD_REGISTER(__mod) \
+    LL_PREPEND(darshan_core_job->mod_list_head, __mod)
+#define DARSHAN_MOD_SEARCH(__mod, __tmp) \
+    LL_SEARCH(darshan_core_job->mod_list_head, __mod, __tmp, mod_cmp)
+#define DARSHAN_MOD_ITER(__mod, __tmp) \
+    LL_FOREACH_SAFE(darshan_core_job->mod_list_head, __mod, __tmp)
+#define DARSHAN_MOD_DELETE(__mod) \
+   LL_DELETE(darshan_core_job->mod_list_head, __mod)
+
 /* intercept MPI initialize and finalize to initialize darshan */
 int MPI_Init(int *argc, char ***argv)
 {
@@ -53,7 +63,7 @@ int MPI_Init_thread(int *argc, char ***argv, int required, int *provided)
     int ret;
 
     ret = DARSHAN_MPI_CALL(PMPI_Init_thread)(argc, argv, required, provided);
-    if (ret != MPI_SUCCESS)
+    if(ret != MPI_SUCCESS)
     {
         return(ret);
     }
@@ -73,6 +83,8 @@ int MPI_Finalize(void)
     return(ret);
 }
 
+/* *********************************** */
+
 static void darshan_core_initialize(int *argc, char ***argv)
 {
     int i;
@@ -90,40 +102,39 @@ static void darshan_core_initialize(int *argc, char ***argv)
     if(getenv("DARSHAN_INTERNAL_TIMING"))
         internal_timing_flag = 1;
 
-    if (internal_timing_flag)
+    if(internal_timing_flag)
         init_start = DARSHAN_MPI_CALL(PMPI_Wtime)();
 
     /* setup darshan runtime if darshan is enabled and hasn't been initialized already */
-    if (!getenv("DARSHAN_DISABLE") && !darshan_global_job)
+    if(!getenv("DARSHAN_DISABLE") && !darshan_core_job)
     {
-        /* allocate structure to track darshan_global_job information */
-        darshan_global_job = malloc(sizeof(*darshan_global_job));
-        if (darshan_global_job)
+        /* allocate structure to track darshan_core_job information */
+        darshan_core_job = malloc(sizeof(*darshan_core_job));
+        if(darshan_core_job)
         {
-            memset(darshan_global_job, 0, sizeof(*darshan_global_job));
+            memset(darshan_core_job, 0, sizeof(*darshan_core_job));
 
-            if (getenv("DARSHAN_DISABLE_TIMING"))
+            if(getenv("DARSHAN_DISABLE_TIMING"))
             {
-                darshan_global_job->flags |= CP_FLAG_NOTIMING;
+                darshan_core_job->flags |= CP_FLAG_NOTIMING;
             }
 
-            strcpy(darshan_global_job->log_job.version_string, CP_VERSION);
-            darshan_global_job->log_job.magic_nr = CP_MAGIC_NR;
-            darshan_global_job->log_job.uid = getuid();
-            darshan_global_job->log_job.start_time = time(NULL);
-            darshan_global_job->log_job.nprocs = nprocs;
-            darshan_global_job->wtime_offset = DARSHAN_MPI_CALL(PMPI_Wtime)();
-            darshan_global_job->mod_list_head = NULL;
+            strcpy(darshan_core_job->log_job.version_string, CP_VERSION);
+            darshan_core_job->log_job.magic_nr = CP_MAGIC_NR;
+            darshan_core_job->log_job.uid = getuid();
+            darshan_core_job->log_job.start_time = time(NULL);
+            darshan_core_job->log_job.nprocs = nprocs;
+            darshan_core_job->wtime_offset = DARSHAN_MPI_CALL(PMPI_Wtime)();
 
             /* record exe and arguments */
             for(i=0; i<(*argc); i++)
             {
-                chars_left = CP_EXE_LEN-strlen(darshan_global_job->exe);
-                strncat(darshan_global_job->exe, *(argv[i]), chars_left);
+                chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
+                strncat(darshan_core_job->exe, *(argv[i]), chars_left);
                 if(i < ((*argc)-1))
                 {
-                    chars_left = CP_EXE_LEN-strlen(darshan_global_job->exe);
-                    strncat(darshan_global_job->exe, " ", chars_left);
+                    chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
+                    strncat(darshan_core_job->exe, " ", chars_left);
                 }
             }
 
@@ -132,17 +143,17 @@ static void darshan_core_initialize(int *argc, char ***argv)
              */
             if(argc == 0)
             {
-                chars_left = CP_EXE_LEN-strlen(darshan_global_job->exe);
-                strncat(darshan_global_job->exe, __progname_full, chars_left);
-                chars_left = CP_EXE_LEN-strlen(darshan_global_job->exe);
-                strncat(darshan_global_job->exe, " <unknown args>", chars_left);
+                chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
+                strncat(darshan_core_job->exe, __progname_full, chars_left);
+                chars_left = CP_EXE_LEN-strlen(darshan_core_job->exe);
+                strncat(darshan_core_job->exe, " <unknown args>", chars_left);
             }
 
             if(chars_left == 0)
             {
                 /* we ran out of room; mark that string was truncated */
                 truncate_offset = CP_EXE_LEN - strlen(truncate_string);
-                sprintf(&darshan_global_job->exe[truncate_offset], "%s",
+                sprintf(&darshan_core_job->exe[truncate_offset], "%s",
                     truncate_string);
             }
         }
@@ -165,16 +176,31 @@ static void darshan_core_initialize(int *argc, char ***argv)
 
 static void darshan_core_shutdown()
 {
+    struct darshan_core_module *mod, *tmp;
     int internal_timing_flag = 0;
 
     if(getenv("DARSHAN_INTERNAL_TIMING"))
         internal_timing_flag = 1;
 
-    printf("darshan SHUTDOWN\n");
+    /* TODO: coordinate shutdown accross all registered modules */
+    DARSHAN_MOD_ITER(mod, tmp)
+    {
+        printf("Shutting down %s module\n", mod->name);
+
+        DARSHAN_MOD_DELETE(mod);
+        free(mod);
+    };
+
+    free(darshan_core_job);
 
     return;
 }
 
+static int mod_cmp(struct darshan_core_module* a, struct darshan_core_module* b)
+{
+    return strcmp(a->name, b->name);
+}
+
 /* ********************************************************* */
 
 void darshan_core_register_module(
@@ -182,44 +208,46 @@ void darshan_core_register_module(
     struct darshan_module_funcs *funcs,
     int *runtime_mem_limit)
 {
-    struct darshan_core_module *tmp;
-    struct darshan_core_module *new_mod;
+    struct darshan_core_module tmp;
+    struct darshan_core_module* mod;
 
     *runtime_mem_limit = 0;
-    if (!darshan_global_job)
+    if(!darshan_core_job)
         return;
 
     DARSHAN_LOCK();
-    tmp = darshan_global_job->mod_list_head;
-    while(tmp)
+
+    /* see if this module is already registered */
+    strncpy(tmp.name, name, DARSHAN_MOD_NAME_LEN);
+    DARSHAN_MOD_SEARCH(mod, &tmp);
+    if(mod)
     {
-        /* silently return if this module is already registered */
-        if (strcmp(tmp->name, name) == 0)
-        {
-            DARSHAN_UNLOCK();
-            return;
-        }
-        tmp = tmp->next_mod;
+        /* if module is already registered, update module_funcs and return */
+        /* NOTE: we do not recalculate memory limit here, just set to 0 */
+        mod->mod_funcs = *funcs;
+
+        DARSHAN_UNLOCK();
+        return;
     }
 
-    /* allocate new module and add to the head of the linked list of darshan modules */
-    new_mod = malloc(sizeof(*new_mod));
-    if (!new_mod)
+    /* this module has not been registered yet, allocate and register it */
+    mod = malloc(sizeof(*mod));
+    if(!mod)
     {
         DARSHAN_UNLOCK();
         return;
     }
+    memset(mod, 0, sizeof(*mod));
 
-    memset(new_mod, 0, sizeof(*new_mod));
-    strncpy(new_mod->name, name, DARSHAN_MOD_NAME_LEN);
-    new_mod->mod_funcs = *funcs;
-    new_mod->next_mod = darshan_global_job->mod_list_head;
-    darshan_global_job->mod_list_head = new_mod;
-    DARSHAN_UNLOCK();
+    strncpy(mod->name, name, DARSHAN_MOD_NAME_LEN);
+    mod->mod_funcs = *funcs;
+    DARSHAN_MOD_REGISTER(mod);
 
     /* TODO: something smarter than just 2 MiB per module */
     *runtime_mem_limit = 2 * 1024 * 1024;
 
+    DARSHAN_UNLOCK();
+
     return;
 }
 
@@ -231,7 +259,7 @@ void darshan_core_lookup_id(
 {
     darshan_file_id tmp_id;
 
-    if (!darshan_global_job)
+    if(!darshan_core_job)
         return;
 
     /* TODO: what do you do with printable flag? */
@@ -247,7 +275,7 @@ void darshan_core_lookup_id(
 
 double darshan_core_wtime()
 {
-    if(!darshan_global_job || darshan_global_job->flags & CP_FLAG_NOTIMING)
+    if(!darshan_core_job || darshan_core_job->flags & CP_FLAG_NOTIMING)
     {
         return(0);
     }
diff --git a/darshan-runtime/lib/darshan-posix.c b/darshan-runtime/lib/darshan-posix.c
index a3b1998..9c8bbb8 100644
--- a/darshan-runtime/lib/darshan-posix.c
+++ b/darshan-runtime/lib/darshan-posix.c
@@ -128,7 +128,7 @@ enum darshan_posix_indices
 };
 
 /* floating point statistics */
-enum f_darshan_posix_indices
+enum darshan_f_posix_indices
 {
     /* NOTE: adjust cp_normalize_timestamps() function if any TIMESTAMPS are
      * added or modified in this list
@@ -159,26 +159,35 @@ enum f_darshan_posix_indices
 struct darshan_posix_file
 {
     darshan_file_id f_id;
+    int64_t rank;
     int64_t counters[CP_NUM_INDICES];
     double fcounters[CP_F_NUM_INDICES];
 };
 
-struct darshan_posix_runtime_file
+struct posix_runtime_file
 {
     struct darshan_posix_file file_record;
     UT_hash_handle hlink;
 };
 
-struct darshan_posix_runtime
+struct posix_runtime_file_ref
 {
-    struct darshan_posix_runtime_file* file_array;
+    struct posix_runtime_file* file;
+    int fd;
+    UT_hash_handle hlink;
+};
+
+struct posix_runtime
+{
+    struct posix_runtime_file* file_array;
     int file_array_size;
     int file_count;
-    struct darshan_posix_runtime_file* file_hash;
+    struct posix_runtime_file* file_hash;
+    struct posix_runtime_file_ref* fd_hash;
 };
 
+static struct posix_runtime *posix_runtime = NULL;
 static pthread_mutex_t posix_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-static struct darshan_posix_runtime *posix_runtime = NULL;
 static int my_rank = -1;
 static int darshan_mem_alignment = 1;
 
@@ -198,19 +207,61 @@ NULL
 };
 
 DARSHAN_FORWARD_DECL(open, int, (const char *path, int flags, ...));
-//DARSHAN_FORWARD_DECL(close, int, (int fd));
+DARSHAN_FORWARD_DECL(close, int, (int fd));
 
 static void posix_runtime_initialize(void);
 static void posix_runtime_finalize(void);
 
+static struct posix_runtime_file* posix_file_by_name(const char *name);
+static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int fd);
+static void posix_file_close_fd(int fd);
+
 static void posix_prepare_for_shutdown(void);
 static void posix_get_output_data(void **buffer, int size);
 
 #define POSIX_LOCK() pthread_mutex_lock(&posix_runtime_mutex)
 #define POSIX_UNLOCK() pthread_mutex_unlock(&posix_runtime_mutex)
 
+#define POSIX_SET(__file, __counter, __value) do {\
+    (__file)->file_record.counters[__counter] = __value; \
+} while(0)
+
+#define POSIX_F_SET(__file, __counter, __value) do {\
+    (__file)->file_record.fcounters[__counter] = __value; \
+} while(0)
+
+#define POSIX_INC(__file, __counter, __value) do {\
+    (__file)->file_record.counters[__counter] += __value; \
+} while(0)
+
+#define POSIX_F_INC(__file, __counter, __value) do {\
+    (__file)->file_record.fcounters[__counter] += __value; \
+} while(0)
+
+#define POSIX_F_INC_NO_OVERLAP(__file, __tm1, __tm2, __last, __counter) do { \
+    if(__tm1 > __last) \
+        POSIX_F_INC(__file, __counter, (__tm2-__tm1)); \
+    else \
+        POSIX_F_INC(__file, __counter, (__tm2 - __last)); \
+    if(__tm2 > __last) \
+        __last = __tm2; \
+} while(0)
+
+#define POSIX_VALUE(__file, __counter) \
+    ((__file)->file_record.counters[__counter])
+
+#define POSIX_F_VALUE(__file, __counter) \
+    ((__file)->file_record.fcounters[__counter])
+
+#define POSIX_MAX(__file, __counter, __value) do {\
+    if((__file)->file_record.counters[__counter] < __value) \
+    { \
+        (__file)->file_record.counters[__counter] = __value; \
+    } \
+} while(0)
+
 #define POSIX_RECORD_OPEN(__ret, __path, __mode, __stream_flag, __tm1, __tm2) do { \
-    struct darshan_posix_runtime_file* file; \
+    struct posix_runtime_file* file; \
     char* exclude; \
     int tmp_index = 0; \
     if(__ret < 0) break; \
@@ -220,22 +271,18 @@ static void posix_get_output_data(void **buffer, int size);
         tmp_index++; \
     } \
     if(exclude) break; \
-    file = darshan_file_by_name(__path, __ret); \
+    file = posix_file_by_name_setfd(__path, __ret); \
     if(!file) break; \
-    file->log_file->rank = my_rank; \
+    file->file_record.rank = my_rank; \
     if(__mode) \
-        DARSHAN_SET(file, DARSHAN_MODE, __mode); \
-    file->offset = 0; \
-    file->last_byte_written = 0; \
-    file->last_byte_read = 0; \
+        POSIX_SET(file, CP_MODE, __mode); \
     if(__stream_flag)\
-        DARSHAN_INC(file, DARSHAN_POSIX_FOPENS, 1); \
+        POSIX_INC(file, CP_POSIX_FOPENS, 1); \
     else \
-        DARSHAN_INC(file, DARSHAN_POSIX_OPENS, 1); \
-    if(DARSHAN_F_VALUE(file, DARSHAN_F_OPEN_TIMESTAMP) == 0) \
-        DARSHAN_F_SET(file, DARSHAN_F_OPEN_TIMESTAMP, __tm1); \
-    DARSHAN_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_posix_meta_end, DARSHAN_F_POSIX_META_TIME); \
-} while (0)
+        POSIX_INC(file, CP_POSIX_OPENS, 1); \
+    if(POSIX_F_VALUE(file, CP_F_OPEN_TIMESTAMP) == 0) \
+        POSIX_F_SET(file, CP_F_OPEN_TIMESTAMP, __tm1); \
+} while(0)
 
 int DARSHAN_DECL(open)(const char *path, int flags, ...)
 {
@@ -266,14 +313,13 @@ int DARSHAN_DECL(open)(const char *path, int flags, ...)
     POSIX_LOCK();
     posix_runtime_initialize();
 
-    //POSIX_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
+    POSIX_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
 
     POSIX_UNLOCK();
 
     return(ret);
 }
 
-#if 0
 int DARSHAN_DECL(close)(int fd)
 {
     struct darshan_file_runtime* file;
@@ -290,21 +336,12 @@ int DARSHAN_DECL(close)(int fd)
     POSIX_LOCK();
     posix_runtime_initialize();
 
-    file = darshan_file_by_fd(tmp_fd);
-    if(file)
-    {
-        file->last_byte_written = 0;
-        file->last_byte_read = 0;
-        DARSHAN_F_SET(file, DARSHAN_F_CLOSE_TIMESTAMP, posix_wtime());
-        DARSHAN_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_posix_meta_end, DARSHAN_F_POSIX_META_TIME);
-        darshan_file_close_fd(tmp_fd);
-    }
+    posix_file_close_fd(tmp_fd);
 
     POSIX_UNLOCK();    
 
     return(ret);
 }
-#endif
 
 /* ***************************************************** */
 
@@ -323,6 +360,36 @@ static void posix_runtime_initialize()
     if(posix_runtime)
         return;
 
+    /* register the posix module with darshan core */
+    darshan_core_register_module(
+        POSIX_MOD_NAME,
+        &posix_mod_fns,
+        &mem_limit);
+
+    /* return if no memory assigned by darshan core */
+    if(mem_limit == 0)
+        return;
+
+    posix_runtime = malloc(sizeof(*posix_runtime));
+    if(!posix_runtime)
+        return;
+    memset(posix_runtime, 0, sizeof(*posix_runtime));
+
+    /* set maximum number of file records according to max memory limit */
+    /* NOTE: maximum number of records is based on the size of a posix file record */
+    posix_runtime->file_array_size = mem_limit / sizeof(struct darshan_posix_file);
+
+    /* allocate array of runtime file records */
+    posix_runtime->file_array = malloc(sizeof(struct posix_runtime_file) *
+                                       posix_runtime->file_array_size);
+    if(!posix_runtime->file_array)
+    {
+        posix_runtime->file_array_size = 0;
+        return;
+    }
+    memset(posix_runtime->file_array, 0, sizeof(struct posix_runtime_file) *
+           posix_runtime->file_array_size);
+
 #if 0
     /* set the memory alignment according to config or environment variables */
     #if (__CP_MEM_ALIGNMENT < 1)
@@ -350,39 +417,20 @@ static void posix_runtime_initialize()
     }
 #endif
 
-    posix_runtime = malloc(sizeof(*posix_runtime));
-    if(!posix_runtime)
-        return;
-    memset(posix_runtime, 0, sizeof(*posix_runtime));
-
-    /* register the posix module with darshan core */
-    darshan_core_register_module(
-        POSIX_MOD_NAME,
-        &posix_mod_fns,
-        &mem_limit);
-
-    /* set maximum number of file records according to max memory limit */
-    posix_runtime->file_array_size = mem_limit / sizeof(struct darshan_posix_runtime_file);
+    return;
+}
 
-    /* allocate array of runtime file records */
-    posix_runtime->file_array = malloc(sizeof(struct darshan_posix_runtime_file) *
-                                       posix_runtime->file_array_size);
-    if(!posix_runtime->file_array)
-    {
-        posix_runtime->file_array_size = 0;
-        return;
-    }
-    memset(posix_runtime->file_array, 0, sizeof(struct darshan_posix_runtime_file) *
-           posix_runtime->file_array_size);
+static void posix_runtime_finalize()
+{
 
     return;
 }
 
-static struct darshan_posix_runtime_file* posix_file_by_name(const char *name)
+static struct posix_runtime_file* posix_file_by_name(const char *name)
 {
-    struct darshan_posix_runtime_file *tmp_file = NULL;
+    struct posix_runtime_file *file = NULL;
     char *newname = NULL;
-    darshan_file_id tmp_id;
+    darshan_file_id file_id;
 
     if(!posix_runtime)
         return(NULL);
@@ -396,29 +444,88 @@ static struct darshan_posix_runtime_file* posix_file_by_name(const char *name)
         (void*)newname,
         strlen(newname),
         1,
-        &tmp_id);
+        &file_id);
 
     /* search the hash table for this file record, and return if found */
-    HASH_FIND(hlink, posix_runtime->file_hash, &tmp_id, sizeof(darshan_file_id), tmp_file);
-    if (tmp_file)
+    HASH_FIND(hlink, posix_runtime->file_hash, &file_id, sizeof(darshan_file_id), file);
+    if(file)
     {
-        if (newname != name)
+        if(newname != name)
             free(newname);
-        return(tmp_file);
+        return(file);
     }
 
     /* no existing record, assign a new file record from the global array */
-    tmp_file = &posix_runtime->file_array[posix_runtime->file_count];
-    tmp_file->file_record.f_id = tmp_id;
+    file = &posix_runtime->file_array[posix_runtime->file_count];
+    file->file_record.f_id = file_id;
 
     /* add new record to file hash table */
-    HASH_ADD(hlink, posix_runtime->file_hash, file_record.f_id, sizeof(darshan_file_id), tmp_file);
+    HASH_ADD(hlink, posix_runtime->file_hash, file_record.f_id, sizeof(darshan_file_id), file);
 
     posix_runtime->file_count++;
 
     if(newname != name)
         free(newname);
-    return(tmp_file);
+    return(file);
+}
+
+static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int fd)
+{
+    struct posix_runtime_file* file;
+    struct posix_runtime_file_ref* ref;
+
+    if(!posix_runtime)
+        return(NULL);
+
+    /* find file record by name first */
+    file = posix_file_by_name(name);
+
+    if(!file)
+        return(NULL);
+
+    /* search hash table for existing file ref for this fd */
+    HASH_FIND(hlink, posix_runtime->fd_hash, &fd, sizeof(int), ref);
+    if(ref)
+    {
+        /* we have a reference.  Make sure it points to the correct file
+         * and return it
+         */
+        ref->file = file;
+        return(file);
+    }
+
+    /* if we hit this point, then we don't have a reference for this fd
+     * in the table yet.  Add it.
+     */
+    ref = malloc(sizeof(*ref));
+    if(!ref)
+        return(NULL);
+    memset(ref, 0, sizeof(*ref));
+    ref->file = file;
+    ref->fd = fd;    
+
+    HASH_ADD(hlink, posix_runtime->fd_hash, fd, sizeof(int), ref);
+
+    return(file);
+}
+
+static void posix_file_close_fd(int fd)
+{
+    struct posix_runtime_file_ref *ref;
+
+    if(!posix_runtime)
+        return;
+
+    /* search hash table for this fd */
+    HASH_FIND(hlink, posix_runtime->fd_hash, &fd, sizeof(int), ref);
+    if (ref)
+    {
+        /* we have a reference, delete it */
+        HASH_DELETE(hlink, posix_runtime->fd_hash, ref);
+        free(ref);
+    }
+
+    return;
 }
 
 /* ***************************************************** */
@@ -432,6 +539,9 @@ static void posix_prepare_for_shutdown()
 static void posix_get_output_data(void **buffer, int size)
 {
 
+    /* shutdown the posix runtime module */
+    posix_runtime_finalize();
+
     return;
 }
 
diff --git a/uthash.h b/darshan-runtime/uthash.h
similarity index 100%
rename from uthash.h
rename to darshan-runtime/uthash.h
diff --git a/darshan-runtime/utlist.h b/darshan-runtime/utlist.h
new file mode 100644
index 0000000..35fc9db
--- /dev/null
+++ b/darshan-runtime/utlist.h
@@ -0,0 +1,490 @@
+/*
+Copyright (c) 2007-2010, Troy D. Hanson   http://uthash.sourceforge.net
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef UTLIST_H
+#define UTLIST_H
+
+#define UTLIST_VERSION 1.9.1
+
+/* 
+ * This file contains macros to manipulate singly and doubly-linked lists.
+ *
+ * 1. LL_ macros:  singly-linked lists.
+ * 2. DL_ macros:  doubly-linked lists.
+ * 3. CDL_ macros: circular doubly-linked lists.
+ *
+ * To use singly-linked lists, your structure must have a "next" pointer.
+ * To use doubly-linked lists, your structure must "prev" and "next" pointers.
+ * Either way, the pointer to the head of the list must be initialized to NULL.
+ * 
+ * ----------------.EXAMPLE -------------------------
+ * struct item {
+ *      int id;
+ *      struct item *prev, *next;
+ * }
+ *
+ * struct item *list = NULL:
+ *
+ * int main() {
+ *      struct item *item;
+ *      ... allocate and populate item ...
+ *      DL_APPEND(list, item);
+ * }
+ * --------------------------------------------------
+ *
+ * For doubly-linked lists, the append and delete macros are O(1)
+ * For singly-linked lists, append and delete are O(n) but prepend is O(1)
+ * The sort macro is O(n log(n)) for all types of single/double/circular lists.
+ */
+
+/* These macros use decltype or the earlier __typeof GNU extension.
+   As decltype is only available in newer compilers (VS2010 or gcc 4.3+
+   when compiling c++ code), this code uses whatever method is needed
+   or, for VS2008 where neither is available, uses casting workarounds. */
+#ifdef _MSC_VER            /* MS compiler */
+#if _MSC_VER >= 1600 && __cplusplus  /* VS2010 and newer in C++ mode */
+#define LDECLTYPE(x) decltype(x)
+#else                     /* VS2008 or older (or VS2010 in C mode) */
+#define NO_DECLTYPE
+#define LDECLTYPE(x) char*
+#endif
+#else                      /* GNU, Sun and other compilers */
+#define LDECLTYPE(x) __typeof(x)
+#endif
+
+/* for VS2008 we use some workarounds to get around the lack of decltype,
+ * namely, we always reassign our tmp variable to the list head if we need
+ * to dereference its prev/next pointers, and save/restore the real head.*/
+#ifdef NO_DECLTYPE
+#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
+#define _NEXT(elt,list) ((char*)((list)->next))
+#define _NEXTASGN(elt,list,to) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
+#define _PREV(elt,list) ((char*)((list)->prev))
+#define _PREVASGN(elt,list,to) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
+#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
+#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
+#else 
+#define _SV(elt,list)
+#define _NEXT(elt,list) ((elt)->next)
+#define _NEXTASGN(elt,list,to) ((elt)->next)=(to)
+#define _PREV(elt,list) ((elt)->prev)
+#define _PREVASGN(elt,list,to) ((elt)->prev)=(to)
+#define _RS(list)
+#define _CASTASGN(a,b) (a)=(b)
+#endif
+
+/******************************************************************************
+ * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort    *
+ * Unwieldy variable names used here to avoid shadowing passed-in variables.  *
+ *****************************************************************************/
+#define LL_SORT(list, cmp)                                                                     \
+do {                                                                                           \
+  LDECLTYPE(list) _ls_p;                                                                       \
+  LDECLTYPE(list) _ls_q;                                                                       \
+  LDECLTYPE(list) _ls_e;                                                                       \
+  LDECLTYPE(list) _ls_tail;                                                                    \
+  LDECLTYPE(list) _ls_oldhead;                                                                 \
+  LDECLTYPE(list) _tmp;                                                                        \
+  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
+  if (list) {                                                                                  \
+    _ls_insize = 1;                                                                            \
+    _ls_looping = 1;                                                                           \
+    while (_ls_looping) {                                                                      \
+      _CASTASGN(_ls_p,list);                                                                   \
+      _CASTASGN(_ls_oldhead,list);                                                             \
+      list = NULL;                                                                             \
+      _ls_tail = NULL;                                                                         \
+      _ls_nmerges = 0;                                                                         \
+      while (_ls_p) {                                                                          \
+        _ls_nmerges++;                                                                         \
+        _ls_q = _ls_p;                                                                         \
+        _ls_psize = 0;                                                                         \
+        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
+          _ls_psize++;                                                                         \
+          _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list);                               \
+          if (!_ls_q) break;                                                                   \
+        }                                                                                      \
+        _ls_qsize = _ls_insize;                                                                \
+        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
+          if (_ls_psize == 0) {                                                                \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+          } else {                                                                             \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+          }                                                                                    \
+          if (_ls_tail) {                                                                      \
+            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
+          } else {                                                                             \
+            _CASTASGN(list,_ls_e);                                                             \
+          }                                                                                    \
+          _ls_tail = _ls_e;                                                                    \
+        }                                                                                      \
+        _ls_p = _ls_q;                                                                         \
+      }                                                                                        \
+      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list);                            \
+      if (_ls_nmerges <= 1) {                                                                  \
+        _ls_looping=0;                                                                         \
+      }                                                                                        \
+      _ls_insize *= 2;                                                                         \
+    }                                                                                          \
+  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
+} while (0)
+
+#define DL_SORT(list, cmp)                                                                     \
+do {                                                                                           \
+  LDECLTYPE(list) _ls_p;                                                                       \
+  LDECLTYPE(list) _ls_q;                                                                       \
+  LDECLTYPE(list) _ls_e;                                                                       \
+  LDECLTYPE(list) _ls_tail;                                                                    \
+  LDECLTYPE(list) _ls_oldhead;                                                                 \
+  LDECLTYPE(list) _tmp;                                                                        \
+  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
+  if (list) {                                                                                  \
+    _ls_insize = 1;                                                                            \
+    _ls_looping = 1;                                                                           \
+    while (_ls_looping) {                                                                      \
+      _CASTASGN(_ls_p,list);                                                                   \
+      _CASTASGN(_ls_oldhead,list);                                                             \
+      list = NULL;                                                                             \
+      _ls_tail = NULL;                                                                         \
+      _ls_nmerges = 0;                                                                         \
+      while (_ls_p) {                                                                          \
+        _ls_nmerges++;                                                                         \
+        _ls_q = _ls_p;                                                                         \
+        _ls_psize = 0;                                                                         \
+        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
+          _ls_psize++;                                                                         \
+          _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list);                               \
+          if (!_ls_q) break;                                                                   \
+        }                                                                                      \
+        _ls_qsize = _ls_insize;                                                                \
+        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
+          if (_ls_psize == 0) {                                                                \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+          } else {                                                                             \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+          }                                                                                    \
+          if (_ls_tail) {                                                                      \
+            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
+          } else {                                                                             \
+            _CASTASGN(list,_ls_e);                                                             \
+          }                                                                                    \
+          _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list);                          \
+          _ls_tail = _ls_e;                                                                    \
+        }                                                                                      \
+        _ls_p = _ls_q;                                                                         \
+      }                                                                                        \
+      _CASTASGN(list->prev, _ls_tail);                                                         \
+      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL); _RS(list);                            \
+      if (_ls_nmerges <= 1) {                                                                  \
+        _ls_looping=0;                                                                         \
+      }                                                                                        \
+      _ls_insize *= 2;                                                                         \
+    }                                                                                          \
+  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
+} while (0)
+
+#define CDL_SORT(list, cmp)                                                                    \
+do {                                                                                           \
+  LDECLTYPE(list) _ls_p;                                                                       \
+  LDECLTYPE(list) _ls_q;                                                                       \
+  LDECLTYPE(list) _ls_e;                                                                       \
+  LDECLTYPE(list) _ls_tail;                                                                    \
+  LDECLTYPE(list) _ls_oldhead;                                                                 \
+  LDECLTYPE(list) _tmp;                                                                        \
+  LDECLTYPE(list) _tmp2;                                                                       \
+  int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping;                       \
+  if (list) {                                                                                  \
+    _ls_insize = 1;                                                                            \
+    _ls_looping = 1;                                                                           \
+    while (_ls_looping) {                                                                      \
+      _CASTASGN(_ls_p,list);                                                                   \
+      _CASTASGN(_ls_oldhead,list);                                                             \
+      list = NULL;                                                                             \
+      _ls_tail = NULL;                                                                         \
+      _ls_nmerges = 0;                                                                         \
+      while (_ls_p) {                                                                          \
+        _ls_nmerges++;                                                                         \
+        _ls_q = _ls_p;                                                                         \
+        _ls_psize = 0;                                                                         \
+        for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) {                                         \
+          _ls_psize++;                                                                         \
+          _SV(_ls_q,list);                                                                     \
+          if (_NEXT(_ls_q,list) == _ls_oldhead) {                                              \
+            _ls_q = NULL;                                                                      \
+          } else {                                                                             \
+            _ls_q = _NEXT(_ls_q,list);                                                         \
+          }                                                                                    \
+          _RS(list);                                                                           \
+          if (!_ls_q) break;                                                                   \
+        }                                                                                      \
+        _ls_qsize = _ls_insize;                                                                \
+        while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) {                                    \
+          if (_ls_psize == 0) {                                                                \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+            if (_ls_q == _ls_oldhead) { _ls_q = NULL; }                                        \
+          } else if (_ls_qsize == 0 || !_ls_q) {                                               \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+            if (_ls_p == _ls_oldhead) { _ls_p = NULL; }                                        \
+          } else if (cmp(_ls_p,_ls_q) <= 0) {                                                  \
+            _ls_e = _ls_p; _SV(_ls_p,list); _ls_p = _NEXT(_ls_p,list); _RS(list); _ls_psize--; \
+            if (_ls_p == _ls_oldhead) { _ls_p = NULL; }                                        \
+          } else {                                                                             \
+            _ls_e = _ls_q; _SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list); _RS(list); _ls_qsize--; \
+            if (_ls_q == _ls_oldhead) { _ls_q = NULL; }                                        \
+          }                                                                                    \
+          if (_ls_tail) {                                                                      \
+            _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e); _RS(list);                     \
+          } else {                                                                             \
+            _CASTASGN(list,_ls_e);                                                             \
+          }                                                                                    \
+          _SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail); _RS(list);                          \
+          _ls_tail = _ls_e;                                                                    \
+        }                                                                                      \
+        _ls_p = _ls_q;                                                                         \
+      }                                                                                        \
+      _CASTASGN(list->prev,_ls_tail);                                                          \
+      _CASTASGN(_tmp2,list);                                                                   \
+      _SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp2); _RS(list);                           \
+      if (_ls_nmerges <= 1) {                                                                  \
+        _ls_looping=0;                                                                         \
+      }                                                                                        \
+      _ls_insize *= 2;                                                                         \
+    }                                                                                          \
+  } else _tmp=NULL; /* quiet gcc unused variable warning */                                    \
+} while (0)
+
+/******************************************************************************
+ * singly linked list macros (non-circular)                                   *
+ *****************************************************************************/
+#define LL_PREPEND(head,add)                                                                   \
+do {                                                                                           \
+  (add)->next = head;                                                                          \
+  head = add;                                                                                  \
+} while (0)
+
+#define LL_APPEND(head,add)                                                                    \
+do {                                                                                           \
+  LDECLTYPE(head) _tmp;                                                                        \
+  (add)->next=NULL;                                                                            \
+  if (head) {                                                                                  \
+    _tmp = head;                                                                               \
+    while (_tmp->next) { _tmp = _tmp->next; }                                                  \
+    _tmp->next=(add);                                                                          \
+  } else {                                                                                     \
+    (head)=(add);                                                                              \
+  }                                                                                            \
+} while (0)
+
+#define LL_DELETE(head,del)                                                                    \
+do {                                                                                           \
+  LDECLTYPE(head) _tmp;                                                                        \
+  if ((head) == (del)) {                                                                       \
+    (head)=(head)->next;                                                                       \
+  } else {                                                                                     \
+    _tmp = head;                                                                               \
+    while (_tmp->next && (_tmp->next != (del))) {                                              \
+      _tmp = _tmp->next;                                                                       \
+    }                                                                                          \
+    if (_tmp->next) {                                                                          \
+      _tmp->next = ((del)->next);                                                              \
+    }                                                                                          \
+  }                                                                                            \
+} while (0)
+
+/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */
+#define LL_APPEND_VS2008(head,add)                                                             \
+do {                                                                                           \
+  if (head) {                                                                                  \
+    (add)->next = head;     /* use add->next as a temp variable */                             \
+    while ((add)->next->next) { (add)->next = (add)->next->next; }                             \
+    (add)->next->next=(add);                                                                   \
+  } else {                                                                                     \
+    (head)=(add);                                                                              \
+  }                                                                                            \
+  (add)->next=NULL;                                                                            \
+} while (0)
+
+#define LL_DELETE_VS2008(head,del)                                                             \
+do {                                                                                           \
+  if ((head) == (del)) {                                                                       \
+    (head)=(head)->next;                                                                       \
+  } else {                                                                                     \
+    char *_tmp = (char*)(head);                                                                \
+    while (head->next && (head->next != (del))) {                                              \
+      head = head->next;                                                                       \
+    }                                                                                          \
+    if (head->next) {                                                                          \
+      head->next = ((del)->next);                                                              \
+    }                                                                                          \
+    {                                                                                          \
+      char **_head_alias = (char**)&(head);                                                    \
+      *_head_alias = _tmp;                                                                     \
+    }                                                                                          \
+  }                                                                                            \
+} while (0)
+#ifdef NO_DECLTYPE
+#undef LL_APPEND
+#define LL_APPEND LL_APPEND_VS2008
+#undef LL_DELETE
+#define LL_DELETE LL_DELETE_VS2008
+#endif
+/* end VS2008 replacements */
+
+#define LL_FOREACH(head,el)                                                                    \
+    for(el=head;el;el=el->next)
+
+#define LL_FOREACH_SAFE(head,el,tmp)                                                           \
+  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
+
+#define LL_SEARCH_SCALAR(head,out,field,val)                                                   \
+do {                                                                                           \
+    LL_FOREACH(head,out) {                                                                     \
+      if ((out)->field == (val)) break;                                                        \
+    }                                                                                          \
+} while(0) 
+
+#define LL_SEARCH(head,out,elt,cmp)                                                            \
+do {                                                                                           \
+    LL_FOREACH(head,out) {                                                                     \
+      if ((cmp(out,elt))==0) break;                                                            \
+    }                                                                                          \
+} while(0) 
+
+/******************************************************************************
+ * doubly linked list macros (non-circular)                                   *
+ *****************************************************************************/
+#define DL_PREPEND(head,add)                                                                   \
+do {                                                                                           \
+ (add)->next = head;                                                                           \
+ if (head) {                                                                                   \
+   (add)->prev = (head)->prev;                                                                 \
+   (head)->prev = (add);                                                                       \
+ } else {                                                                                      \
+   (add)->prev = (add);                                                                        \
+ }                                                                                             \
+ (head) = (add);                                                                               \
+} while (0)
+
+#define DL_APPEND(head,add)                                                                    \
+do {                                                                                           \
+  if (head) {                                                                                  \
+      (add)->prev = (head)->prev;                                                              \
+      (head)->prev->next = (add);                                                              \
+      (head)->prev = (add);                                                                    \
+      (add)->next = NULL;                                                                      \
+  } else {                                                                                     \
+      (head)=(add);                                                                            \
+      (head)->prev = (head);                                                                   \
+      (head)->next = NULL;                                                                     \
+  }                                                                                            \
+} while (0);
+
+#define DL_DELETE(head,del)                                                                    \
+do {                                                                                           \
+  if ((del)->prev == (del)) {                                                                  \
+      (head)=NULL;                                                                             \
+  } else if ((del)==(head)) {                                                                  \
+      (del)->next->prev = (del)->prev;                                                         \
+      (head) = (del)->next;                                                                    \
+  } else {                                                                                     \
+      (del)->prev->next = (del)->next;                                                         \
+      if ((del)->next) {                                                                       \
+          (del)->next->prev = (del)->prev;                                                     \
+      } else {                                                                                 \
+          (head)->prev = (del)->prev;                                                          \
+      }                                                                                        \
+  }                                                                                            \
+} while (0);
+
+
+#define DL_FOREACH(head,el)                                                                    \
+    for(el=head;el;el=el->next)
+
+/* this version is safe for deleting the elements during iteration */
+#define DL_FOREACH_SAFE(head,el,tmp)                                                           \
+  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
+
+/* these are identical to their singly-linked list counterparts */
+#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR
+#define DL_SEARCH LL_SEARCH
+
+/******************************************************************************
+ * circular doubly linked list macros                                         *
+ *****************************************************************************/
+#define CDL_PREPEND(head,add)                                                                  \
+do {                                                                                           \
+ if (head) {                                                                                   \
+   (add)->prev = (head)->prev;                                                                 \
+   (add)->next = (head);                                                                       \
+   (head)->prev = (add);                                                                       \
+   (add)->prev->next = (add);                                                                  \
+ } else {                                                                                      \
+   (add)->prev = (add);                                                                        \
+   (add)->next = (add);                                                                        \
+ }                                                                                             \
+(head)=(add);                                                                                  \
+} while (0)
+
+#define CDL_DELETE(head,del)                                                                   \
+do {                                                                                           \
+  if ( ((head)==(del)) && ((head)->next == (head))) {                                          \
+      (head) = 0L;                                                                             \
+  } else {                                                                                     \
+     (del)->next->prev = (del)->prev;                                                          \
+     (del)->prev->next = (del)->next;                                                          \
+     if ((del) == (head)) (head)=(del)->next;                                                  \
+  }                                                                                            \
+} while (0);
+
+#define CDL_FOREACH(head,el)                                                                   \
+    for(el=head;el;el=(el->next==head ? 0L : el->next)) 
+
+#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2)                                                    \
+  for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL);                                        \
+      (el) && ((tmp2)=(el)->next, 1);                                                          \
+      ((el) = (((el)==(tmp1)) ? 0L : (tmp2))))
+
+#define CDL_SEARCH_SCALAR(head,out,field,val)                                                  \
+do {                                                                                           \
+    CDL_FOREACH(head,out) {                                                                    \
+      if ((out)->field == (val)) break;                                                        \
+    }                                                                                          \
+} while(0) 
+
+#define CDL_SEARCH(head,out,elt,cmp)                                                           \
+do {                                                                                           \
+    CDL_FOREACH(head,out) {                                                                    \
+      if ((cmp(out,elt))==0) break;                                                            \
+    }                                                                                          \
+} while(0) 
+
+#endif /* UTLIST_H */
+


hooks/post-receive
--



More information about the Darshan-commits mailing list