/*
 *  Copyright 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 *
 */

#ifndef _VMS_H
#define	_VMS_H


#include "VMS_primitive_data_types.h"
#include "Queue_impl/BlockingQueue.h"

//This value is the number of hardware threads in the shared memory
// machine
#define NUM_WORKERS 4
#define NUM_SLAVES  8

#define SUCCESS 0

#define thdAttrs NULL

typedef struct WorkUnit   WorkUnit;
typedef struct VMSProcr   VMSProcr;
typedef struct SlaveReqst SlaveReqst;

typedef bool8 (*SlaveScheduler)    ( void * );
typedef void  (*RequestHandler)  ( SlaveReqst * );

typedef struct
 {
   QueueStruc     *workQ;
   unsigned int    id;
 }
ThdParams;

//This is application-level data of the scheduler that runs in the master
// virtual processor.  This data is at a higher level than the slave data-
// struc, which is part of the virtualization infrastructure..  this
// MasterEnv sits on top of that level
typedef struct
 {
   VMSProcr    virtSlaves[ NUM_SLAVES ];
   VMSProcr    virtMaster;
   
   SlaveScheduler  slaveScheduler;
   RequestHandler  requestHandler;

   int         stillRunning;
   WorkUnit   *masterWorkUnit;
   
   VMSProcr  **scheduledSlaves;
   int         numScheduled;

   void       *OSEventStruc;
   void       *semanticEnv;
 }
MasterEnv;


struct WorkUnit
 {
   VMSProcr   *slaveAssignedTo;
   void       *addrToJumpTo;
   void       *workData;

   void       *pluginSpecific;
 };


struct VMSProcr
 {
   WorkUnit    *workUnitToDo;
   SlaveReqst  *requestsToMaster;
   int          workIsDone;
   int          needsWorkAssigned;
 };

struct SlaveReqst
 {
   VMSProcr    *slaveFrom;
   int          reqType;
   void        *reqData;

   SlaveReqst  *nextRequest;
 };



void * coreLoop( void *paramsIn );  //standard PThreads fn prototype


//=====================  Global Vars ===================

pthread_t      coreLoopThds[ NUM_WORKERS ];  // std struc, holds thread info
QueueStruc    *workQ;
ThdParams      thdParams[ NUM_WORKERS ];

MasterEnv     *masterEnv;


#endif	/* _VMS_H */

