示例#1
0
        internal BassStream(StreamHandle handle)
        {
            if (!BassNative.Singleton.IsHandleValid(handle))
            {
                throw new InvalidOperationException();
            }

            Handle = handle;
            Info   = BassNative.Singleton.GetChannelInfo(Handle);
            if (Info.plugin != PluginHandle.Null && BassNative.Singleton.Plugins.TryGetValue(Info.plugin, out var value))
            {
                Log.Information($"Using bass plugin {value.manifest.Name} version {value.info.version} to play {Info.FileName}");
            }

            BassNative.Singleton.PlayChannel(Handle);

            _failProc    = (u, channel, data, user) => BassNative.Singleton.Restart();
            _restartSync = BassNative.Singleton.SetSync(handle, BassSync.DevFail, 0, _failProc, IntPtr.Zero);

            _freeProc = (u, channel, data, user) =>
            {
                _streamFreed = true;
                if (Monitor.TryEnter(_freeLock))
                {
                    GC.SuppressFinalize(this);
                    _disposed = true;
                    Monitor.Exit(_freeLock);
                }
            };
            BassNative.Singleton.SetSync(handle, BassSync.Free, 0, _freeProc, IntPtr.Zero);
        }
        internal bool WaitOneNoGC()
        {
            bool b = SyncHandle.WaitOneNoGC(handle);

            GC.KeepAlive(this);
            return(b);
        }
        //| <include path='docs/doc[@for="WaitHandle.WaitOne1"]/*' />
        public override bool WaitOne(SchedulerTime stop)
        {
            bool b = SyncHandle.WaitOne(handle, stop);

            GC.KeepAlive(this);
            return(b);
        }
        //| <include path='docs/doc[@for="SyncHandle.WaitOne2"]/*' />
        public override bool WaitOne()
        {
            bool b = SyncHandle.WaitOne(handle);

            GC.KeepAlive(this);
            return(b);
        }
        //| <include path='docs/doc[@for="WaitHandle.WaitOne"]/*' />
        public override bool WaitOne(TimeSpan timeout)
        {
            bool b = SyncHandle.WaitOne(handle, timeout);

            GC.KeepAlive(this);
            return(b);
        }
        public sealed override bool TrackChanges(object newValue, SyncContext context)
        {
            if (newValue != value)
            {
                value = newValue;
                if (value == null)
                {
                    PoolID   = 0;
                    EntityID = SyncHandle.NullEntityID;
                }
                else
                {
                    SyncHandle handle = context.GetLinkedHandleByObject(value, out ushort poolID);
                    if (handle != null)
                    {
                        EntityID = handle.EntityID;
                        PoolID   = poolID;
                    }
                    else
                    {
                        EntityID = SyncHandle.NullEntityID;
                        PoolID   = 0;
                    }
                }

                Synchronised = false;
                Revision     = context.Revision;
                return(true);
            }
            return(false);
        }
示例#7
0
 public void PushSelectSyncHandles(SyncHandle[] cache)
 {
     for (int i = 0; i < cache.Length; i++)
     {
         cache[i] = new SyncHandle();
     }
     selectSyncHandlesStack.Push(cache);
 }
示例#8
0
        //| <include path='docs/doc[@for="WaitHandleHandle.WaitAny2"]/*' />
        public static unsafe int WaitAny(WaitHandle[] waitHandles)
        {
            SyncHandle[] handles = Thread.CurrentThread.GetSyncHandles(waitHandles.Length);
            for (int i = 0; i < waitHandles.Length; i++)
            {
                handles[i] = waitHandles[i].Handle;
            }

            fixed(SyncHandle *array = &handles[0])
            {
                return(SyncHandle.WaitAny(array, waitHandles.Length));
            }
        }
示例#9
0
文件: Sync.cs 项目: ianuub/Ryujinxxx
        public void Create(ulong id)
        {
            SyncHandle handle = new SyncHandle
            {
                ID     = id,
                Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None)
            };

            lock (Handles)
            {
                Handles.Add(handle);
            }
        }
示例#10
0
        public sealed override void UpdateReferences(SyncContext context)
        {
            SyncHandle handle = context.GetHandle(EntityID);

            if (handle != null)
            {
                if (ReferenceType.IsAssignableFrom(handle.Obj.GetType()))
                {
                    value = handle.Obj;
                }
                Synchronised      = false;
                ReferencesPending = false;
            }
        }
示例#11
0
文件: Sync.cs 项目: zjcom/Ryujinx
        public void Create(ulong id)
        {
            SyncHandle handle = new SyncHandle
            {
                ID     = id,
                Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None)
            };

            // Force commands to flush up to the syncpoint.
            GL.ClientWaitSync(handle.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 0);

            lock (Handles)
            {
                Handles.Add(handle);
            }
        }
示例#12
0
        public void Create(ulong id)
        {
            MultiFenceHolder waitable = new MultiFenceHolder();

            _gd.FlushAllCommands();
            _gd.CommandBufferPool.AddWaitable(waitable);

            SyncHandle handle = new SyncHandle
            {
                ID       = id,
                Waitable = waitable
            };

            lock (_handles)
            {
                _handles.Add(handle);
            }
        }
示例#13
0
文件: Sync.cs 项目: ianuub/Ryujinxxx
        public void Cleanup()
        {
            // Iterate through handles and remove any that have already been signalled.

            while (true)
            {
                SyncHandle first = null;
                lock (Handles)
                {
                    first = Handles.FirstOrDefault();
                }

                if (first == null)
                {
                    break;
                }

                WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 0);

                if (syncResult == WaitSyncStatus.AlreadySignaled)
                {
                    // Delete the sync object.
                    lock (Handles)
                    {
                        lock (first)
                        {
                            _firstHandle = first.ID + 1;
                            Handles.RemoveAt(0);
                            GL.DeleteSync(first.Handle);
                            first.Handle = IntPtr.Zero;
                        }
                    }
                }
                else
                {
                    // This sync handle and any following have not been reached yet.
                    break;
                }
            }
        }
示例#14
0
文件: Sync.cs 项目: ianuub/Ryujinxxx
        public void Wait(ulong id)
        {
            SyncHandle result = null;

            lock (Handles)
            {
                if ((long)(_firstHandle - id) > 0)
                {
                    return; // The handle has already been signalled or deleted.
                }

                foreach (SyncHandle handle in Handles)
                {
                    if (handle.ID == id)
                    {
                        result = handle;
                        break;
                    }
                }
            }

            if (result != null)
            {
                lock (result)
                {
                    if (result.Handle == IntPtr.Zero)
                    {
                        return;
                    }

                    WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000);

                    if (syncResult == WaitSyncStatus.TimeoutExpired)
                    {
                        Logger.Error?.PrintMsg(LogClass.Gpu, $"GL Sync Object {result.ID} failed to signal within 1000ms. Continuing...");
                    }
                }
            }
        }
示例#15
0
        public void Cleanup()
        {
            // Iterate through handles and remove any that have already been signalled.

            while (true)
            {
                SyncHandle first = null;
                lock (_handles)
                {
                    first = _handles.FirstOrDefault();
                }

                if (first == null)
                {
                    break;
                }

                bool signaled = first.Waitable.WaitForFences(_gd.Api, _device, 0);
                if (signaled)
                {
                    // Delete the sync object.
                    lock (_handles)
                    {
                        lock (first)
                        {
                            _firstHandle = first.ID + 1;
                            _handles.RemoveAt(0);
                            first.Waitable = null;
                        }
                    }
                }
                else
                {
                    // This sync handle and any following have not been reached yet.
                    break;
                }
            }
        }
示例#16
0
        public void Wait(ulong id)
        {
            SyncHandle result = null;

            lock (_handles)
            {
                if ((long)(_firstHandle - id) > 0)
                {
                    return; // The handle has already been signalled or deleted.
                }

                foreach (SyncHandle handle in _handles)
                {
                    if (handle.ID == id)
                    {
                        result = handle;
                        break;
                    }
                }
            }

            if (result != null)
            {
                lock (result)
                {
                    if (result.Waitable == null)
                    {
                        return;
                    }

                    bool signaled = result.Waitable.WaitForFences(_gd.Api, _device, 1000000000);
                    if (!signaled)
                    {
                        Logger.Error?.PrintMsg(LogClass.Gpu, $"VK Sync Object {result.ID} failed to signal within 1000ms. Continuing...");
                    }
                }
            }
        }
示例#17
0
        public sealed override bool TrackChanges(object newValue, SyncContext context)
        {
            if (newValue != value)
            {
                value = newValue;
                if (value == null)
                {
                    EntityID = SyncHandle.NullEntityID;
                }
                else
                {
                    SyncHandle handle = context.GetHandleByObject(value);

                    // If no handle is found, then the supplie object is not in the syncpool.
                    //TODO: Here we could optionally add the object to the pool for laughs.
                    EntityID = (handle != null) ? handle.EntityID : SyncHandle.NullEntityID;
                }

                Synchronised = false;
                Revision     = context.Revision;
                return(true);
            }
            return(false);
        }
示例#18
0
 public override bool WaitOne()
 {
     return(SyncHandle.WaitOne(Handle));
 }
示例#19
0
 public override bool WaitOne(SchedulerTime stop)
 {
     return(SyncHandle.WaitOne(Handle, stop));
 }
示例#20
0
 public override bool WaitOne(TimeSpan timeout)
 {
     return(SyncHandle.WaitOne(Handle, timeout));
 }
示例#21
0
 public SyncWaitHandle(SyncHandle s)
 {
     _sync = s;
 }
示例#22
0
 /// <summary>
 /// Wait for a message to arrive on this endpoint.
 /// </summary>
 public static void Wait(ref EndpointCore ep)
 {
     SyncHandle.WaitOne(GetWaitHandle(ref ep));
 }
示例#23
0
 public static void Wait(ref EndpointCore ep)
 {
     SyncHandle.WaitOne(ep.cachedMessageEvent);
 }
示例#24
0
        /// <summary>
        /// Connects the pairs.
        /// </summary>
        public DirectoryFile(FileSystemInfo LocalFile, RemoteFile RemoteFile, DirectoryLogItem LogItem)
        {
            Size = 0;
            if (LocalFile == null)
            {
                Name        = RemoteFile.Name;
                Size        = RemoteFile.Length;
                IsDirectory = RemoteFile.IsDirectory;
            }
            else
            {
                Name = LocalFile.Name;
                FileAttributes attr = File.GetAttributes(LocalFile.FullName);
                IsDirectory = attr.HasFlag(FileAttributes.Directory);
                if (!IsDirectory)
                {
                    Size = new FileInfo(LocalFile.FullName).Length;
                }
            }

            Handle          = SyncHandle.Nothing;
            this.LogItem    = LogItem;
            this.LocalFile  = LocalFile;
            this.RemoteFile = RemoteFile;

            if (LocalFile != null && RemoteFile != null)
            {
                //If file can be found (!)previously & locally & remotely => Find the one with the lastest changes
                if (IsDirectory)
                {
                    Handle = SyncHandle.Synchronize;
                }
                else
                {
                    //Synchronize
                    if (LocalFile.LastWriteTimeUtc.Ticks == LogItem.LocalTicks && RemoteFile.LastWriteTimeUtc.Ticks != LogItem.RemoteTicks)
                    {
                        Handle = SyncHandle.Download;
                    }
                    else if (LocalFile.LastWriteTimeUtc.Ticks != LogItem.LocalTicks && RemoteFile.LastWriteTimeUtc.Ticks == LogItem.RemoteTicks)
                    {
                        Handle = SyncHandle.Upload;
                    }
                    else if (LocalFile.LastWriteTimeUtc.Ticks != LogItem.LocalTicks && RemoteFile.LastWriteTimeUtc.Ticks != LogItem.RemoteTicks)
                    {
                        if (LocalFile.LastWriteTimeUtc.Ticks < RemoteFile.LastWriteTimeUtc.Ticks)
                        {
                            //Download
                            Handle = SyncHandle.Download;
                        }
                        else if (LocalFile.LastWriteTimeUtc.Ticks > RemoteFile.LastWriteTimeUtc.Ticks)
                        {
                            //Upload
                            Handle = SyncHandle.Upload;
                        }
                    }
                }
            }
            else if (LogItem.Equals(DirectoryLogItem.Empty))
            {
                if (LocalFile != null && RemoteFile == null)
                {
                    //If file can be found !previously & locally & !remotely => Upload
                    Handle = SyncHandle.NewUpload;
                }
                else if (LocalFile == null && RemoteFile != null)
                {
                    //If file can be found !previously & !locally & remotely => Download
                    Handle = SyncHandle.NewDownload;
                }
            }
            else
            {
                if (LocalFile != null && RemoteFile == null)
                {
                    //If file can be found previously & locally & !remotely => Delete local (If local & previously LastWriteTime is the same, otherwise upload)
                    if (LocalFile.LastWriteTimeUtc.Ticks == LogItem.LocalTicks)
                    {
                        Handle = SyncHandle.DeleteLocal;
                    }
                    else
                    {
                        Handle = SyncHandle.NewUpload;
                    }
                }
                else if (LocalFile == null && RemoteFile != null)
                {
                    //If file can be found previously & !locally & remotely => Delete remote (If remote & previously LastWriteTime is the same, otherwise download)
                    if (RemoteFile.LastWriteTimeUtc.Ticks == LogItem.RemoteTicks)
                    {
                        Handle = SyncHandle.DeleteRemote;
                    }
                    else
                    {
                        Handle = SyncHandle.NewDownload;
                    }
                }
            }
        }