Hi! On 2018-06-19T10:01:20-0700, Cesar Philippidis wrote: > --- a/libgomp/target.c > +++ b/libgomp/target.c > +attribute_hidden bool > +gomp_remove_var (struct gomp_device_descr *devicep, splay_tree_key k) > +{ > + bool is_tgt_unmapped = false; > + splay_tree_remove (&devicep->mem_map, k); > + if (k->link_key) > + splay_tree_insert (&devicep->mem_map, (splay_tree_node) k->link_key); > + if (k->tgt->refcount > 1) > + k->tgt->refcount--; > + else > + { > + is_tgt_unmapped = true; > + gomp_unmap_tgt (k->tgt); > + } > + return is_tgt_unmapped; This new function, can, like done here: > @@ -1059,16 +1077,7 @@ gomp_unmap_vars (struct target_mem_desc *tgt, bool do_copyfrom) > + tgt->list[i].offset), > tgt->list[i].length); > if (do_unmap) > - { > - splay_tree_remove (&devicep->mem_map, k); > - if (k->link_key) > - splay_tree_insert (&devicep->mem_map, > - (splay_tree_node) k->link_key); > - if (k->tgt->refcount > 1) > - k->tgt->refcount--; > - else > - gomp_unmap_tgt (k->tgt); > - } > + gomp_remove_var (devicep, k); > } ..., and here: > @@ -1298,17 +1307,7 @@ gomp_unload_image_from_device (struct gomp_device_descr *devicep, > else > { > splay_tree_key n = splay_tree_lookup (&devicep->mem_map, &k); > - splay_tree_remove (&devicep->mem_map, n); > - if (n->link_key) > - { > - if (n->tgt->refcount > 1) > - n->tgt->refcount--; > - else > - { > - is_tgt_unmapped = true; > - gomp_unmap_tgt (n->tgt); > - } > - } > + is_tgt_unmapped = gomp_remove_var (devicep, n); > } ..., also be used in 'gomp_exit_data', see attached "In 'libgomp/target.c:gomp_exit_data', remove open-coded 'gomp_remove_var'", committed to trunk in r279118. Grüße Thomas