using System;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Messaging;
using System.Threading;
namespace System.Runtime.Remoting.Contexts
{
/// Enforces a synchronization domain for the current context and all contexts that share the same instance.
// Token: 0x020003CA RID: 970
[AttributeUsage(AttributeTargets.Class)]
[ComVisible(true)]
[Serializable]
public class SynchronizationAttribute : ContextAttribute, IContributeClientContextSink, IContributeServerContextSink
{
/// Initializes a new instance of the class with default values.
// Token: 0x06002637 RID: 9783 RVA: 0x0007E06C File Offset: 0x0007C26C
public SynchronizationAttribute()
: this(8, false)
{
}
/// Initializes a new instance of the class with a Boolean value indicating whether reentry is required.
/// A Boolean value indicating whether reentry is required.
// Token: 0x06002638 RID: 9784 RVA: 0x0007E078 File Offset: 0x0007C278
public SynchronizationAttribute(bool reEntrant)
: this(8, reEntrant)
{
}
/// Initializes a new instance of the class with a flag indicating the behavior of the object to which this attribute is applied.
/// An integer value indicating the behavior of the object to which this attribute is applied.
/// The parameter was not one of the defined flags.
// Token: 0x06002639 RID: 9785 RVA: 0x0007E084 File Offset: 0x0007C284
public SynchronizationAttribute(int flag)
: this(flag, false)
{
}
/// Initializes a new instance of the class with a flag indicating the behavior of the object to which this attribute is applied, and a Boolean value indicating whether reentry is required.
/// An integer value indicating the behavior of the object to which this attribute is applied.
/// true if reentry is required, and callouts must be intercepted and serialized; otherwise, false.
/// The parameter was not one of the defined flags.
// Token: 0x0600263A RID: 9786 RVA: 0x0007E090 File Offset: 0x0007C290
public SynchronizationAttribute(int flag, bool reEntrant)
: base("Synchronization")
{
if (flag != 1 && flag != 4 && flag != 8 && flag != 2)
{
throw new ArgumentException("flag");
}
this._bReEntrant = reEntrant;
this._flavor = flag;
}
/// Gets or sets a Boolean value indicating whether reentry is required.
/// A Boolean value indicating whether reentry is required.
///
///
///
// Token: 0x17000725 RID: 1829
// (get) Token: 0x0600263B RID: 9787 RVA: 0x0007E0EC File Offset: 0x0007C2EC
public virtual bool IsReEntrant
{
get
{
return this._bReEntrant;
}
}
/// Gets or sets a Boolean value indicating whether the implementing this instance of is locked.
/// A Boolean value indicating whether the implementing this instance of is locked.
///
///
///
// Token: 0x17000726 RID: 1830
// (get) Token: 0x0600263C RID: 9788 RVA: 0x0007E0F4 File Offset: 0x0007C2F4
// (set) Token: 0x0600263D RID: 9789 RVA: 0x0007E0FC File Offset: 0x0007C2FC
public virtual bool Locked
{
get
{
return this._locked;
}
set
{
if (value)
{
this._mutex.WaitOne();
lock (this)
{
this._lockCount++;
if (this._lockCount > 1)
{
this.ReleaseLock();
}
this._ownerThread = Thread.CurrentThread;
}
}
else
{
lock (this)
{
while (this._lockCount > 0 && this._ownerThread == Thread.CurrentThread)
{
this._lockCount--;
this._mutex.ReleaseMutex();
this._ownerThread = null;
}
}
}
}
}
// Token: 0x0600263E RID: 9790 RVA: 0x0007E1E8 File Offset: 0x0007C3E8
internal void AcquireLock()
{
this._mutex.WaitOne();
lock (this)
{
this._ownerThread = Thread.CurrentThread;
this._lockCount++;
}
}
// Token: 0x0600263F RID: 9791 RVA: 0x0007E24C File Offset: 0x0007C44C
internal void ReleaseLock()
{
lock (this)
{
if (this._lockCount > 0 && this._ownerThread == Thread.CurrentThread)
{
this._lockCount--;
this._mutex.ReleaseMutex();
this._ownerThread = null;
}
}
}
/// Adds the Synchronized context property to the specified .
/// The to which to add the property.
///
///
///
// Token: 0x06002640 RID: 9792 RVA: 0x0007E2C8 File Offset: 0x0007C4C8
[ComVisible(true)]
public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
{
if (this._flavor != 1)
{
ctorMsg.ContextProperties.Add(this);
}
}
/// Creates a CallOut sink and chains it in front of the provided chain of sinks at the context boundary on the client end of a remoting call.
/// The composite sink chain with the new CallOut sink.
/// The chain of sinks composed so far.
///
///
///
// Token: 0x06002641 RID: 9793 RVA: 0x0007E2E4 File Offset: 0x0007C4E4
public virtual IMessageSink GetClientContextSink(IMessageSink nextSink)
{
return new SynchronizedClientContextSink(nextSink, this);
}
/// Creates a synchronized dispatch sink and chains it in front of the provided chain of sinks at the context boundary on the server end of a remoting call.
/// The composite sink chain with the new synchronized dispatch sink.
/// The chain of sinks composed so far.
///
///
///
// Token: 0x06002642 RID: 9794 RVA: 0x0007E2F0 File Offset: 0x0007C4F0
public virtual IMessageSink GetServerContextSink(IMessageSink nextSink)
{
return new SynchronizedServerContextSink(nextSink, this);
}
/// Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.
/// true if the passed in context is OK; otherwise, false.
/// The context to check.
/// Information gathered at construction time of the context bound object marked by this attribute. The can inspect, add to, and remove properties from the context while determining if the context is acceptable to it.
/// The or parameter is null.
///
///
///
// Token: 0x06002643 RID: 9795 RVA: 0x0007E2FC File Offset: 0x0007C4FC
[ComVisible(true)]
public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
{
SynchronizationAttribute synchronizationAttribute = ctx.GetProperty("Synchronization") as SynchronizationAttribute;
switch (this._flavor)
{
case 1:
return synchronizationAttribute == null;
case 2:
return true;
case 4:
return synchronizationAttribute != null;
case 8:
return false;
}
return false;
}
// Token: 0x06002644 RID: 9796 RVA: 0x0007E360 File Offset: 0x0007C560
internal static void ExitContext()
{
if (Thread.CurrentContext.IsDefaultContext)
{
return;
}
SynchronizationAttribute synchronizationAttribute = Thread.CurrentContext.GetProperty("Synchronization") as SynchronizationAttribute;
if (synchronizationAttribute == null)
{
return;
}
synchronizationAttribute.Locked = false;
}
// Token: 0x06002645 RID: 9797 RVA: 0x0007E3A0 File Offset: 0x0007C5A0
internal static void EnterContext()
{
if (Thread.CurrentContext.IsDefaultContext)
{
return;
}
SynchronizationAttribute synchronizationAttribute = Thread.CurrentContext.GetProperty("Synchronization") as SynchronizationAttribute;
if (synchronizationAttribute == null)
{
return;
}
synchronizationAttribute.Locked = true;
}
/// Indicates that the class to which this attribute is applied cannot be created in a context that has synchronization. This field is constant.
// Token: 0x04000EE2 RID: 3810
public const int NOT_SUPPORTED = 1;
/// Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. This field is constant.
// Token: 0x04000EE3 RID: 3811
public const int SUPPORTED = 2;
/// Indicates that the class to which this attribute is applied must be created in a context that has synchronization. This field is constant.
// Token: 0x04000EE4 RID: 3812
public const int REQUIRED = 4;
/// Indicates that the class to which this attribute is applied must be created in a context with a new instance of the synchronization property each time. This field is constant.
// Token: 0x04000EE5 RID: 3813
public const int REQUIRES_NEW = 8;
// Token: 0x04000EE6 RID: 3814
private bool _bReEntrant;
// Token: 0x04000EE7 RID: 3815
private int _flavor;
// Token: 0x04000EE8 RID: 3816
[NonSerialized]
private bool _locked;
// Token: 0x04000EE9 RID: 3817
[NonSerialized]
private int _lockCount;
// Token: 0x04000EEA RID: 3818
[NonSerialized]
private Mutex _mutex = new Mutex(false);
// Token: 0x04000EEB RID: 3819
[NonSerialized]
private Thread _ownerThread;
}
}