/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2011 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#ifndef GLUE_ROMIO_H_INCLUDED
#define GLUE_ROMIO_H_INCLUDED

/* TODO we should probaly eliminate this type entirely and just patch up the
 * environment so that intptr_t and uintptr_t always work. */
#define MPIU_Pint int
#define MPIU_Upint unsigned int

#if 0
#define USE_DBG_LOGGING 1
#endif

/* used by ROMIO, should be handled by a romio-private version of this macro
 * instead */
#ifdef HAVE_WINDOWS_H
#define MPIU_UNREFERENCED_ARG(a) a
#else
#define MPIU_UNREFERENCED_ARG(a)
#endif

int MPIR_Ext_assert_fail(const char *cond, const char *file_name, int line_num);

#if (!defined(NDEBUG) && (1))
#define MPIR_Ext_assert(a_)                                \
    do {                                                   \
        if (!(a_)) {                                       \
            MPIR_Ext_assert_fail(#a_, __FILE__, __LINE__); \
        }                                                  \
    } while (0)
#else
#define MPIR_Ext_assert(a_) do {} while(0)
#endif


extern int MPIR_Ext_dbg_romio_terse_enabled;
extern int MPIR_Ext_dbg_romio_typical_enabled;
extern int MPIR_Ext_dbg_romio_verbose_enabled;

/* a copy of MPIU_Ensure_Aint_fits_in_pointer for external use, slightly
 * modified to use ROMIO's version of the pointer-casting macro */
#define MPIR_Ext_ensure_Aint_fits_in_pointer(aint) \
  MPIR_Ext_assert((aint) == (MPI_Aint)(MPIU_Upint) ADIOI_AINT_CAST_TO_VOID_PTR(aint));

/* to be called early by ROMIO's initialization process in order to setup init-time
 * glue code that cannot be initialized statically */
int MPIR_Ext_init(void);

void MPIR_Ext_cs_enter(void);
void MPIR_Ext_cs_exit(void);
void MPIR_Ext_cs_yield(void);

/* to facilitate error checking */
int MPIR_Ext_datatype_iscommitted(MPI_Datatype datatype);

/* prototypes for the mem tracing routines */
void *MPIU_trmalloc(size_t a, int lineno, const char fname[]);
void MPIU_trfree(void *a_ptr, int line, const char fname[]);
void *MPIU_trcalloc(size_t nelem, size_t elsize, int lineno, const char fname[]);
void *MPIU_trrealloc(void *p, size_t size, int lineno, const char fname[]);
void *MPIU_trstrdup(const char *str, int lineno, const char fname[]);

#endif /* defined(GLUE_ROMIO_H_INCLUDED) */

