Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

lock.h File Reference

lock.h File Reference

A minimalistic platform agnostic lock abstraction for thread synchronization. More...

Go to the source code of this file.

Functions

 DEFINE_ENUM (LOCK_RESULT, LOCK_RESULT_VALUES)
 Enumeration specifying the lock status.
 MOCKABLE_FUNCTION (, LOCK_HANDLE, Lock_Init)
 This API creates and returns a valid lock handle.
 MOCKABLE_FUNCTION (, LOCK_RESULT, Lock, LOCK_HANDLE, handle)
 Acquires a lock on the given lock handle.
 MOCKABLE_FUNCTION (, LOCK_RESULT, Unlock, LOCK_HANDLE, handle)
 Releases the lock on the given lock handle.
 MOCKABLE_FUNCTION (, LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle)
 The lock instance is destroyed.

Detailed Description

A minimalistic platform agnostic lock abstraction for thread synchronization.

The Lock component is implemented in order to achieve thread synchronization, as we may have a requirement to consume locks across different platforms. This component exposes some generic APIs so that it can be extended for platform specific implementations.

Definition in file lock.h.


Function Documentation

DEFINE_ENUM ( LOCK_RESULT  ,
LOCK_RESULT_VALUES   
)

Enumeration specifying the lock status.

MOCKABLE_FUNCTION ( LOCK_RESULT  ,
Lock_Deinit  ,
LOCK_HANDLE  ,
handle   
)

The lock instance is destroyed.

Parameters:
handleA valid handle to the lock.
Returns:
Returns LOCK_OK when the lock object has been destroyed and LOCK_ERROR when an error occurs.
MOCKABLE_FUNCTION ( LOCK_RESULT  ,
Unlock  ,
LOCK_HANDLE  ,
handle   
)

Releases the lock on the given lock handle.

Uses platform specific mutex primitives in its implementation.

Parameters:
handleA valid handle to the lock.
Returns:
Returns LOCK_OK when the lock has been released and LOCK_ERROR when an error occurs.
MOCKABLE_FUNCTION ( LOCK_RESULT  ,
Lock  ,
LOCK_HANDLE  ,
handle   
)

Acquires a lock on the given lock handle.

Uses platform specific mutex primitives in its implementation.

Parameters:
handleA valid handle to the lock.
Returns:
Returns LOCK_OK when a lock has been acquired and LOCK_ERROR when an error occurs.
MOCKABLE_FUNCTION ( LOCK_HANDLE  ,
Lock_Init   
)

This API creates and returns a valid lock handle.

Returns:
A valid LOCK_HANDLE when successful or NULL otherwise.