#define INTHREADING
#include <Threading.h>

int GetThreadMsg(char *source, char *type, char *dest, char *data, time_t *timestamp)
{
pthread_t	selfid;
int		t=0;
int		m=0;

selfid = pthread_self();

while ( t <= 4096 )
   {
   if ( ThreadDB[t].State == PT_RUNNING )
      {
      if ( ThreadDB[t].pID == selfid )
         {
         break;
         }
      }
   t++;
   }
if ( t > 4096 )
   return -1;

if ( ThreadDB[t].CurMsg == ThreadDB[t].ProcMsg )
   return -2;

pthread_mutex_lock(&ThreadDB[t].Mutex);
m = ThreadDB[t].ProcMsg;
ThreadDB[t].ProcMsg++;
if ( ThreadDB[t].ProcMsg > 10 )
   ThreadDB[t].ProcMsg = 0;
strcpy(source,ThreadDB[t].MsgQue[m].Source);
strcpy(type,ThreadDB[t].MsgQue[m].Type);
strcpy(dest,ThreadDB[t].MsgQue[m].Dest);
strcpy(data,ThreadDB[t].MsgQue[m].Data);
memcpy(timestamp,&ThreadDB[t].MsgQue[m].TimeStamp,sizeof(ThreadDB[t].MsgQue[m].TimeStamp));
pthread_mutex_unlock(&ThreadDB[t].Mutex);
return ThreadDB[t].MsgQue[m].State;
}
