Just a few helpers.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Sep 2008 09:58:58 +0000 (11:58 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Sep 2008 09:58:58 +0000 (11:58 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/array.h

index 0ca70de..63e66cf 100644 (file)
         array_wipe(array);                                                     \
     } while (0)
 
-#define array_byte_len(array) (array).len * sizeof(*(array).data)
+#define array_len(array) (array).len
+#define array_size(array) (array).size
+#define array_elt_len(array) sizeof(*(array).data)
+#define array_byte_len(array) (array).len * array_elt_len(array)
 
 #define array_lock(array)                                                      \
     ((array).locked                                                            \
-     || (mprotect((array).data, array_byte_len(array), PROT_READ) == 0         \
-         && mlock((array).data, array_byte_len(array)) == 0                    \
-         && ((array).locked = true))                                           \
-     || (mprotect((array).data, array_byte_len(array),                         \
-                  PROT_READ | PROT_WRITE) > 0))
+     || (mlock((array).data, array_byte_len(array)) == 0                       \
+         && ((array).locked = true)))
 #define array_unlock(array)                                                    \
     if ((array).locked) {                                                      \
         (void)munlock((array).data, array_byte_len(array));                    \
-        (void)mprotect((array).data, array_byte_len(array),                    \
-                       PROT_READ | PROT_WRITE);                                \
         (array).locked = false;                                                \
     }