summaryrefslogtreecommitdiff
path: root/src/components/include/utils/rwlock.h
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2015-02-20 09:11:18 -0500
committerJustin Dickow <jjdickow@gmail.com>2015-02-20 09:11:18 -0500
commita7c5d752cb75485baa0ded5226335d0f8eb10321 (patch)
treefbfd9251ada2cdcd5cf6a03a79887d08f6b496d7 /src/components/include/utils/rwlock.h
parentb2b2233d866f102d3de339afa8ccaf37d3cf2570 (diff)
downloadsdl_core-a7c5d752cb75485baa0ded5226335d0f8eb10321.tar.gz
Bug Fixes and ImprovementsSynchronizationCommit
Fix Empty perform iteration request Fix type of name from string to enum SendLocation implemented on HTML5 HMI Fixed PI response on VR rejection due to high priority. Fix Apps not responsive/not able to start app/apps remain listed on SYNC even after USB disconnect Mobile API change and processing capabilities Change perform interaction request conditions. Fix SDL must always start 3sec timer before resuming the HMILevel of the app Remove redundant StartSavePersistentDataTimer() call. Change wrong predicate name to right. Added stream request handling feature Made streaming timeout in media manager configurable Put navi app in LIMITED in case of phone call Handling of audio state for applications Add stop streaming timeout into ini file Implement HMILevel resumption for job-1 Fix result code ABORTED when interrupts it by Voice recognition activation Fix incorrect value parameter unexpectedDisconnect in BCOnAppUnregistered Fix SDL send BC.OnAppUnregistered with "unexpectedDisconnect" set to "true" in case received from HMI OnExitAllApplications {"reason":"MASTER_RESET"} Fix Update ini file for iAP1 support Current working directory added to image path Fix helpers to make it workable with more then 2 parameters DCHECK() for ManageMobileCommand() replaced with log message because the latter returns false in some regular situations (e.g. TOO_MANY_PENDING_REQUESTS, see SDLAQ-CRS-10) Remove connection after closing. Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/include/utils/rwlock.h')
-rw-r--r--src/components/include/utils/rwlock.h95
1 files changed, 84 insertions, 11 deletions
diff --git a/src/components/include/utils/rwlock.h b/src/components/include/utils/rwlock.h
index b5042acbfe..1083dbd63f 100644
--- a/src/components/include/utils/rwlock.h
+++ b/src/components/include/utils/rwlock.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Ford Motor Company
+ * Copyright (c) 2015, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,8 +30,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SRC_COMPONENTS_UTILS_INCLUDE_UTILS_RWLOCK_H_
-#define SRC_COMPONENTS_UTILS_INCLUDE_UTILS_RWLOCK_H_
+#ifndef SRC_COMPONENTS_INCLUDE_UTILS_RWLOCK_H_
+#define SRC_COMPONENTS_INCLUDE_UTILS_RWLOCK_H_
#if defined(OS_POSIX)
#include <pthread.h>
@@ -49,21 +49,91 @@ typedef pthread_rwlock_t PlatformRWLock;
#endif
} // namespace impl
+/**
+ * RW locks wrapper
+ * Read-write locks permit concurrent reads and exclusive writes to a protected shared resource.
+ * The read-write lock is a single entity that can be locked in read or write mode.
+ * To modify a resource, a thread must first acquire the exclusive write lock.
+ * An exclusive write lock is not permitted until all read locks have been released.
+ */
+
class RWLock {
public:
RWLock();
~RWLock();
- void AcquireForReading();
- void AcquireForWriting();
- void Release();
+
+ /**
+ * @brief Acqure read-write lock for reading.
+ * The calling thread acquires the read lock if a writer does not
+ * hold the lock and there are no writers blocked on the lock.
+ * It is unspecified whether the calling thread acquires the lock
+ * when a writer does not hold the lock and there are writers waiting for the lock.
+ * If a writer holds the lock, the calling thread will not acquire the read lock.
+ * If the read lock is not acquired, the calling thread blocks
+ * (that is, it does not return from the AcquireForReading()) until it can acquire the lock.
+ * Results are undefined if the calling thread holds a write lock on rwlock at the time the call is made.
+ * A thread can hold multiple concurrent read locks on rwlock
+ * (that is, successfully call AcquireForReading() n times)
+ * If so, the thread must perform matching unlocks (that is, it must call Release() n times).
+ * @returns true if lock was acquired and false if was not
+ */
+ bool AcquireForReading();
+
+ /**
+ * @brief try to Acqure read-write lock for reading.
+ * Applies a read lock as in AcquireForReading()
+ * with the exception that the function fails if any thread
+ * holds a write lock on rwlock or there are writers blocked on rwlock.
+ * But not blocks calling thread.
+ * @returns true if lock was acquired and false if was not
+ */
+ bool TryAcquireForReading();
+
+ /**
+ * @brief Try to Acqure read-write lock for writing.
+ * Applies a write lock like AcquireForWriting(), with the exception that the
+ * function fails if any thread currently holds rwlock (for reading or writing)
+ * Invoke of TryAcquireForWriting will not block calling thread and returns "false"
+ * @returns true if lock was acquired and false if was not
+ */
+ bool TryAcquireForWriting();
+
+ /**
+ * @brief Acqure read-write lock for writing.
+ * Applies a write lock to the read-write lock.
+ * The calling thread acquires the write lock if no other thread (reader or writer)
+ * holds the read-write lock rwlock. Otherwise, the thread blocks
+ * (that is, does not return from the AcquireForWriting() call)
+ * until it can acquire the lock.
+ * Results are undefined if the calling thread holds the read-write lock (whether a read or write lock)
+ * at the time the call is made.
+ * The thread must perform matching unlock (that is, it must call Release()).
+ * @returns true if lock was acquired and false if was not
+ */
+ bool AcquireForWriting();
+
+ /**
+ * @brief Release read-write lock.
+ * Releases a lock held on the read-write lock object.
+ * Results are undefined if the read-write lock rwlock
+ * is not held by the calling thread.
+ * @returns true if lock was released and false if was not
+ */
+ bool Release();
private:
impl::PlatformRWLock rwlock_;
};
+/**
+ * @brief Makes auto lock read-write locks for reading
+ * Please use AutoReadLock to acquire for reading and (automatically) release it
+ */
+
class AutoReadLock {
public:
- explicit AutoReadLock(RWLock& rwlock) : rwlock_(rwlock) {
+ explicit AutoReadLock(RWLock& rwlock)
+ : rwlock_(rwlock) {
rwlock_.AcquireForReading();
}
~AutoReadLock() {
@@ -72,13 +142,17 @@ class AutoReadLock {
private:
RWLock& rwlock_;
-
DISALLOW_COPY_AND_ASSIGN(AutoReadLock);
};
+/**
+ * @brief Makes auto lock read-write locks for writing
+ * Please use AutoWriteLock to acquire for writing and (automatically) release it
+ */
class AutoWriteLock {
public:
- explicit AutoWriteLock(RWLock& rwlock) : rwlock_(rwlock) {
+ explicit AutoWriteLock(RWLock& rwlock)
+ : rwlock_(rwlock) {
rwlock_.AcquireForWriting();
}
~AutoWriteLock() {
@@ -87,10 +161,9 @@ class AutoWriteLock {
private:
RWLock& rwlock_;
-
DISALLOW_COPY_AND_ASSIGN(AutoWriteLock);
};
} // namespace sync_primitives
-#endif // SRC_COMPONENTS_UTILS_INCLUDE_UTILS_RWLOCK_H_
+#endif // SRC_COMPONENTS_INCLUDE_UTILS_RWLOCK_H_