Ejemplo n.º 1
0
static Res rankBufInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args)
{
  Rank rank = BUFFER_RANK_DEFAULT;
  Res res;
  ArgStruct arg;

  AVERT(ArgList, args);
  if (ArgPick(&arg, args, MPS_KEY_RANK))
    rank = arg.val.rank;
  AVERT(Rank, rank);

  /* Initialize the superclass fields first via next-method call */
  res = NextMethod(Buffer, RankBuf, init)(buffer, pool, isMutator, args);
  if (res != ResOK)
    return res;

  BufferSetRankSet(buffer, RankSetSingle(rank));

  SetClassOfPoly(buffer, CLASS(RankBuf));
  AVERC(RankBuf, buffer);
  
  EVENT4(BufferInitRank, buffer, pool, BOOLOF(buffer->isMutator), rank);

  return ResOK;
}
Ejemplo n.º 2
0
void BufferAttach(Buffer buffer, Addr base, Addr limit,
                  Addr init, Size size)
{
  Size filled;

  AVERT(Buffer, buffer);
  AVER(BufferIsReset(buffer));
  AVER(AddrAdd(base, size) <= limit);
  AVER(base <= init);
  AVER(init <= limit);

  /* Set up the buffer to point at the supplied region */
  buffer->mode |= BufferModeATTACHED;
  buffer->base = base;
  buffer->ap_s.init = init;
  buffer->ap_s.alloc = AddrAdd(init, size);
  /* only set limit if not logged */
  if ((buffer->mode & BufferModeLOGGED) == 0) {
    buffer->ap_s.limit = limit;
  } else {
    AVER(buffer->ap_s.limit == (Addr)0);
  }
  AVER(buffer->initAtFlip == (Addr)0);
  buffer->poolLimit = limit;

  filled = AddrOffset(init, limit);
  buffer->fillSize += filled;
  if (buffer->isMutator) {
    if (base != init) { /* see <design/buffer#.count.alloc.how> */
      Size prealloc = AddrOffset(base, init);
      ArenaGlobals(buffer->arena)->allocMutatorSize -= prealloc;
    }
    ArenaGlobals(buffer->arena)->fillMutatorSize += filled;
  } else {
    ArenaGlobals(buffer->arena)->fillInternalSize += filled;
  }

  /* run any class-specific attachment method */
  Method(Buffer, buffer, attach)(buffer, base, limit, init, size);

  AVERT(Buffer, buffer);
  EVENT4(BufferFill, buffer, size, base, filled);
}
Ejemplo n.º 3
0
void LoadStdQuote(const char *sFileName)
{
	FILE *fh;
	int iRec,iSkip,iFail,iOk;
	char m_sBuffer[1024];
	CStdPharser *cp;
	st_quoteitem m_item;
	bool bRet;
	char m_sExchangeID[11];
	char m_sInstrumentID[41];
	char m_sVersion[41];
	char m_sTradingDay[11];
	ST_INTCTRLBLK m_ctrl;
	int iExchange;
	
	
	fh = fopen(sFileName,"rb");
	if (fh == nullptr)
	{
		WARN("Can not open file:%s",sFileName);
		return ;
	}
	cp = new CStdPharser();

	bRet = cp->ReadHeader(fh, m_sExchangeID, m_sInstrumentID, m_sTradingDay, m_sVersion, &m_ctrl,nullptr,nullptr);
	if (bRet == false)
	{
		WARN("Reading STD quote [%s] header failed",sFileName);
		fclose(fh);
		return ;
	}
	iExchange = fCheckExchange(m_sExchangeID);
	if (iExchange<0)
	{
		WARN("Reading STD quote [%s] header failed:Unknown exchange ID",sFileName);
		fclose(fh);
		return ;
	}
	iRec = 0;
	iSkip = 0;
	iFail = 0;
	iOk = 0;
	

	while (cp->ReadLine(fh,sizeof(m_sBuffer),m_sBuffer)==true)
	{
		if (cp->Pharse(m_sBuffer, &m_item) == false)
		{
			iSkip ++;
			continue;
		}
		if (strcmp(m_item.sExchangeID,"--NULL--")==0)
		{
			iSkip ++;
			continue;
		}
		bRet = g_var.m_pMarket[iExchange]->AddQuote(&m_item);
		if (bRet != 0)
			iFail ++;
		else
			iOk  ++;
		iRec++;
	}
	EVENT4("%s STD LoadQuote finished: total %d loaded,%d skipped,%d failed",m_sExchangeID,iOk,iSkip,iFail);
	fclose(fh);
}
Ejemplo n.º 4
0
Bool BufferTrip(Buffer buffer, Addr p, Size size)
{
  Pool pool;

  AVERT(Buffer, buffer);
  AVER(p != 0);
  AVER(size > 0);
  AVER(SizeIsAligned(size, buffer->alignment));

  /* The limit field should be zero, because that's how trip gets */
  /* called.  See .commit.trip. */
  AVER(buffer->ap_s.limit == 0);
  /* Of course we should be trapped. */
  AVER(BufferIsTrapped(buffer));

  /* The init and alloc fields should be equal at this point, because */
  /* the step .commit.update has happened. */
  AVER(buffer->ap_s.init == buffer->ap_s.alloc);

  /* The p parameter points at the base address of the allocated */
  /* block, the end of which should now coincide with the init and */
  /* alloc fields. */
  /* Note that we don't _really_ care about p too much.  We don't */
  /* do anything else with it apart from these checks. (in particular */
  /* it seems like the algorithms could be modified to cope with the */
  /* case of the object having been copied between Commit updating i */
  /* and testing limit) */
  AVER(AddrAdd(p, size) == buffer->ap_s.init);

  pool = BufferPool(buffer);

  AVER(PoolHasAddr(pool, p));

  /* .trip.unflip: If the flip occurred before commit set "init" */
  /* to "alloc" (see .commit.before) then the object is invalid */
  /* (won't've been scanned) so undo the allocation and fail commit. */
  /* Otherwise (see .commit.after) the object is valid (will've been */
  /* scanned) so commit can simply succeed. */
  if ((buffer->mode & BufferModeFLIPPED)
      && buffer->ap_s.init != buffer->initAtFlip) {
    /* Reset just enough state for Reserve/Fill to work. */
    /* The buffer is left trapped and we leave the untrapping */
    /* for the next reserve (which goes out of line to Fill */
    /* (.fill.unflip) because the buffer is still trapped) */
    buffer->ap_s.init = p;
    buffer->ap_s.alloc = p;
    return FALSE;
  }

  /* Emit event including class if logged */
  if (buffer->mode & BufferModeLOGGED) {
    Bool b;
    Format format;
    Addr clientClass;

    b = PoolFormat(&format, buffer->pool);
    if (b) {
      clientClass = format->klass(p);
    } else {
      clientClass = (Addr)0;
    }
    EVENT4(BufferCommit, buffer, p, size, clientClass);
  }
  return TRUE;
}