summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-01-26 07:21:27 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-01-26 07:21:27 +0000
commitf5e8b882e0ffd2383c65b4e146a2720fd322ec8d (patch)
tree7b108501ce47ec756abb632209005624240a7d47
parent74b23fb2a68d3fd88b4d6987d23899fa9e4b6101 (diff)
downloadeina-f5e8b882e0ffd2383c65b4e146a2720fd322ec8d.tar.gz
Eina: fix compilation errors in Eina_RWLock code when building code on Windows > XP
SVN revision: 67545
-rw-r--r--ChangeLog4
-rw-r--r--NEWS7
-rw-r--r--src/include/eina_inline_lock_win32.x59
3 files changed, 56 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 19bfb3f..84c1190 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -202,3 +202,7 @@
2012-01-20 Gustavo Barbieri
* Add eina_model data type (generic hierarchy data access).
+
+2011-12-30 Vincent Torri
+
+ * Fix Eina_RWLock code on Windows > XP.
diff --git a/NEWS b/NEWS
index 328f974..49e2178 100644
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,12 @@ Additions:
* Added eina_value data type (generic value storage)
* Added eina_model data type (generic hierarchy data access)
-Eina 1.1.0
+Fixes:
+
+ * compilation errors in Eina_RWLock code when building code on Windows > XP
+
+
+Eina 1.1.0 (2011-12-02)
Changes since Eina 1.0.0:
-------------------------
diff --git a/src/include/eina_inline_lock_win32.x b/src/include/eina_inline_lock_win32.x
index e8363d5..2239c69 100644
--- a/src/include/eina_inline_lock_win32.x
+++ b/src/include/eina_inline_lock_win32.x
@@ -23,6 +23,9 @@
typedef CRITICAL_SECTION Eina_Lock;
typedef struct _Eina_Condition Eina_Condition;
+typedef struct _Eina_RWLock Eina_RWLock;
+typedef DWORD Eina_TLS;
+typedef HANDLE Eina_Semaphore;
#if _WIN32_WINNT >= 0x0600
struct _Eina_Condition
@@ -30,6 +33,13 @@ struct _Eina_Condition
CRITICAL_SECTION *mutex;
CONDITION_VARIABLE condition;
};
+
+struct _Eina_RWLock
+{
+ SRWLOCK mutex;
+
+ Eina_Bool is_read_mode : 1;
+};
#else
struct _Eina_Condition
{
@@ -40,28 +50,24 @@ struct _Eina_Condition
HANDLE waiters_done;
Eina_Bool was_broadcast;
};
-#endif
-
-typedef struct _Eina_Win32_RWLock Eina_RWLock;
-struct _Eina_Win32_RWLock
+struct _Eina_RWLock
{
- LONG readers_count;
- LONG writers_count;
- int readers;
- int writers;
+ LONG readers_count;
+ LONG writers_count;
+ int readers;
+ int writers;
Eina_Lock mutex;
Eina_Condition cond_read;
Eina_Condition cond_write;
};
+#endif
-typedef DWORD Eina_TLS;
-
-typedef HANDLE Eina_Semaphore;
EAPI extern Eina_Bool _eina_threads_activated;
+
static inline Eina_Bool
eina_lock_new(Eina_Lock *mutex)
{
@@ -143,9 +149,9 @@ eina_condition_new(Eina_Condition *cond, Eina_Lock *mutex)
CloseHandle(cond->semaphore);
return EINA_FALSE;
}
+#endif
return EINA_TRUE;
-#endif
}
static inline void
@@ -153,6 +159,7 @@ eina_condition_free(Eina_Condition *cond)
{
#if _WIN32_WINNT >= 0x0600
/* Nothing to do */
+ (void)cond;
#else
CloseHandle(cond->waiters_done);
DeleteCriticalSection(&cond->waiters_count_lock);
@@ -309,14 +316,18 @@ eina_condition_signal(Eina_Condition *cond)
if (!ReleaseSemaphore(cond->semaphore, 1, 0))
return EINA_FALSE;
}
+#endif
return EINA_TRUE;
-#endif
}
static inline Eina_Bool
eina_rwlock_new(Eina_RWLock *mutex)
{
+#if _WIN32_WINNT >= 0x0600
+ InitializeSRWLock(mutex->mutex);
+ return EINA_TRUE;
+#else
if (!eina_lock_new(&(mutex->mutex))) return EINA_FALSE;
if (!eina_condition_new(&(mutex->cond_read), &(mutex->mutex)))
goto on_error1;
@@ -330,19 +341,28 @@ eina_rwlock_new(Eina_RWLock *mutex)
on_error1:
eina_lock_free(&(mutex->mutex));
return EINA_FALSE;
+#endif
}
static inline void
eina_rwlock_free(Eina_RWLock *mutex)
{
+#if _WIN32_WINNT >= 0x0600
+ (void)mutex;
+#else
eina_condition_free(&(mutex->cond_read));
eina_condition_free(&(mutex->cond_write));
eina_lock_free(&(mutex->mutex));
+#endif
}
static inline Eina_Lock_Result
eina_rwlock_take_read(Eina_RWLock *mutex)
{
+#if _WIN32_WINNT >= 0x0600
+ AcquireSRWLockShared(mutex->mutex);
+ mutex->is_read_mode = EINA_TRUE;
+#else
DWORD res;
if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL)
@@ -364,6 +384,7 @@ eina_rwlock_take_read(Eina_RWLock *mutex)
if (res == 0)
mutex->readers++;
eina_lock_release(&(mutex->mutex));
+#endif
return EINA_LOCK_SUCCEED;
}
@@ -371,6 +392,10 @@ eina_rwlock_take_read(Eina_RWLock *mutex)
static inline Eina_Lock_Result
eina_rwlock_take_write(Eina_RWLock *mutex)
{
+#if _WIN32_WINNT >= 0x0600
+ AcquireSRWLockExclusive(mutex->mutex);
+ mutex->is_read_mode = EINA_FALSE;
+#else
DWORD res;
if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL)
@@ -391,6 +416,7 @@ eina_rwlock_take_write(Eina_RWLock *mutex)
}
if (res == 0) mutex->writers_count = 1;
eina_lock_release(&(mutex->mutex));
+#endif
return EINA_LOCK_SUCCEED;
}
@@ -398,6 +424,12 @@ eina_rwlock_take_write(Eina_RWLock *mutex)
static inline Eina_Lock_Result
eina_rwlock_release(Eina_RWLock *mutex)
{
+#if _WIN32_WINNT >= 0x0600
+ if (mutex->is_read_mode)
+ ReleaseSRWLockShared(mutex->mutex);
+ else
+ ReleaseSRWLockExclusive(mutex->mutex);
+#else
if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL)
return EINA_LOCK_FAIL;
@@ -433,6 +465,7 @@ eina_rwlock_release(Eina_RWLock *mutex)
}
}
eina_lock_release(&(mutex->mutex));
+#endif
return EINA_LOCK_SUCCEED;
}