1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using Antmicro.Renode.Utilities; 9 10 namespace Antmicro.Renode.Time 11 { 12 /// <summary> 13 /// Represents an object that is aware of time flow. 14 /// </summary> 15 public interface ITimeSink 16 { 17 /// <summary> 18 /// Gets or sets handle used to synchronize time. 19 /// </summary> 20 TimeHandle TimeHandle { get; set; } 21 } 22 23 public static class TimeSinkExtensions 24 { ObtainSinkActiveState(this ITimeSink @this)25 public static IDisposable ObtainSinkActiveState(this ITimeSink @this) 26 { 27 var result = new DisposableWrapper(); 28 @this.TimeHandle.SinkSideActive = true; 29 result.RegisterDisposeAction(() => @this.TimeHandle.SinkSideActive = false); 30 return result; 31 } 32 ObtainSinkInactiveState(this ITimeSink @this)33 public static IDisposable ObtainSinkInactiveState(this ITimeSink @this) 34 { 35 var result = new DisposableWrapper(); 36 @this.TimeHandle.SinkSideActive = false; 37 result.RegisterDisposeAction(() => @this.TimeHandle.SinkSideActive = true); 38 return result; 39 } 40 } 41 } 42