// SDK location: /user/pspthreadman.h:1277
        // SDK declaration: int sceKernelAllocateVpl(SceUID uid, unsigned int size, void **data, unsigned int *timeout);
        public int sceKernelAllocateVpl(int uid, int size, int data, int timeout)
        {
            KVariablePool pool = _kernel.GetHandle <KVariablePool>(uid);

            if (pool == null)
            {
                return(-1);
            }

            KMemoryBlock block = pool.Allocate();

            if (block != null)
            {
                Debug.Assert(data != 0);
                unsafe
                {
                    uint *pdata = ( uint * )_memorySystem.Translate(( uint )data);
                    *     pdata = block.Address;
                }

                return(0);
            }
            else
            {
                uint timeoutUs = 0;
                if (timeout != 0)
                {
                    unsafe
                    {
                        uint *ptimeout = ( uint * )_memorySystem.Translate(( uint )timeout);
                        timeoutUs = *ptimeout;
                    }
                }
                KThread thread = _kernel.ActiveThread;
                Debug.Assert(thread != null);
                thread.Wait(pool, ( uint )data, timeoutUs, false);
                return(0);
            }
        }
예제 #2
0
        // SDK location: /user/pspthreadman.h:700
        // SDK declaration: int sceKernelWaitEventFlagCB(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
        public int sceKernelWaitEventFlagCB(int evid, int bits, int wait, int outBits, int timeout)
        {
            // SAME AS ABOVE!

            KEvent ev = _kernel.GetHandle <KEvent>(evid);

            if (ev == null)
            {
                return(-1);
            }

            // TODO: event timeouts
            Debug.Assert(timeout == 0);

            // We may already be set
            if (ev.Matches(( uint )bits, ( KWaitType )wait) == true)
            {
                if (outBits != 0)
                {
                    unsafe
                    {
                        uint *poutBits = ( uint * )_memorySystem.Translate(( uint )outBits);
                        *     poutBits = ev.Value;
                    }
                }

                ev.Clear(( uint )bits, ( KWaitType )wait);
                return(0);
            }
            else
            {
                // No match - wait us
                KThread thread = _kernel.ActiveThread;
                Debug.Assert(thread != null);
                thread.Wait(ev, ( KWaitType )wait, ( uint )bits, ( uint )outBits, ( uint )timeout, true);

                return(0);
            }
        }