/*
 * Copyright (c) 2004 MIPS Technologies, Inc.
 * 
 * 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.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * 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.
 */

/*
 * pthread/rtpxint.h: RTPX user-visible internals 
 */

#ifndef __PTHREAD_RTPXINT_H
#define __PTHREAD_RTPXINT_H

#ifdef __cplusplus
extern "C" {
#endif

/* 
 * RTPX SPECIFIC EXTENSIONS, WHICH ARE NOT
 * REQUIRED BY <pthread.h>, BUT MAY BE CALLED BY 
 * KNOWLEDGABLE USERS.
 */

/* debug hooks */
extern unsigned int _rtpx_evlog_mask;
extern unsigned int _rtpx_evlog_size;
void _rtpx_elog_dump (void);

/* print thread table */
void _rtpx_threadstat (void);

/* print thread table via user-supplied printf function */
void _rtpx_threadstat_user (int (*)(const char *, ...));

/* print mutex state */
struct pthread_mutex;
void _rtpx_mutexstat (const struct pthread_mutex *);

struct _rtpx_eloginfo {
    const char	* 	fmt;
    int 		nargs;
    int 		intern;
};

void _rtpx_elog (struct _rtpx_eloginfo *, ...);
/*  __attribute__((format(printf,2,3)));*/

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L

/* ISO C99 vararg macros */

/* user-level logging */
#define _RTPX_ELOG(fmt, ...) \
   do { \
    static struct _rtpx_eloginfo _einfo = {fmt, -1, 0}; \
    _rtpx_elog (&_einfo, ## __VA_ARGS__); \
   } while (0)

/* kernel-level logging */
#define _RTPX_ELOG_INTERN(fmt, ...) \
   do { \
    static struct _rtpx_eloginfo _einfo = {fmt, -1, 1}; \
    _rtpx_elog (&_einfo, ## __VA_ARGS__); \
   } while (0)

#else

#if defined(__GNUC__) && ! defined(__STRICT_ANSI__)

/* GNU vararg macro extension */

/* user-level logging */
#define _RTPX_ELOG(fmt, args...) \
   do { \
    static struct _rtpx_eloginfo _einfo = {fmt, -1, 0}; \
    _rtpx_elog (&_einfo , ## args); \
   } while (0)

/* kernel-level logging */
#define _RTPX_ELOG_INTERN(fmt, args...) \
   do { \
    static struct _rtpx_eloginfo _einfo = {fmt, -1, 1}; \
    _rtpx_elog (&_einfo , ## args); \
   } while (0)

#endif /* GNUC && ! __STRICT_ANSI__ */

#endif /* __STDC_VERSION__ < 199901L */

#ifdef __cplusplus
}
#endif

#endif /* __PTHREAD_RTPXINT_H */
