aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/rwlock.h
diff options
context:
space:
mode:
authorAnders Roxell <anders.roxell@linaro.org>2015-01-28 16:46:36 +0100
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-01-29 20:42:32 +0300
commitcb197cd973230fe765adc159ba82bd9edda0dd9f (patch)
tree9d75caf2e2804da37278c424b53cfc8e7371a93d /include/odp/api/rwlock.h
parentc1b9f1d9fca5904f1eae8416a863bf151d53b523 (diff)
api: move generic API into the odp namespace
Move generic API into an api directory. Force the platform implementation to add its own header file that shall include the generic API header file. This splitup enables platform implementors to implement inline functions without modifying the "public" API files. Signed-off-by: Anders Roxell <anders.roxell@linaro.org> Reviewed-by: Balasubramanian Manoharan <bala.manoharan@linaro.org> Reviewed-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'include/odp/api/rwlock.h')
-rw-r--r--include/odp/api/rwlock.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/include/odp/api/rwlock.h b/include/odp/api/rwlock.h
new file mode 100644
index 000000000..f9d418ea2
--- /dev/null
+++ b/include/odp/api/rwlock.h
@@ -0,0 +1,85 @@
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ODP_RWLOCK_H_
+#define ODP_RWLOCK_H_
+
+/**
+ * @file
+ *
+ * ODP RW Locks
+ */
+
+#include <odp/atomic.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup odp_synchronizers ODP SYNCRONIZERS
+ * Operations on reader/writer locks.
+ * A reader/writer lock allows multiple simultaneous readers but only one
+ * writer at a time.
+ * A thread that wants write access will have to wait until there are no
+ * threads that want read access. This casues a risk for starvation.
+ * @{
+ */
+
+/**
+ * The odp_rwlock_t type.
+ */
+typedef struct {
+ odp_atomic_u32_t cnt; /**< @private lock count
+ 0 lock not taken
+ -1 write lock taken
+ >0 read lock(s) taken */
+} odp_rwlock_t;
+
+
+/**
+ * Initialize a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ */
+void odp_rwlock_init(odp_rwlock_t *rwlock);
+
+/**
+ * Acquire read permission on a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ */
+void odp_rwlock_read_lock(odp_rwlock_t *rwlock);
+
+/**
+ * Release read permission on a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ */
+void odp_rwlock_read_unlock(odp_rwlock_t *rwlock);
+
+/**
+ * Acquire write permission on a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ */
+void odp_rwlock_write_lock(odp_rwlock_t *rwlock);
+
+/**
+ * Release write permission on a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ */
+void odp_rwlock_write_unlock(odp_rwlock_t *rwlock);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODP_RWLOCK_H_ */