Show / Hide Table of Contents

# Class Synchronization

Utilities for inter-thread synchronization. All Locker method acquire their object immediately, and should only be used with langword_csharp_using to automatically release them.

##### Inheritance

Object
Synchronization

##### Inherited Members

Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()

###### Namespace: IPA.Utilities.Async

###### Assembly: IPA.Loader.dll

##### Syntax

    public static class Synchronization

##### Examples

The canonical usage of all of the member functions is as follows, substituting Lock(Mutex) with whichever member you want to use, according to your lock type.

    using var _locker = Synchronization.Lock(mutex);

### Methods

| Improve this Doc View Source

#### Lock(Mutex)

Creates a locker for a mutex.

##### Declaration

    public static Synchronization.MutexLocker Lock(Mutex mut)

##### Parameters

Type | Name | Description
--- | --- | ---
Mutex | mut | the mutex to acquire

##### Returns

Type | Description
--- | ---
Synchronization.MutexLocker | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### Lock(Semaphore)

Creates a locker for a semaphore.

##### Declaration

    public static Synchronization.SemaphoreLocker Lock(Semaphore sem)

##### Parameters

Type | Name | Description
--- | --- | ---
Semaphore | sem | the semaphore to acquire

##### Returns

Type | Description
--- | ---
Synchronization.SemaphoreLocker | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### Lock(SemaphoreSlim)

Creates a locker for a slim semaphore.

##### Declaration

    public static Synchronization.SemaphoreSlimLocker Lock(SemaphoreSlim sem)

##### Parameters

Type | Name | Description
--- | --- | ---
SemaphoreSlim | sem | the slim semaphore to acquire

##### Returns

Type | Description
--- | ---
Synchronization.SemaphoreSlimLocker | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### LockAsync(SemaphoreSlim)

Creates a locker for a slim semaphore asynchronously.

##### Declaration

    public static Task<Synchronization.SemaphoreSlimAsyncLocker> LockAsync(SemaphoreSlim sem)

##### Parameters

Type | Name | Description
--- | --- | ---
SemaphoreSlim | sem | the slim semaphore to acquire async

##### Returns

Type | Description
--- | ---
Task<Synchronization.SemaphoreSlimAsyncLocker> | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### LockRead(ReaderWriterLockSlim)

Creates a locker for a read lock on a ReaderWriterLockSlim.

##### Declaration

    public static Synchronization.ReaderWriterLockSlimReadLocker LockRead(ReaderWriterLockSlim rwl)

##### Parameters

Type | Name | Description
--- | --- | ---
ReaderWriterLockSlim | rwl | the lock to acquire in read mode

##### Returns

Type | Description
--- | ---
Synchronization.ReaderWriterLockSlimReadLocker | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### LockReadUpgradable(ReaderWriterLockSlim)

Creates a locker for an upgradable read lock on a ReaderWriterLockSlim.

##### Declaration

    public static Synchronization.ReaderWriterLockSlimUpgradableReadLocker LockReadUpgradable(ReaderWriterLockSlim rwl)

##### Parameters

Type | Name | Description
--- | --- | ---
ReaderWriterLockSlim | rwl | the lock to acquire in upgradable read mode

##### Returns

Type | Description
--- | ---
Synchronization.ReaderWriterLockSlimUpgradableReadLocker | the locker to use with langword_csharp_using

| Improve this Doc View Source

#### LockWrite(ReaderWriterLockSlim)

Creates a locker for a write lock ReaderWriterLockSlim.

##### Declaration

    public static Synchronization.ReaderWriterLockSlimWriteLocker LockWrite(ReaderWriterLockSlim rwl)

##### Parameters

Type | Name | Description
--- | --- | ---
ReaderWriterLockSlim | rwl | the lock to acquire in write mode

##### Returns

Type | Description
--- | ---
Synchronization.ReaderWriterLockSlimWriteLocker | the locker to use with langword_csharp_using