Beispiel #1
0
void co_switch(cothread_t cothread)
{

   uint32_t argOnReturn = 0;
   if(cothread == (cothread_t)1){
     co_active_ = cothread;
     sceFiberReturnToThread(0, NULL);
   }else{
		 SceFiber* theFiber = (SceFiber*)cothread;
		 if(co_active_ == (cothread_t)1){
			 co_active_ = cothread;
			 sceFiberRun(theFiber, 0, &argOnReturn);
		 }else{
			 co_active_ = cothread;
			 sceFiberSwitch(theFiber, 0, &argOnReturn);
		 }
   }
}
Beispiel #2
0
void Pass::fiberDoPass(int passOffset, int startIndex, int endIndex) {
  Fiber leader __attribute__((aligned(SCE_FIBER_ALIGNMENT)));
  Fiber* followers __attribute__((aligned(SCE_FIBER_ALIGNMENT)));
  SceFiber tailFiber __attribute__((aligned(SCE_FIBER_ALIGNMENT)));
  char m_contextBuffer[CONTEXT_SIZE] __attribute__((aligned(SCE_FIBER_CONTEXT_ALIGNMENT)));
  off_t physicalAddress;

  int ret = SCE_OK;

  ret = sceFiberInitialize(&leader.fiber, "leaderFiber", fiberEntryLeader, (uint64_t) &leader, (void*) m_contextBuffer, CONTEXT_SIZE, NULL);
  assert(ret == SCE_OK);

  leader.nextFiber = &followers[0].fiber;
  leader.directory = &directory;
  leader.spheres = spheres;
  leader.deferSaving = ioMethod == "tio";
  leader.iteration = ioMethod == "tio" ? startIndex : passOffset + startIndex;

  ret = sceFiberInitialize(&tailFiber, "tailFiber", fiberEntryTail, (uint64_t) &tailFiber, (void*) m_contextBuffer, CONTEXT_SIZE, NULL);
  assert(ret == SCE_OK);

  int framesPerThread = endIndex - startIndex;
  size_t totalSize = sizeof(Fiber) * framesPerThread;
  followers = (Fiber*) operator new[](totalSize, physicalAddress);

  int i = startIndex;
  int fiberIndex = 0;
  while (i < endIndex) {
    int iteration = ioMethod == "tio" ? i : passOffset + i;
    for (auto move : moves) {
      move.doMove(spheres[move.getTargetSphere()]);
    }

    ret = sceFiberInitialize(&followers[fiberIndex].fiber, "followerFiber", fiberEntryFollower, (uint64_t) &followers[fiberIndex], (void*) m_contextBuffer, CONTEXT_SIZE, NULL);
    assert(ret == SCE_OK);

    if (fiberIndex != framesPerThread - 1) {
      followers[fiberIndex].nextFiber = &followers[fiberIndex + 1].fiber;
    }
    else {
      followers[fiberIndex].nextFiber = &tailFiber;
    }

    followers[fiberIndex].directory = &directory;
    followers[fiberIndex].spheres = spheres;
    followers[fiberIndex].deferSaving = ioMethod == "tio";
    followers[fiberIndex].iteration = iteration;

    fiberIndex++;
    i++;
  }

  uint64_t argOnReturn = 0;

  leader.nextFiber = &followers[0].fiber;
  ret = sceFiberRun(&leader.fiber, 0, &argOnReturn);
  assert(ret == SCE_OK);
  assert(argOnReturn == 0);

  ret = sceFiberFinalize(&tailFiber);
  assert(ret == SCE_OK);

  for (int i = 0; i < framesPerThread; i++) {
    ret = sceFiberFinalize(&followers[i].fiber);
    assert(ret == SCE_OK);
  }

  ret = sceFiberFinalize(&leader.fiber);
  assert(ret == SCE_OK);

  operator delete[](followers, totalSize, physicalAddress);
}