dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / acpi / acpica / utlock.c
blob8b4ff11d617abf91a01244ce63392f8346f6f3a2
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utlock - Reader/Writer lock interfaces
6 * Copyright (C) 2000 - 2019, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
13 #define _COMPONENT ACPI_UTILITIES
14 ACPI_MODULE_NAME("utlock")
16 /*******************************************************************************
18 * FUNCTION: acpi_ut_create_rw_lock
19 * acpi_ut_delete_rw_lock
21 * PARAMETERS: lock - Pointer to a valid RW lock
23 * RETURN: Status
25 * DESCRIPTION: Reader/writer lock creation and deletion interfaces.
27 ******************************************************************************/
28 acpi_status acpi_ut_create_rw_lock(struct acpi_rw_lock *lock)
30 acpi_status status;
32 lock->num_readers = 0;
33 status = acpi_os_create_mutex(&lock->reader_mutex);
34 if (ACPI_FAILURE(status)) {
35 return (status);
38 status = acpi_os_create_mutex(&lock->writer_mutex);
39 return (status);
42 void acpi_ut_delete_rw_lock(struct acpi_rw_lock *lock)
45 acpi_os_delete_mutex(lock->reader_mutex);
46 acpi_os_delete_mutex(lock->writer_mutex);
48 lock->num_readers = 0;
49 lock->reader_mutex = NULL;
50 lock->writer_mutex = NULL;
53 /*******************************************************************************
55 * FUNCTION: acpi_ut_acquire_read_lock
56 * acpi_ut_release_read_lock
58 * PARAMETERS: lock - Pointer to a valid RW lock
60 * RETURN: Status
62 * DESCRIPTION: Reader interfaces for reader/writer locks. On acquisition,
63 * only the first reader acquires the write mutex. On release,
64 * only the last reader releases the write mutex. Although this
65 * algorithm can in theory starve writers, this should not be a
66 * problem with ACPICA since the subsystem is infrequently used
67 * in comparison to (for example) an I/O system.
69 ******************************************************************************/
71 acpi_status acpi_ut_acquire_read_lock(struct acpi_rw_lock *lock)
73 acpi_status status;
75 status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER);
76 if (ACPI_FAILURE(status)) {
77 return (status);
80 /* Acquire the write lock only for the first reader */
82 lock->num_readers++;
83 if (lock->num_readers == 1) {
84 status =
85 acpi_os_acquire_mutex(lock->writer_mutex,
86 ACPI_WAIT_FOREVER);
89 acpi_os_release_mutex(lock->reader_mutex);
90 return (status);
93 acpi_status acpi_ut_release_read_lock(struct acpi_rw_lock *lock)
95 acpi_status status;
97 status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER);
98 if (ACPI_FAILURE(status)) {
99 return (status);
102 /* Release the write lock only for the very last reader */
104 lock->num_readers--;
105 if (lock->num_readers == 0) {
106 acpi_os_release_mutex(lock->writer_mutex);
109 acpi_os_release_mutex(lock->reader_mutex);
110 return (status);
113 /*******************************************************************************
115 * FUNCTION: acpi_ut_acquire_write_lock
116 * acpi_ut_release_write_lock
118 * PARAMETERS: lock - Pointer to a valid RW lock
120 * RETURN: Status
122 * DESCRIPTION: Writer interfaces for reader/writer locks. Simply acquire or
123 * release the writer mutex associated with the lock. Acquisition
124 * of the lock is fully exclusive and will block all readers and
125 * writers until it is released.
127 ******************************************************************************/
129 acpi_status acpi_ut_acquire_write_lock(struct acpi_rw_lock *lock)
131 acpi_status status;
133 status = acpi_os_acquire_mutex(lock->writer_mutex, ACPI_WAIT_FOREVER);
134 return (status);
137 void acpi_ut_release_write_lock(struct acpi_rw_lock *lock)
140 acpi_os_release_mutex(lock->writer_mutex);