/// <summary>
        /// This method creates a mutable resource vault.  It is internal because it should be called only by a <see cref="LockedVaultMutableResource{TVault,TResource}"/>
        /// It is not intended to be used directly by client code.
        /// </summary>
        /// <param name="vault">the vault that this locked resource is obtained from</param>
        /// <param name="box">The vault's box object</param>
        /// <returns>the locked mutable resource vault.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="Exception"></exception>
        internal static LockedVaultMutableResource <TVault, TResource> CreateLockedResource([NotNull] TVault vault,
                                                                                            [NotNull] Vault <TResource> .Box box)
        {
            Func <TVault, Vault <TResource> .Box, Vault <TResource> .Box> releaseFunc = AtomicVault <TResource> .ReleaseResourceMethod;
            var temp = new LockedVaultMutableResource <TVault, TResource>(vault, box, releaseFunc);

            return(temp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the LockedResource.  Until you actually return it to the ultimate consumer in one of the <see cref="Lock()"/> or <see cref="SpinLock()"/>
        /// methods (which are annotated with <see cref="UsingMandatoryAttribute"/>, guaranteeing disposal) it is YOUR responsiblity to make sure
        /// that the item is disposed IN ANY PATH THAT DOES NOT RESULT IN THE USER GETTING THE LOCKED RESOURCE REQUESTED.  This include exceptions,
        /// short-circuited returns, etc.
        /// </summary>
        /// <param name="timeout">How long should be wait.  If null, wait forever</param>
        /// <param name="token">A cancellation token that can be used to cancel attempting to obtain the resource.</param>
        /// <param name="spin">true for busy wait, false for yielding wait</param>
        /// <returns>A locked vault mutable resource</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeout"/> was not-null but was not positive</exception>
        /// <exception cref="TimeoutException">operation not completed in time (should be handled by user not by me or you ... except, see above, we need
        /// to dispose the resource ourselves if we've obtained it ... before rethrowing)</exception>
        /// <exception cref="OperationCanceledException">the operation was cancelled and the cancellation was received via <paramref name="token"/>.
        /// The user should handle this, not you or me (except, if we obtained the resource we need to dispose it before rethrowing).</exception>
        protected LockedVaultMutableResource <MutableResourceVault <T>, T> PerformLock(TimeSpan?timeout, CancellationToken token, bool spin)
        {
            if (timeout == null)
            {
                using (AtomicLockedResource ilr = GetInternalLockedResource(token, spin))
                {
                    return(LockedVaultMutableResource <MutableResourceVault <T>, T> .CreateLockedResource(this, ilr.Release()));
                }
            }

            using (AtomicLockedResource ilr = GetInternalLockedResource(timeout.Value, token, spin))
            {
                return(LockedVaultMutableResource <MutableResourceVault <T>, T> .CreateLockedResource(this, ilr.Release()));
            }
        }
Ejemplo n.º 3
0
 internal static LockedLaundryMachine CreateLockedResource(
     LockedVaultMutableResource <MutableResourceVault <LaundryMachine>, LaundryMachine> me) =>
 new LockedLaundryMachine(me);
Ejemplo n.º 4
0
 internal static LockedLsf CreateLockedResource(
     LockedVaultMutableResource <MutableResourceVault <LaundryStatusFlags>, LaundryStatusFlags> me)
 => new LockedLsf(me);
Ejemplo n.º 5
0
 internal static LockedStringBuilder CreateLockedResource(
     LockedVaultMutableResource <MutableResourceVault <StringBuilder>, StringBuilder> me)
 => new LockedStringBuilder(me);