summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoran Aleksov <zoran.aleksov@seavus.com>2012-05-04 16:05:48 +0200
committerViktor Mladenovski <viktor.mladenovski@seavus.com>2012-05-25 14:45:43 +0200
commit24629b4d05f7b0826c8cd1866d57ddcc4cb949d1 (patch)
tree5d9dd6c4dafd956413b5d289a2301f60e2dd3fcc
parent78bf8bace61dbae9d7d314716dfd356ff639a416 (diff)
sem_open issue
Previous solution is reverted back using compile switches) only for Ubuntu. For Mac OS the problem still exists and will be fixed in different patch. ST-Ericsson ID: 432287 ST-Ericsson FOSS-OUT ID: NA Change-Id: Idd50886392ceb58fb07d0c14ed5c9b88fcc7fd35 Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/58222 Reviewed-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com> Tested-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com>
-rw-r--r--lcmodule/Makefile2
-rw-r--r--source/api_wrappers/linux/CEventObject.cpp32
-rw-r--r--source/api_wrappers/linux/CEventObject.h4
-rw-r--r--source/api_wrappers/linux/CSemaphore.cpp30
-rw-r--r--source/api_wrappers/linux/CSemaphore.h5
-rw-r--r--source/api_wrappers/linux/CSemaphoreQueue.cpp4
-rw-r--r--source/api_wrappers/linux/Types.h2
-rw-r--r--source/api_wrappers/linux/sdf0
8 files changed, 78 insertions, 1 deletions
diff --git a/lcmodule/Makefile b/lcmodule/Makefile
index c418122..3aac38a 100644
--- a/lcmodule/Makefile
+++ b/lcmodule/Makefile
@@ -331,7 +331,7 @@ $(LCM_AUTO_DIR)/.autodirdummy : | $(LCM_AUTO_DIR)
.PHONY: setup_folders
setup_folders: validatevariables
-setup_folders: $(AUTO_DIR_LOADER)/.autodirldrdummy $(AUTO_DIR_LIB)/.autodirlibdummy $(LCM_AUTO_DIR)/.autodirdummy
+setup_folders: $(AUTO_DIR_LOADER)/.autodirldrdummy $(AUTO_DIR_LIB)/.autodirlibdummy $(LCM_AUTO_DIR)/.autodirdummy $(LCMLIB_INSTALLDIR)/.libinstalldummy
@echo $< > /dev/null
diff --git a/source/api_wrappers/linux/CEventObject.cpp b/source/api_wrappers/linux/CEventObject.cpp
index 1a09fa9..eecbe6d 100644
--- a/source/api_wrappers/linux/CEventObject.cpp
+++ b/source/api_wrappers/linux/CEventObject.cpp
@@ -18,6 +18,7 @@
// ******************************************************************************
CEventObject::CEventObject()
{
+#if defined(__APPLE__)
char sem_name[SEM_NAME_MAX_LENGTH];
int sem_nr = 1;
@@ -33,6 +34,9 @@ CEventObject::CEventObject()
sem_nr++;
}
+#elif defined(__linux__)
+ sem_init(&m_sem, 0, 0);
+#endif
}
// ******************************************************************************
@@ -42,7 +46,11 @@ CEventObject::CEventObject()
// ******************************************************************************
CEventObject::~CEventObject()
{
+#if defined(__APPLE__)
sem_close(m_sem);
+#elif defined(__linux__)
+ sem_destroy(&m_sem);
+#endif
}
// ******************************************************************************
@@ -52,7 +60,11 @@ CEventObject::~CEventObject()
// ******************************************************************************
void CEventObject::SetEvent()
{
+#if defined(__APPLE__)
sem_post(m_sem);
+#elif defined(__linux__)
+ sem_post(&m_sem);
+#endif
}
// ******************************************************************************
@@ -62,6 +74,7 @@ void CEventObject::SetEvent()
// ******************************************************************************
DWORD CEventObject::Wait(DWORD dwTimeout)
{
+#if defined(__APPLE__)
if (INFINITE == dwTimeout) {
sem_wait(m_sem);
} else {
@@ -97,4 +110,23 @@ DWORD CEventObject::Wait(DWORD dwTimeout)
}
return WAIT_OBJECT_0;
+
+#elif defined(__linux__)
+ if (INFINITE == dwTimeout) {
+ sem_wait(&m_sem);
+ return WAIT_OBJECT_0;
+ } else {
+ timespec absolute_time = OS::GetAbsoluteTime(dwTimeout);
+ int ret;
+
+ /* coverity[returned_null] */
+ while (-1 == (ret = sem_timedwait(&m_sem, &absolute_time)) && errno == EINTR);
+
+ if (0 == ret) {
+ return WAIT_OBJECT_0;
+ } else {
+ return WAIT_TIMEOUT;
+ }
+ }
+#endif
}
diff --git a/source/api_wrappers/linux/CEventObject.h b/source/api_wrappers/linux/CEventObject.h
index 987b33e..ec7d126 100644
--- a/source/api_wrappers/linux/CEventObject.h
+++ b/source/api_wrappers/linux/CEventObject.h
@@ -33,7 +33,11 @@ public:
void UnsetEvent();
DWORD Wait(DWORD dwTimeout = INFINITE);
private:
+#if defined(__APPLE__)
sem_t *m_sem;
+#elif defined(__linux__)
+ sem_t m_sem;
+#endif
};
#endif /* _CEVENTOBJECT_H */
diff --git a/source/api_wrappers/linux/CSemaphore.cpp b/source/api_wrappers/linux/CSemaphore.cpp
index 166ab88..b7e4224 100644
--- a/source/api_wrappers/linux/CSemaphore.cpp
+++ b/source/api_wrappers/linux/CSemaphore.cpp
@@ -14,6 +14,7 @@
CSemaphore::CSemaphore(unsigned int initial_count)
{
+#if defined(__APPLE__)
char sem_name[SEM_NAME_MAX_LENGTH];
int sem_nr = 1;
@@ -29,11 +30,18 @@ CSemaphore::CSemaphore(unsigned int initial_count)
sem_nr++;
}
+#elif defined(__linux__)
+ sem_init(&m_semaphore, 0, initial_count);
+#endif
}
CSemaphore::~CSemaphore()
{
+#if defined(__APPLE__)
sem_close(m_semaphore);
+#elif defined(__linux__)
+ sem_destroy(&m_semaphore);
+#endif
}
bool CSemaphore::Release(unsigned int count)
@@ -43,7 +51,11 @@ bool CSemaphore::Release(unsigned int count)
}
for (unsigned int i = 0; i < count; ++i) {
+#if defined(__APPLE__)
if (sem_post(m_semaphore)) {
+#elif defined(__linux__)
+ if (sem_post(&m_semaphore)) {
+#endif
return false;
}
}
@@ -53,6 +65,7 @@ bool CSemaphore::Release(unsigned int count)
DWORD CSemaphore::Wait(DWORD timeout)
{
+#if defined(__APPLE__)
if (INFINITE == timeout) {
sem_wait(m_semaphore);
} else {
@@ -88,4 +101,21 @@ DWORD CSemaphore::Wait(DWORD timeout)
}
return WAIT_OBJECT_0;
+#elif defined(__linux__)
+ if (INFINITE == timeout) {
+ sem_wait(&m_semaphore);
+ } else {
+ timespec absoulute_time = OS::GetAbsoluteTime(timeout);
+ int ret;
+
+ /* coverity[returned_null] */
+ while (-1 == (ret = sem_timedwait(&m_semaphore, &absoulute_time)) && errno == EINTR);
+
+ if (0 != ret) {
+ return WAIT_TIMEOUT;
+ }
+ }
+
+ return WAIT_OBJECT_0;
+#endif
}
diff --git a/source/api_wrappers/linux/CSemaphore.h b/source/api_wrappers/linux/CSemaphore.h
index 3d68b63..32d8ca2 100644
--- a/source/api_wrappers/linux/CSemaphore.h
+++ b/source/api_wrappers/linux/CSemaphore.h
@@ -19,7 +19,12 @@ public:
DWORD Wait(DWORD timeout = INFINITE);
private:
+#if defined(__APPLE__)
sem_t *m_semaphore;
+#elif defined(__linux__)
+ sem_t m_semaphore;
+#endif
+
};
#endif /* _CSEMAPHORE_H */
diff --git a/source/api_wrappers/linux/CSemaphoreQueue.cpp b/source/api_wrappers/linux/CSemaphoreQueue.cpp
index 448b4ee..55871ca 100644
--- a/source/api_wrappers/linux/CSemaphoreQueue.cpp
+++ b/source/api_wrappers/linux/CSemaphoreQueue.cpp
@@ -13,7 +13,11 @@
CSemaphoreQueue::CSemaphoreQueue(unsigned int MaxCount) : m_MaximumCount(MaxCount)
{
m_pEventObject = new CEventObject();
+#if defined(__APPLE__)
m_pSemaphore = new CSemaphore(0);
+#elif defined(__linux__)
+ m_pSemaphore = new CSemaphore();
+#endif
m_ObjectCollection.Add(m_pEventObject);
m_ObjectCollection.Add(m_pSemaphore);
diff --git a/source/api_wrappers/linux/Types.h b/source/api_wrappers/linux/Types.h
index 4f720aa..6008996 100644
--- a/source/api_wrappers/linux/Types.h
+++ b/source/api_wrappers/linux/Types.h
@@ -17,8 +17,10 @@ typedef unsigned int DWORD;
#define WINAPI
+#if defined(__APPLE__)
#define SEM_NAME_MAX_LENGTH 16
#define SEM_MAX_NR 1000
+#endif
#endif /* _TYPES_H */
diff --git a/source/api_wrappers/linux/sdf b/source/api_wrappers/linux/sdf
deleted file mode 100644
index e69de29..0000000
--- a/source/api_wrappers/linux/sdf
+++ /dev/null