[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
make linked-list traversable in signal handlers
From: |
Bruno Haible |
Subject: |
make linked-list traversable in signal handlers |
Date: |
Mon, 24 Jul 2006 18:33:28 +0200 |
User-agent: |
KMail/1.9.1 |
Hi,
I committed this patch, using 'volatile' to avoid instruction reordering.
2006-07-23 Bruno Haible <address@hidden>
* gl_anylinked_list2.h (ASYNCSAFE): New macro.
(gl_linked_add_first, gl_linked_add_last, gl_linked_add_before,
gl_linked_add_after, gl_linked_add_at, gl_linked_remove_node,
gl_linked_remove_at): Use it.
*** GNULIB/gnulib-20060722-modified/lib/gl_anylinked_list2.h 2006-07-17
13:27:18.000000000 +0200
--- GETTEXT/gettext-work/gettext-6/gettext-tools/lib/gl_anylinked_list2.h
2006-07-23 00:50:01.000000000 +0200
***************
*** 18,23 ****
--- 18,40 ----
/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */
+ /* If the symbol SIGNAL_SAFE_LIST is defined, the code is compiled in such
+ a way that a gl_list_t data structure may be used from within a signal
+ handler. The operations allowed in the signal handler are:
+ gl_list_iterator, gl_list_iterator_next, gl_list_iterator_free.
+ The list and node fields that are therefore accessed from the signal
handler
+ are:
+ list->root, node->next, node->value.
+ We are careful to make modifications to these fields only in an order
+ that maintains the consistency of the list data structure at any moment,
+ and we use 'volatile' assignments to prevent the compiler from reordering
+ such assignments. */
+ #ifdef SIGNAL_SAFE_LIST
+ # define ASYNCSAFE(type) *(volatile type *)&
+ #else
+ # define ASYNCSAFE(type)
+ #endif
+
/* -------------------------- gl_list_t Data Type --------------------------
*/
static gl_list_t
***************
*** 396,402 ****
gl_list_node_t node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! node->value = elt;
#if WITH_HASHTABLE
node->h.hashcode =
(list->base.hashcode_fn != NULL
--- 413,419 ----
gl_list_node_t node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! ASYNCSAFE(const void *) node->value = elt;
#if WITH_HASHTABLE
node->h.hashcode =
(list->base.hashcode_fn != NULL
***************
*** 409,417 ****
/* Add node to the list. */
node->prev = &list->root;
! node->next = list->root.next;
node->next->prev = node;
! list->root.next = node;
list->count++;
#if WITH_HASHTABLE
--- 426,434 ----
/* Add node to the list. */
node->prev = &list->root;
! ASYNCSAFE(gl_list_node_t) node->next = list->root.next;
node->next->prev = node;
! ASYNCSAFE(gl_list_node_t) list->root.next = node;
list->count++;
#if WITH_HASHTABLE
***************
*** 427,433 ****
gl_list_node_t node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! node->value = elt;
#if WITH_HASHTABLE
node->h.hashcode =
(list->base.hashcode_fn != NULL
--- 444,450 ----
gl_list_node_t node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! ASYNCSAFE(const void *) node->value = elt;
#if WITH_HASHTABLE
node->h.hashcode =
(list->base.hashcode_fn != NULL
***************
*** 439,447 ****
#endif
/* Add node to the list. */
! node->next = &list->root;
node->prev = list->root.prev;
! node->prev->next = node;
list->root.prev = node;
list->count++;
--- 456,464 ----
#endif
/* Add node to the list. */
! ASYNCSAFE(gl_list_node_t) node->next = &list->root;
node->prev = list->root.prev;
! ASYNCSAFE(gl_list_node_t) node->prev->next = node;
list->root.prev = node;
list->count++;
***************
*** 458,464 ****
gl_list_node_t new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
--- 475,481 ----
gl_list_node_t new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! ASYNCSAFE(const void *) new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
***************
*** 470,478 ****
#endif
/* Add new_node to the list. */
! new_node->next = node;
new_node->prev = node->prev;
! new_node->prev->next = new_node;
node->prev = new_node;
list->count++;
--- 487,495 ----
#endif
/* Add new_node to the list. */
! ASYNCSAFE(gl_list_node_t) new_node->next = node;
new_node->prev = node->prev;
! ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
node->prev = new_node;
list->count++;
***************
*** 489,495 ****
gl_list_node_t new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
--- 506,512 ----
gl_list_node_t new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! ASYNCSAFE(const void *) new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
***************
*** 502,510 ****
/* Add new_node to the list. */
new_node->prev = node;
! new_node->next = node->next;
new_node->next->prev = new_node;
! node->next = new_node;
list->count++;
#if WITH_HASHTABLE
--- 519,527 ----
/* Add new_node to the list. */
new_node->prev = node;
! ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
new_node->next->prev = new_node;
! ASYNCSAFE(gl_list_node_t) node->next = new_node;
list->count++;
#if WITH_HASHTABLE
***************
*** 526,532 ****
new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
--- 543,549 ----
new_node =
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
! ASYNCSAFE(const void *) new_node->value = elt;
#if WITH_HASHTABLE
new_node->h.hashcode =
(list->base.hashcode_fn != NULL
***************
*** 546,554 ****
for (; position > 0; position--)
node = node->next;
new_node->prev = node;
! new_node->next = node->next;
new_node->next->prev = new_node;
! node->next = new_node;
}
else
{
--- 563,571 ----
for (; position > 0; position--)
node = node->next;
new_node->prev = node;
! ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
new_node->next->prev = new_node;
! ASYNCSAFE(gl_list_node_t) node->next = new_node;
}
else
{
***************
*** 558,566 ****
node = &list->root;
for (; position > 0; position--)
node = node->prev;
! new_node->next = node;
new_node->prev = node->prev;
! new_node->prev->next = new_node;
node->prev = new_node;
}
list->count++;
--- 575,583 ----
node = &list->root;
for (; position > 0; position--)
node = node->prev;
! ASYNCSAFE(gl_list_node_t) new_node->next = node;
new_node->prev = node->prev;
! ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
node->prev = new_node;
}
list->count++;
***************
*** 587,593 ****
prev = node->prev;
next = node->next;
! prev->next = next;
next->prev = prev;
list->count--;
--- 604,610 ----
prev = node->prev;
next = node->next;
! ASYNCSAFE(gl_list_node_t) prev->next = next;
next->prev = prev;
list->count--;
***************
*** 615,621 ****
node = node->next;
removed_node = node->next;
after_removed = node->next->next;
! node->next = after_removed;
after_removed->prev = node;
}
else
--- 632,638 ----
node = node->next;
removed_node = node->next;
after_removed = node->next->next;
! ASYNCSAFE(gl_list_node_t) node->next = after_removed;
after_removed->prev = node;
}
else
***************
*** 630,636 ****
removed_node = node->prev;
before_removed = node->prev->prev;
node->prev = before_removed;
! before_removed->next = node;
}
#if WITH_HASHTABLE
remove_from_bucket (list, removed_node);
--- 647,653 ----
removed_node = node->prev;
before_removed = node->prev->prev;
node->prev = before_removed;
! ASYNCSAFE(gl_list_node_t) before_removed->next = node;
}
#if WITH_HASHTABLE
remove_from_bucket (list, removed_node);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- make linked-list traversable in signal handlers,
Bruno Haible <=