From aea79e82e14f6d9059ed3a75c0f0a31cdf967597 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 30 Dec 2002 23:59:59 +0000 Subject: [PATCH] Added comments to asm Original commit message from CVS: Added comments to asm --- gst/gsttrashstack.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/gst/gsttrashstack.h b/gst/gsttrashstack.h index 98259671e7..25422b9157 100644 --- a/gst/gsttrashstack.h +++ b/gst/gsttrashstack.h @@ -73,9 +73,9 @@ gst_trash_stack_push (GstTrashStack *stack, gpointer mem) { __asm__ __volatile__ ( "1: \n\t" - " movl %2, (%1); \n\t" - " lock; cmpxchg %1, %0; \n\t" - " jnz 1b; \n" + " movl %2, (%1); \n\t" /* mem->next == stack->head */ + " lock; cmpxchg %1, %0; \n\t" /* if head unchanged, move mem into it */ + " jnz 1b; \n" /* head changed, retry */ : : "m" (*stack), "r" (mem), @@ -88,15 +88,22 @@ gst_trash_stack_pop (GstTrashStack *stack) { GstTrashStackElement *head; + /* pop is a little more complicated as we need to avoid the so called ABA + * problem that arises when a pop and push of the same element happens + * right between when we read head->next and try to swing the new pointer + * into place. This is usually solved using a counter which makes it highly + * inlikely that we manage to grab the wrong head->next value. + */ __asm__ __volatile__ ( - " testl %%eax, %%eax; \n\t" + " testl %%eax, %%eax; \n\t" /* if (head == NULL) return */ " jz 20f; \n\t" "10: \n\t" - " movl (%%eax), %%ebx; \n\t" - " movl %%edx, %%ecx; \n\t" - " incl %%ecx; \n\t" - " lock; cmpxchg8b %1; \n\t" - " jnz 10b; \n\t" + " movl (%%eax), %%ebx; \n\t" /* take value pointed to by head (head->next) */ + " movl %%edx, %%ecx; \n\t" /* take counter */ + " incl %%ecx; \n\t" /* and increment */ + " lock; cmpxchg8b %1; \n\t" /* if eax:edx == *stack, move ebx:ecx to *stack, + * else *stack is moved into eax:edx again... */ + " jnz 10b; \n\t" /* ... and we retry */ "20: \n" : "=a" (head) : "m" (*stack),