diff mbox

[API-NEXT,PATCHv3,17/18] drv: adding spinlock.h

Message ID 1469102786-65530-18-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard July 21, 2016, 12:06 p.m. UTC
Based on API interface file.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 include/odp/drv/spec/spinlock.h | 86 +++++++++++++++++++++++++++++++++++++++++
 platform/Makefile.inc           |  1 +
 2 files changed, 87 insertions(+)
 create mode 100644 include/odp/drv/spec/spinlock.h

-- 
2.7.4
diff mbox

Patch

diff --git a/include/odp/drv/spec/spinlock.h b/include/odp/drv/spec/spinlock.h
new file mode 100644
index 0000000..52efb56
--- /dev/null
+++ b/include/odp/drv/spec/spinlock.h
@@ -0,0 +1,86 @@ 
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODPDRV spinlock
+ */
+
+#ifndef ODPDRV_API_SPINLOCK_H_
+#define ODPDRV_API_SPINLOCK_H_
+#include <odp/visibility_begin.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup odpdrv_locks
+ * @details
+ * <b> Spin lock (odpdrv_spinlock_t) </b>
+ *
+ * Spinlock simply re-tries to acquire the lock as long as takes to succeed.
+ * Spinlock is not fair since some threads may succeed more often than others.
+ * @{
+ */
+
+/**
+ * @typedef odpdrv_spinlock_t
+ * ODPDRV spinlock
+ */
+
+/**
+ * Initialize spin lock.
+ *
+ * @param splock Pointer to a spin lock
+ */
+void odpdrv_spinlock_init(odpdrv_spinlock_t *splock);
+
+/**
+ * Acquire spin lock.
+ *
+ * @param splock Pointer to a spin lock
+ */
+void odpdrv_spinlock_lock(odpdrv_spinlock_t *splock);
+
+/**
+ * Try to acquire spin lock.
+ *
+ * @param splock Pointer to a spin lock
+ *
+ * @retval  0 lock not acquired
+ * @retval !0 lock acquired
+ */
+int odpdrv_spinlock_trylock(odpdrv_spinlock_t *splock);
+
+/**
+ * Release spin lock.
+ *
+ * @param splock Pointer to a spin lock
+ */
+void odpdrv_spinlock_unlock(odpdrv_spinlock_t *splock);
+
+/**
+ * Check if spin lock is busy (locked).
+ *
+ * @param splock Pointer to a spin lock
+ *
+ * @retval 1 lock busy (locked)
+ * @retval 0 lock not busy.
+ */
+int odpdrv_spinlock_is_locked(odpdrv_spinlock_t *splock);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#include <odp/visibility_end.h>
+#endif
diff --git a/platform/Makefile.inc b/platform/Makefile.inc
index 900b023..404c798 100644
--- a/platform/Makefile.inc
+++ b/platform/Makefile.inc
@@ -67,5 +67,6 @@  odpdrvspecinclude_HEADERS = \
 		  $(top_srcdir)/include/odp/drv/spec/atomic.h \
 		  $(top_srcdir)/include/odp/drv/spec/byteorder.h \
 		  $(top_srcdir)/include/odp/drv/spec/compiler.h \
+		  $(top_srcdir)/include/odp/drv/spec/spinlock.h \
 		  $(top_srcdir)/include/odp/drv/spec/std_types.h \
 		  $(top_srcdir)/include/odp/drv/spec/sync.h