Commit 9274df75 authored by jdelange's avatar jdelange

* include/po_hi_protected.h

   src/po_hi_protected.c
     - Protected objects are now correctly handled on Win32


git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@4632 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent fbbe7afa
......@@ -6,7 +6,7 @@
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2007-2009, GET-Telecom Paris.
* Copyright (C) 2011, European Space Agency.
* Copyright (C) 2011-2012, European Space Agency.
*/
#ifndef __PO_HI_PROTECTED_H__
......@@ -25,13 +25,19 @@
#include <time.h>
#include <pthread.h>
#endif
#if defined (RTEMS_PURE)
#include <rtems.h>
#endif
#if defined (XENO_NATIVE)
#include <native/mutex.h>
#endif
#ifdef _WIN32
#include <windows.h>
#endif
typedef enum
......@@ -64,6 +70,9 @@ typedef struct
#if defined (XENO_NATIVE)
RT_MUTEX xeno_mutex;
#endif
#if defined (_WIN32)
HANDLE win32_mutex;
#endif
}__po_hi_mutex_t;
......
......@@ -6,7 +6,7 @@
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2007-2008, GET-Telecom Paris.
* Copyright (C) 2011, European Space Agency.
* Copyright (C) 2011-2012, European Space Agency.
*/
#include <po_hi_config.h>
......@@ -170,6 +170,14 @@ int __po_hi_mutex_init (__po_hi_mutex_t* mutex, const __po_hi_mutex_protocol_t p
__DEBUGMSG ("[PROTECTED] Cannot create RTEMS binary semaphore\n");
return __PO_HI_ERROR_PROTECTED_CREATE;
}
#endif
#ifdef _WIN32
mutex->win32_mutex = CreateMutex (NULL, FALSE, NULL);
if (mutex->win32_mutex == NULL)
{
__DEBUGMSG ("[PROTECTED] Cannot create WIN32 mutex\n");
return __PO_HI_ERROR_PROTECTED_CREATE;
}
#endif
return (__PO_HI_SUCCESS);
}
......@@ -197,6 +205,22 @@ int __po_hi_mutex_lock (__po_hi_mutex_t* mutex)
__PO_HI_DEBUG_DEBUG ("[PROTECTED] Error when trying to lock mutex\n");
return __PO_HI_ERROR_MUTEX_LOCK;
}
#endif
#ifdef _WIN32
DWORD status;
status = WaitForSingleObject( mutex->win32_mutex, INFINITE);
if (status == WAIT_ABANDONED)
{
__PO_HI_DEBUG_DEBUG ("[PROTECTED] Lock failed (abandon)\n");
return __PO_HI_ERROR_MUTEX_LOCK;
}
if (status == WAIT_FAILED)
{
__PO_HI_DEBUG_DEBUG ("[PROTECTED] Lock failed (failure)\n");
return __PO_HI_ERROR_MUTEX_LOCK;
}
#endif
return __PO_HI_SUCCESS;
}
......@@ -224,7 +248,13 @@ int __po_hi_mutex_unlock (__po_hi_mutex_t* mutex)
return __PO_HI_ERROR_MUTEX_UNLOCK;
}
#endif
#ifdef _WIN32
if (ReleaseMutex (mutex->win32_mutex) == 0)
{
__PO_HI_DEBUG_DEBUG ("[PROTECTED] Release failed\n");
return __PO_HI_ERROR_MUTEX_UNLOCK;
}
#endif
return __PO_HI_SUCCESS;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment