private void onLwMutexModified(SceKernelLwMutexInfo info) {
    ThreadManForUser threadMan = Modules.ThreadManForUserModule;
    boolean reschedule = false;

    if ((info.attr & PSP_LWMUTEX_ATTR_PRIORITY) == PSP_LWMUTEX_ATTR_FIFO) {
      for (Iterator<SceKernelThreadInfo> it = Modules.ThreadManForUserModule.iterator();
          it.hasNext(); ) {
        SceKernelThreadInfo thread = it.next();
        if (thread.isWaitingForType(PSP_WAIT_LWMUTEX)
            && thread.wait.LwMutex_id == info.uid
            && tryLockLwMutex(info, thread.wait.LwMutex_count, thread)) {
          // New thread is taking control of LwMutex.
          info.threadid = thread.uid;
          // Update numWaitThreads
          info.numWaitThreads--;
          // Return success or failure
          thread.cpuContext.gpr[2] = 0;
          // Wakeup
          threadMan.hleChangeThreadState(thread, PSP_THREAD_READY);
          reschedule = true;
        }
      }
    } else if ((info.attr & PSP_LWMUTEX_ATTR_PRIORITY) == PSP_LWMUTEX_ATTR_PRIORITY) {
      for (Iterator<SceKernelThreadInfo> it = Modules.ThreadManForUserModule.iteratorByPriority();
          it.hasNext(); ) {
        SceKernelThreadInfo thread = it.next();
        if (thread.isWaitingForType(PSP_WAIT_LWMUTEX)
            && thread.wait.LwMutex_id == info.uid
            && tryLockLwMutex(info, thread.wait.LwMutex_count, thread)) {
          // New thread is taking control of LwMutex.
          info.threadid = thread.uid;
          // Update numWaitThreads
          info.numWaitThreads--;
          // Return success or failure
          thread.cpuContext.gpr[2] = 0;
          // Wakeup
          threadMan.hleChangeThreadState(thread, PSP_THREAD_READY);
          reschedule = true;
        }
      }
    }
    // Reschedule only if threads waked up.
    if (reschedule) {
      Modules.ThreadManForUserModule.hleRescheduleCurrentThread();
    }
  }
Exemplo n.º 2
0
  @HLEFunction(nid = 0xB287BD61, version = 150)
  public int sceGeDrawSync(@CheckArgument("checkMode") int mode) {
    if (mode == 0 && IntrManager.getInstance().isInsideInterrupt()) {
      log.debug("sceGeDrawSync (mode==0) cannot be called inside an interrupt handler!");
      return SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT;
    }

    // no synchronization on "this" required because we are not accessing
    // local data, only list information from the VideoEngine.
    int result = 0;
    if (mode == 0) {
      PspGeList lastList;
      if (ExternalGE.isActive()) {
        lastList = ExternalGE.getLastDrawList();
      } else {
        lastList = VideoEngine.getInstance().getLastDrawList();
      }

      if (lastList != null) {
        blockCurrentThreadOnList(lastList, new HLEAfterDrawSyncAction());
      } else {
        if (log.isDebugEnabled()) {
          log.debug("sceGeDrawSync all lists completed, not waiting");
        }
        hleGeAfterDrawSyncAction();
        Modules.ThreadManForUserModule.hleRescheduleCurrentThread();
      }
    } else if (mode == 1) {
      PspGeList currentList;
      if (ExternalGE.isActive()) {
        currentList = ExternalGE.getFirstDrawList();
      } else {
        currentList = VideoEngine.getInstance().getFirstDrawList();
      }
      if (currentList != null) {
        result = currentList.status;
      }
      if (log.isDebugEnabled()) {
        log.debug(String.format("sceGeDrawSync mode=%d, returning %d", mode, result));
      }
    }

    return result;
  }