/* --------------------------------------------------------------------------
   Time-stamp: <Thu Dec 23 2010 21:30:30 Stardate: Stardate: [-28]4184.48 hwloidl>

   High Level Communications Header (HLC.h)

   Contains the high-level definitions (i.e. communication
   subsystem independent) used by GUM
   Phil Trinder, Glasgow University, 12 December 1994
   H-W. Loidl, Heriot-Watt, November 1999
   ----------------------------------------------------------------------- */

#ifndef __HLC_H
#define __HLC_H

// -----------------------------------------------------------------------------
// TODO: move this into ParallelRts.h or DataComms.h
// -----------------------------------------------------------------------------

#if 0
// PARALLEL_RTS

# error HLC.h should not be used any more; include ParallelRTs.h instead

#include "ParallelRts.h"
#include "LLC.h"

//@node Message-Processing Functions
//@subsection Message-Processing Functions

void        unpackPorts(Port *sender, Port *receiver);
StgClosure *unpackRFork(void);
// void        processDataMsg(Capability *cap, OpCode tag);

#if 0
// these are now set via Rts flags (see includes/rts/Flags.h)
#define NEW_FISH_AGE           0
#define NEW_FISH_HISTORY       0
#define NEW_FISH_HUNGER        0
#define FISH_LIFE_EXPECTANCY  10
#endif

//@node GUM Message Sending and Unpacking Functions
//@subsection GUM Message Sending and Unpacking Functions

/* now declared in ParallelRts.h -- HWL GUM6
void 	 sendFetch (globalAddr *ga, globalAddr *bqga, int load);
void 	 sendResume(globalAddr *rga, int nelem, rtsPackBuffer *packBuffer);
void 	 sendAck (nat task, int ngas, globalAddr *gagamap);
void 	 sendFish (nat destPE, nat origPE, int age, int history, int hunger);
void 	 sendFree (nat destPE, int nelem, P_ data);
void 	 sendSchedule(nat origPE, int nelem, rtsPackBuffer *packBuffer);
void 	 sendReval(nat origPE, int nelem, rtsPackBuffer *data);
*/
//@node Message-Processing Functions
//@subsection Message-Processing Functions

// void 	 processTheRealFetches(void);

void     processFish(Capability *cap, OpCode opcode, nat origPE, long *recvBuffer);
void     processSchedule(Capability *cap, nat sender, long *recvBuffer);

// extern StgTSO *PendingFetches;
extern nat advisory_thread_count;
extern nat outstandingFishes ;
extern rtsTime last_fish_arrived_at;
extern rtsTime next_fish_to_send_at;

//@node Miscellaneous Functions
//@subsection Miscellaneous Functions

#if defined(DEBUG)
void checkPendingFetches(rtsBool in_gc);
#endif
void 	freeRemoteGA (int pe, globalAddr *ga);
// NB: GlobalTaskId doesn't exist any more; it's just a nat (see MPSystem.c) -- HWL GUM6

//now declared in ParallelRts.h -- HWL GUM6
/*void    offLoadSpark(StgInt pe, rtsSpark spark);
void 	prepareFreeMsgBuffers(void);
void 	freeRemoteGA (int pe, globalAddr *ga);
void 	sendFreeMessages(void);

// nat  choosePE(void); 
StgClosure   *createBlockedFetch (globalAddr ga, globalAddr rga);
*/
nat  choosePE(void); 
// StgClosure   *createBlockedFetch (globalAddr ga, globalAddr rga);
#define NEW_FISH_AGE           0
#define NEW_FISH_HISTORY       0
#define NEW_FISH_HUNGER        0
#define FISH_LIFE_EXPECTANCY  10

/* I'm not sure if those functions are necessary in the new implementation. */
/* void 	      waitForTermination(void); */
 void          DebugPrintGAGAMap (globalAddr *gagamap, int nGAs); 


// things only needed for fish/spark mechanism

//void 	 sendFish (GlobalTaskId destPE, GlobalTaskId origPE, int age, int history, int hunger); mustafa 
//void 	 sendFree (GlobalTaskId destPE, int nelem, P_ data);
//void 	 sendSchedule(GlobalTaskId origPE, int nelem, rtsPackBuffer *packBuffer);
//void 	 sendReval(GlobalTaskId origPE, int nelem, rtsPackBuffer *data);

#endif /* PARALLEL_RTS */
#endif /* __HLC_H */
