#define INTHREADING
#include <Threading.h>

int	RegisterThread(char *name, char *function, int wait)
{
int	t=0;
char	report[1024];

sprintf(report,"Started (%s)",name);
Error(10,report);

/* Find the next free threading DB no */
while ( t <= 4096 )
   {
   if ( pthread_mutex_trylock(&ThreadDB[t].Mutex) == 0 )
      {
      if ( ThreadDB[t].State == PT_FREE )
         {
         break;
         }
      pthread_mutex_unlock(&ThreadDB[t].Mutex);
      }
   t++;
   }

if ( t > 4096 )
   return -1;

ThreadDB[t].Name = malloc(strlen(name)+1);
if ( ThreadDB[t].Name == 0 )
   {
   Error(2,"Couldn't alloc for thread name");
   return -1;
   }
strcpy(ThreadDB[t].Name,name);
ThreadDB[t].Function = malloc(strlen(function)+1);
if ( ThreadDB[t].Function == 0 )
   {
   Error(2,"Couldn't alloc for thread function");
   return -1;
   }
strcpy(ThreadDB[t].Function,function);
ThreadDB[t].WaitOnToExit = wait;
ThreadDB[t].pID = pthread_self();
ThreadDB[t].State = PT_RUNNING;

pthread_mutex_unlock(&ThreadDB[t].Mutex);
return 0;
}
