You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/08/13 20:09:03 UTC

[GitHub] andrzej-kaczmarek closed pull request #1327: kernel/os: Optimize os_mempool poison

andrzej-kaczmarek closed pull request #1327: kernel/os: Optimize os_mempool poison
URL: https://github.com/apache/mynewt-core/pull/1327
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/kernel/os/src/os_mempool.c b/kernel/os/src/os_mempool.c
index 8b448bc76c..5df846dfd3 100644
--- a/kernel/os/src/os_mempool.c
+++ b/kernel/os/src/os_mempool.c
@@ -35,28 +35,44 @@ STAILQ_HEAD(, os_mempool) g_os_mempool_list =
 #if MYNEWT_VAL(OS_MEMPOOL_POISON)
 static uint32_t os_mem_poison = 0xde7ec7ed;
 
+_Static_assert(sizeof(struct os_memblock) % 4 == 0, "sizeof(struct os_memblock) shall be aligned to 4");
+_Static_assert(sizeof(os_mem_poison) == 4, "sizeof(os_mem_poison) shall be 4");
+
 static void
 os_mempool_poison(void *start, int sz)
 {
-    int i;
-    char *p = start;
+    uint32_t *p;
+    uint32_t *end;
+
+    assert(((uintptr_t)start & 0x03) == 0);
+    assert((sz & 0x03) == 0);
+
+    p = start;
+    end = p + sz / 4;
+    p += sizeof(struct os_memblock) / 4;
 
-    for (i = sizeof(struct os_memblock); i < sz;
-         i = i + sizeof(os_mem_poison)) {
-        memcpy(p + i, &os_mem_poison, min(sizeof(os_mem_poison), sz - i));
+    while (p < end) {
+        *p = os_mem_poison;
+        p++;
     }
 }
 
 static void
 os_mempool_poison_check(void *start, int sz)
 {
-    int i;
-    char *p = start;
+    uint32_t *p;
+    uint32_t *end;
+
+    assert(((uintptr_t)start & 0x03) == 0);
+    assert((sz & 0x03) == 0);
+
+    p = start;
+    end = p + sz / 4;
+    p += sizeof(struct os_memblock) / 4;
 
-    for (i = sizeof(struct os_memblock); i < sz;
-         i = i + sizeof(os_mem_poison)) {
-        assert(!memcmp(p + i, &os_mem_poison,
-               min(sizeof(os_mem_poison), sz - i)));
+    while (p < end) {
+        assert(*p == os_mem_poison);
+        p++;
     }
 }
 #else


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services