/*     
 * $RCSfile: trace.c,v $
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 *
 * $Log: trace.c,v $
 * Revision 1.1  1997/03/11  20:47:08  dorgival
 * Initial revision
 *
 * Revision 1.1  1997/03/11 20:47:08  dorgival
 * Initial revision
 *
 *
 */

#include "platform.h"
#include "xk_debug.h"
#include "compose.h"
#include "xk_semaphore.h"
#include "idmap.h"

int always_true(void);

int always_true(void)
{
    return 1;
}

int (*trace_guard)(void) = always_true;

#ifdef TRACEABLE_THREADS

Map traceable_threads;

void
make_thread_untraceable( void* thread )
{
    /*
	xTraceLock();
	fprintf(stderr,"thread 0x%x made untraceable\n",thread);
	xTraceUnlock();
    */
    mapRemoveKey( traceable_threads, thread );
}

void
make_thread_traceable( void* thread )
{
    /*
	xTraceLock();
	fprintf(stderr,"thread 0x%x made traceable\n",thread);
	xTraceUnlock();
    */
    mapBind( traceable_threads, thread, NULL );
}

int
thread_is_traceable( void* thread )
{
    int result;
    result = ( mapResolve( traceable_threads, thread, NULL ) == XK_SUCCESS );
    /*
	xTraceLock();
	fprintf(stderr,"thread 0x%x is %straceable\n",thread, (result)?"":"un");
	xTraceUnlock();
    */
    return result;
}

#endif /* TRACEABLE_THREADS */

#ifdef XK_TRACE_LOCKING
static pthread_mutex_t trace_mutex;
#endif

void
xTraceLock(void)
{
#ifdef XK_TRACE_LOCKING
    pthread_mutex_lock(&trace_mutex);
#endif
}

void
xTraceUnlock(void)
{
#ifdef XK_TRACE_LOCKING
    pthread_mutex_unlock(&trace_mutex);
#endif
}

 

void
xTraceInit(void)
{
#ifdef XK_TRACE_LOCKING
    pthread_mutex_init(&trace_mutex,pthread_mutexattr_default);
#endif
#ifdef TRACEABLE_THREADS
    traceable_threads = mapCreate(113,sizeof(void*));
#endif
    initTraceLevels();
}

