/*
  File dldet.h

  Definitions, etc for deadlock detector.

  pfh 11/19/2000
*/
#if !defined(DLDET_H_)
#define DELDET_H_

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

// Size limits
const static uint32_t DLD_TRACK_COUNT = 128;

// Value for pthreads success
const static int PTHREAD_SUCCESS = 0;
const static int PTHREAD_ERROR = -1;

// Structure defining tracking info for a mutex
typedef struct
{
    pthread_mutex_t  *mutex;        // Keep pointer to real mutex
    uint32_t         lock_count;    // Zero if free
    pthread_t        *thr_owner;    // Ptr to current owner
} dld_mutex_t;

// Structure defining the array of per-thread tracked mutexes
// Allocated at thread creation, updated when our code is caled.
typedef struct
{
    pthread_t       thread_id;
    dld_mutex_t     mlist[DLD_TRACK_COUNT];
} tsd_t;

// Function prototypes
int dld_dmt_init(dld_mutex_t *dmt);
void pthread_once_routine(void);
int dld_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
		       void *(*start)(void *), void *arg);

int dld_pthread_mutex_lock(const pthread_mutex_t *mutex);
int dld_pthread_mutex_unlock(const pthread_mutex_t *mutex);

void *dld_pthread_startup(void *(*start)(void *), void *arg);

