1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2004-2005 The Trustees of Indiana University.
4  *                         All rights reserved.
5  * Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
6  *                         All rights reserved.
7  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
8  *                         University of Stuttgart.  All rights reserved.
9  * Copyright (c) 2004-2005 The Regents of the University of California.
10  *                         All rights reserved.
11  * Copyright (c) 2007-2016 Los Alamos National Security, LLC.  All rights
12  *                         reserved.
13  * Copyright (c) 2012-2013 Sandia National Laboratories.  All rights reserved.
14  * Copyright (c) 2015      Research Organization for Information Science
15  *                         and Technology (RIST). All rights reserved.
16  * Copyright (c) 2017      The University of Tennessee and The University
17  *                         of Tennessee Research Foundation.  All rights
18  *                         reserved.
19  * $COPYRIGHT$
20  *
21  * Additional copyrights may follow
22  *
23  * $HEADER$
24  */
25 
26 #include "osc_pt2pt.h"
27 
28 
ompi_osc_pt2pt_attach(struct ompi_win_t * win,void * base,size_t len)29 int ompi_osc_pt2pt_attach(struct ompi_win_t *win, void *base, size_t len)
30 {
31     return OMPI_SUCCESS;
32 }
33 
34 
35 int
ompi_osc_pt2pt_detach(struct ompi_win_t * win,const void * base)36 ompi_osc_pt2pt_detach(struct ompi_win_t *win, const void *base)
37 {
38     return OMPI_SUCCESS;
39 }
40 
41 
ompi_osc_pt2pt_free(ompi_win_t * win)42 int ompi_osc_pt2pt_free(ompi_win_t *win)
43 {
44     int ret = OMPI_SUCCESS;
45     ompi_osc_pt2pt_module_t *module = GET_MODULE(win);
46     ompi_osc_pt2pt_peer_t *peer;
47     uint32_t key;
48     void *node;
49 
50     if (NULL == module) {
51         return OMPI_SUCCESS;
52     }
53 
54     if (NULL != module->comm) {
55         opal_output_verbose(1, ompi_osc_base_framework.framework_output,
56                             "pt2pt component destroying window with id %d",
57                             ompi_comm_get_cid(module->comm));
58 
59         /* finish with a barrier */
60         if (ompi_group_size(win->w_group) > 1) {
61             (void) module->comm->c_coll->coll_barrier (module->comm,
62                                                       module->comm->c_coll->coll_barrier_module);
63         }
64 
65         /* remove from component information */
66         OPAL_THREAD_SCOPED_LOCK(&mca_osc_pt2pt_component.lock,
67                                 opal_hash_table_remove_value_uint32(&mca_osc_pt2pt_component.modules,
68                                                                     ompi_comm_get_cid(module->comm)));
69     }
70 
71     win->w_osc_module = NULL;
72 
73     OBJ_DESTRUCT(&module->outstanding_locks);
74     OBJ_DESTRUCT(&module->locks_pending);
75     OBJ_DESTRUCT(&module->locks_pending_lock);
76     OBJ_DESTRUCT(&module->cond);
77     OBJ_DESTRUCT(&module->lock);
78     OBJ_DESTRUCT(&module->all_sync);
79 
80     /* it is erroneous to close a window with active operations on it so we should
81      * probably produce an error here instead of cleaning up */
82     OPAL_LIST_DESTRUCT(&module->pending_acc);
83     OBJ_DESTRUCT(&module->pending_acc_lock);
84 
85     osc_pt2pt_gc_clean (module);
86     OPAL_LIST_DESTRUCT(&module->buffer_gc);
87     OBJ_DESTRUCT(&module->gc_lock);
88 
89     ret = opal_hash_table_get_first_key_uint32 (&module->peer_hash, &key, (void **) &peer, &node);
90     while (OPAL_SUCCESS == ret) {
91         OBJ_RELEASE(peer);
92         ret = opal_hash_table_get_next_key_uint32 (&module->peer_hash, &key, (void **) &peer, node,
93                                                    &node);
94     }
95 
96     OBJ_DESTRUCT(&module->peer_hash);
97     OBJ_DESTRUCT(&module->peer_lock);
98 
99     if (NULL != module->recv_frags) {
100         for (unsigned int i = 0 ; i < module->recv_frag_count ; ++i) {
101             OBJ_DESTRUCT(module->recv_frags + i);
102         }
103 
104         free (module->recv_frags);
105     }
106 
107     if (NULL != module->epoch_outgoing_frag_count) free(module->epoch_outgoing_frag_count);
108 
109     if (NULL != module->comm) {
110         ompi_comm_free(&module->comm);
111     }
112 
113     if (NULL != module->free_after) free(module->free_after);
114 
115     free (module);
116 
117     return OMPI_SUCCESS;
118 }
119