| 1 | #ifndef AWS_COMMON_CROSS_PROCESS_LOCK_H |
| 2 | #define AWS_COMMON_CROSS_PROCESS_LOCK_H |
| 3 | /** |
| 4 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | * SPDX-License-Identifier: Apache-2.0. |
| 6 | */ |
| 7 | #include <aws/common/byte_buf.h> |
| 8 | #include <aws/common/common.h> |
| 9 | |
| 10 | struct aws_cross_process_lock; |
| 11 | AWS_EXTERN_C_BEGIN |
| 12 | |
| 13 | /** |
| 14 | * Attempts to acquire a system-wide (not per process or per user) lock scoped by instance_nonce. |
| 15 | * For any given unique nonce, a lock will be returned by the first caller. Subsequent calls will |
| 16 | * return NULL and raise AWS_ERROR_MUTEX_CALLER_NOT_OWNER |
| 17 | * until the either the process owning the lock exits or the program owning the lock |
| 18 | * calls aws_cross_process_lock_release() explicitly. |
| 19 | * |
| 20 | * If the process exits before the lock is released, the kernel will unlock it for the next consumer. |
| 21 | */ |
| 22 | AWS_COMMON_API |
| 23 | struct aws_cross_process_lock *aws_cross_process_lock_try_acquire( |
| 24 | struct aws_allocator *allocator, |
| 25 | struct aws_byte_cursor instance_nonce); |
| 26 | |
| 27 | /** |
| 28 | * Releases the lock so the next caller (may be another process) can get an instance of the lock. |
| 29 | */ |
| 30 | AWS_COMMON_API |
| 31 | void aws_cross_process_lock_release(struct aws_cross_process_lock *instance_lock); |
| 32 | |
| 33 | AWS_EXTERN_C_END |
| 34 | |
| 35 | #endif /* AWS_COMMON_CROSS_PROCESS_LOCK_H */ |