コード例 #1
0
ファイル: MemMgrPrimSimple.c プロジェクト: B-Rich/EBBlib
EBBRC
EBBMemMgrPrimSimpleInit()
{
  static CObjEBBRootMultiImp theRoot;
  CObjEBBRootMultiImpRef rootRef = &theRoot;
  EBBMemMgrPrimSimpleRef repRef;
  EBBLTrans *lt;
  EBBRC rc;
  EBBId id;
  
  if (__sync_bool_compare_and_swap(&(theEBBMemMgrPrimId), 0, -1)) {
    CObjEBBRootMultiImpStaticInit(rootRef, MemMgrPrimRB_createRep);
    rc = EBBAllocPrimIdBoot(&id);
    LRT_RCAssert(rc);
    rc = CObjEBBBindBoot(id, rootRef); 
    LRT_RCAssert(rc);
    
    __sync_bool_compare_and_swap(&(theEBBMemMgrPrimId), -1, id);
  } else {   
    // racing with root creation...wait till root is ready
    while (((volatile uintptr_t)theEBBMemMgrPrimId)==-1);
  }
  // no where to alloc rep from other than the memory
  // we are creating this rep to manage so we do the obvious
  // and hack off some memory for the rep itself.
  // "create the rep"
  repRef = (EBBMemMgrPrimSimpleRef)lrt_mem_start();

  // initialize the rep memory
  EBBMemMgrPrimSimpleSetFT(repRef); 
  init_rep(repRef, (CObjEBBRootMultiRef)rootRef, lrt_mem_end());

  // manually install rep into local table so that memory allocations 
  // can work immediate without recursion
  lt = (EBBLTrans *)lrt_trans_id2lt((uintptr_t)theEBBMemMgrPrimId);
  EBBCacheObj(lt, (EBBRep *)repRef); 

  // it is now safe to call the allocator assuming that the 
  // ltrans is stable between last and the next one that 
  // may use dynamic memory to add the rep to the root
  rootRef->ft->addRepOn((CObjEBBRootMultiRef)rootRef, MyEL(), (EBBRep *)repRef);

  // Ok at this point the memory manager is up on this EL
  // and missing on the local table is also safe for this EL
  // as the rep has been added explicity to the root.

  return EBBRC_OK;
}
コード例 #2
0
ファイル: mlx_line.c プロジェクト: ffredon/corewar
void			line_px_img(t_struck *s, int *l, int col)
{
	float	x;
	float	y;
	float	rep;
	float	d[3];

	x = 0;
	y = 0;
	d[1] = l[1] - l[3];
	d[2] = l[0] - l[2];
	rep = init_rep(d[2], d[1]);
	while (x != d[2] || y != d[1])
	{
		px_img(s, l[0] - x, l[1] - y, col);
		if ((fabs(d[2]) >= fabs(d[1])) || fabs(y) >= fabs(rep))
			trace_line_bis(d[2], d[1], &x, &rep);
		if ((fabs(d[1]) >= fabs(d[2])) || fabs(x) >= fabs(rep))
			trace_line_bis(d[1], d[2], &y, &rep);
	}
}