summaryrefslogtreecommitdiffstats
path: root/nci/jni/Mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'nci/jni/Mutex.h')
-rw-r--r--nci/jni/Mutex.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/nci/jni/Mutex.h b/nci/jni/Mutex.h
new file mode 100644
index 0000000..c858e8e
--- /dev/null
+++ b/nci/jni/Mutex.h
@@ -0,0 +1,93 @@
+/*****************************************************************************
+**
+** Name: Mutex.h
+**
+** Description: Encapsulate a mutex for thread synchronization.
+**
+** Copyright (c) 2012, Broadcom Corp., All Rights Reserved.
+** Proprietary and confidential.
+**
+*****************************************************************************/
+
+#pragma once
+#include <pthread.h>
+
+
+class Mutex
+{
+public:
+ /*******************************************************************************
+ **
+ ** Function: Mutex
+ **
+ ** Description: Initialize member variables.
+ **
+ ** Returns: None.
+ **
+ *******************************************************************************/
+ Mutex ();
+
+
+ /*******************************************************************************
+ **
+ ** Function: ~Mutex
+ **
+ ** Description: Cleanup all resources.
+ **
+ ** Returns: None.
+ **
+ *******************************************************************************/
+ ~Mutex ();
+
+
+ /*******************************************************************************
+ **
+ ** Function: lock
+ **
+ ** Description: Block the thread and try lock the mutex.
+ **
+ ** Returns: None.
+ **
+ *******************************************************************************/
+ void lock ();
+
+
+ /*******************************************************************************
+ **
+ ** Function: unlock
+ **
+ ** Description: Unlock a mutex to unblock a thread.
+ **
+ ** Returns: None.
+ **
+ *******************************************************************************/
+ void unlock ();
+
+
+ /*******************************************************************************
+ **
+ ** Function: tryLock
+ **
+ ** Description: Try to lock the mutex.
+ **
+ ** Returns: True if the mutex is locked.
+ **
+ *******************************************************************************/
+ bool tryLock ();
+
+
+ /*******************************************************************************
+ **
+ ** Function: nativeHandle
+ **
+ ** Description: Get the handle of the mutex.
+ **
+ ** Returns: Handle of the mutex.
+ **
+ *******************************************************************************/
+ pthread_mutex_t* nativeHandle ();
+
+private:
+ pthread_mutex_t mMutex;
+};
+