umock-c/devdoc/umock_lock_factory_windows.md

98 строки
3.9 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

Lock factory to allow using umock in multithreaded tests (#177) * Add lock/unlock functions specs * Add specs for umock_c_set_lock_functions * Add some tests for lock/unlock * Add test for not initialized for set lock functions * Add unit tests for set lock functions * Update tests for the umock_c unit to check call order * Made all tests pass again with call order for the umock_c unit * Cleanup umock_c unit tests * Fix specs of umock_c unit * Minor update of umockcallrecorder specs * Add mock_lock_functions * Update umockcallrecorder interface * Update CMakeLists * Changed half of umockcallrecorder tests to check order of mocked calls also * Transformed all unit tests for umockcallrecorder to have mock call order * Implement umockcallrecorder_set_lock_functions * Fixed umock_c unit to simply call into the call recorder * Removed backticks * Make umock_c_wout_init_ut build * Builds all tests again * Add locking for umockcallrecorder_reset_all_calls * Add locking to umockcallrecorder_add_expected_call * Add locking for umockcallrecorder_add_actual_call * Add locking for umockcallrecorder_get_actual_calls * Add locking for umockcallrecorder_get_expected_calls * Add locking for umockcallrecorder_get_last_expected_call * Add locking for umockcallrecorder_clone * Implemented locking in umockcallrecorder * Add one more test for resetting lock functions to NULL * Add lock factory and windows lock factory implementation * Add destroy to the lock_if * Add params to lock factory create lock * Add creation and destroy of the lock for call recorder * All tests pass again * call recorder uses not the lock interface * Remove lock/unlock functions in favor of lock factory * Minor fix of int test * Rename test to with_lock_factory * Add int test checking for multithreaded issues * Only run lock factory int tests for Win or Unix * Make the threaded test run on Linux * Tune lock_factory int test for Valgrind * Fix test leaks * Add umock_lock_factory_windows * Add unit tests for umock_lock_factory_windows * Add pthread lock unit tests * Remove backticks * Check that we call pthread_rwlock_destroy for Linux locks * Fix build error in windows lock factory tests * Fix build issue in lock factory windows unit tests * Address CR comments * Fix UT for umock_lock factory for pthread
2020-11-26 06:41:30 +03:00
# umock_lock_factory_windows
## Overview
`umock_lock_factory_windows` is a module that implements the lock factory for `umock_c` for Windows.
## Exposed API
```c
UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params);
```
## static lock functions
```c
static void umock_lock_windows_acquire_shared(UMOCK_C_LOCK_HANDLE lock);
static void umock_lock_windows_release_shared(UMOCK_C_LOCK_HANDLE lock);
static void umock_lock_windows_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock);
static void umock_lock_windows_release_exclusive(UMOCK_C_LOCK_HANDLE lock);
static void umock_lock_windows_destroy(UMOCK_C_LOCK_HANDLE lock);
```
### umockcall_create
```c
UMOCK_C_LOCK_HANDLE umock_lock_factory_create_lock(void* params);
```
`umock_lock_factory_create_lock` creates a new lock to be used by `umock_c`.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_001: [** `umock_lock_factory_create_lock` shall allocate memory for the lock. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_002: [** `umock_lock_factory_create_lock` shall initialize a SRW lock that is encapsulated by the new `UMOCK_C_LOCK_HANDLE`. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_003: [** `umock_lock_factory_create_lock` shall return a lock handle that has the function pointers set to `umock_lock_windows_acquire_shared`, `umock_lock_windows_release_shared`, `umock_lock_windows_acquire_exclusive`, `umock_lock_windows_release_exclusive` and `umock_lock_windows_destroy`. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_004: [** If any error occurs, `umock_lock_factory_create_lock` shall fail and return `NULL`. **]**
### umock_lock_windows_acquire_shared
```c
static void umock_lock_windows_acquire_shared(UMOCK_C_LOCK_HANDLE lock);
```
`umock_lock_windows_acquire_shared` acquires the lock in shared mode.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_010: [** If `lock` is `NULL`, `umock_lock_windows_acquire_shared` shall return. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_005: [** `umock_lock_windows_acquire_shared` shall acquire the lock in shared mode by calling `AcquireSRWLockShared`. **]**
### umock_lock_windows_release_shared
```c
static void umock_lock_windows_release_shared(UMOCK_C_LOCK_HANDLE lock);
```
`umock_lock_windows_release_shared` releases the lock that was acquired in shared mode.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_011: [** If `lock` is `NULL`, `umock_lock_windows_release_shared` shall return. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_006: [** `umock_lock_windows_release_shared` shall release the lock that was acquired in shared mode by calling `ReleaseSRWLockShared`. **]**
### umock_lock_windows_acquire_exclusive
```c
static void umock_lock_windows_acquire_exclusive(UMOCK_C_LOCK_HANDLE lock);
```
`umock_lock_windows_acquire_exclusive` acquires the lock in exclusive mode.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_012: [** If `lock` is `NULL`, `umock_lock_windows_acquire_exclusive` shall return. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_007: [** `umock_lock_windows_acquire_exclusive` shall acquire the lock in exclusive mode by calling `AcquireSRWLockExclusive`. **]**
### umock_lock_windows_release_exclusive
```c
static void umock_lock_windows_release_exclusive(UMOCK_C_LOCK_HANDLE lock);
```
`umock_lock_windows_release_exclusive` releases the lock that was acquired in exclusive mode.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_013: [** If `lock` is `NULL`, `umock_lock_windows_release_exclusive` shall return. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_008: [** `umock_lock_windows_release_exclusive` shall release the lock that was acquired in exclusive mode by calling `ReleaseSRWLockExclusive`. **]**
### umock_lock_windows_destroy
```c
static void umock_lock_windows_destroy(UMOCK_C_LOCK_HANDLE lock);
```
`umock_lock_windows_destroy` frees the resources associated with the lock.
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_014: [** If `lock` is `NULL`, `umock_lock_windows_destroy` shall return. **]**
**SRS_UMOCK_LOCK_FACTORY_WINDOWS_01_009: [** `umock_lock_windows_destroy` shall free the memory associated with the lock. **]**