static void frontend_gx_init(void *data) { (void)data; #ifdef HW_RVL IOS_ReloadIOS(IOS_GetVersion()); L2Enhance(); #ifndef IS_SALAMANDER gx_init_mem2(); #endif #endif #if defined(DEBUG) && defined(IS_SALAMANDER) VIDEO_Init(); GXRModeObj *rmode = VIDEO_GetPreferredMode(NULL); void *xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); #endif #ifndef DEBUG __exception_setreload(8); #endif fatInitDefault(); #ifdef HAVE_LOGGER devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_net; #elif defined(HAVE_FILE_LOGGER) && !defined(IS_SALAMANDER) devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_file; #endif #if defined(HW_RVL) && !defined(IS_SALAMANDER) OSThread gx_device_thread; gx_devices[GX_DEVICE_SD].interface = &__io_wiisd; gx_devices[GX_DEVICE_SD].name = "sd"; gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface); gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage; gx_devices[GX_DEVICE_USB].name = "usb"; gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface); OSInitMutex(&gx_device_cond_mutex); OSInitCond(&gx_device_cond); OSInitMutex(&gx_device_mutex); OSCreateThread(&gx_device_thread, gx_devthread, 0, NULL, NULL, 0, 66, 0); #endif }
void ghs_flock_create(be_val<uint32_t> *lock) { for (auto i = 0; i < GHS_FLOCK_MAX; ++i) { if (!*p_iob_mutex_used[i]) { *lock = i; OSInitMutex(p_iob_mutexes[i]); *p_iob_mutex_used[i] = true; return; } } *lock = -1; gLog->warn("ghs_flock_create ran out of locks!"); }
static void lockMutexNoLock(OSMutex *mutex) { // The following check is disabled as not calling InitMutex does // not break behaviour, and some games do not properly initialise // their mutexes before using them. We manually call OSInitMutex // to avoid triggering any of our own assertions later on... // HACK: This might be a hack around some broken behaviour elsewhere // inside of decaf, it's hard to tell... Let's assume not for now. //decaf_check(mutex->tag == OSMutex::Tag); if (mutex->tag != OSMutex::Tag) { OSInitMutex(mutex); } auto thread = OSGetCurrentThread(); while (mutex->owner && mutex->owner != thread) { thread->mutex = mutex; // Promote mutex owner priority internal::promoteThreadPriorityNoLock(mutex->owner, thread->priority); // Wait for other owner to unlock internal::sleepThreadNoLock(&mutex->queue); internal::rescheduleSelfNoLock(); thread->mutex = nullptr; } if (mutex->owner != thread) { // Add to mutex queue MutexQueue::append(&thread->mutexQueue, mutex); } mutex->owner = thread; mutex->count++; }
void ghs_mtx_init(void *mtx) { auto pmutex = static_cast<be_ptr<OSMutex>*>(mtx); *pmutex = static_cast<OSMutex*>((*pMEMAllocFromDefaultHeapEx)(sizeof(OSMutex), 8)); OSInitMutex(*pmutex); }
static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd) { devoptab_t *dev = NULL; char *devname = NULL; char *devpath = NULL; int i; // Sanity check if (!name) { errno = EINVAL; return -1; } // Allocate a devoptab for this device dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1); if (!dev) { errno = ENOMEM; return -1; } // Use the space allocated at the end of the devoptab for storing the device name devname = (char*)(dev + 1); strcpy(devname, name); // create private data sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1); if(!priv) { free(dev); errno = ENOMEM; return -1; } devpath = (char*)(priv+1); strcpy(devpath, mount_path); // setup private data priv->mount_path = devpath; priv->pClient = pClient; priv->pCmd = pCmd; priv->pMutex = malloc(sizeof(OSMutex)); if(!priv->pMutex) { free(dev); free(priv); errno = ENOMEM; return -1; } OSInitMutex(priv->pMutex); // Setup the devoptab memcpy(dev, &devops_sd_fat, sizeof(devoptab_t)); dev->name = devname; dev->deviceData = priv; // Add the device to the devoptab table (if there is a free slot) for (i = 3; i < STD_MAX; i++) { if (devoptab_list[i] == devoptab_list[0]) { devoptab_list[i] = dev; return 0; } } // failure, free all memory free(priv); free(dev); // If we reach here then there are no free slots in the devoptab table for this device errno = EADDRNOTAVAIL; return -1; }