2525/* create a tracking object for progress threads */
2626typedef struct {
2727 opal_list_item_t super ;
28+ int refcount ;
2829 char * name ;
2930 opal_event_base_t * ev_base ;
3031 volatile bool ev_active ;
@@ -36,6 +37,7 @@ typedef struct {
3637} opal_progress_tracker_t ;
3738static void trkcon (opal_progress_tracker_t * p )
3839{
40+ p -> refcount = 1 ; // start at one since someone created it
3941 p -> name = NULL ;
4042 p -> ev_base = NULL ;
4143 p -> ev_active = true;
@@ -97,6 +99,21 @@ opal_event_base_t *opal_start_progress_thread(char *name,
9799 opal_progress_tracker_t * trk ;
98100 int rc ;
99101
102+ if (!inited ) {
103+ OBJ_CONSTRUCT (& tracking , opal_list_t );
104+ inited = true;
105+ }
106+
107+ /* check if we already have this thread */
108+ OPAL_LIST_FOREACH (trk , & tracking , opal_progress_tracker_t ) {
109+ if (0 == strcmp (name , trk -> name )) {
110+ /* we do, so up the refcount on it */
111+ ++ trk -> refcount ;
112+ /* return the existing base */
113+ return trk -> ev_base ;
114+ }
115+ }
116+
100117 trk = OBJ_NEW (opal_progress_tracker_t );
101118 trk -> name = strdup (name );
102119 if (NULL == (trk -> ev_base = opal_event_base_create ())) {
@@ -136,10 +153,6 @@ opal_event_base_t *opal_start_progress_thread(char *name,
136153 OBJ_RELEASE (trk );
137154 return NULL ;
138155 }
139- if (!inited ) {
140- OBJ_CONSTRUCT (& tracking , opal_list_t );
141- inited = true;
142- }
143156 opal_list_append (& tracking , & trk -> super );
144157 return trk -> ev_base ;
145158}
@@ -166,6 +179,12 @@ void opal_stop_progress_thread(char *name, bool cleanup)
166179 }
167180 return ;
168181 }
182+ /* decrement the refcount */
183+ -- trk -> refcount ;
184+ /* if we have reached zero, then it's time to stop it */
185+ if (0 < trk -> refcount ) {
186+ return ;
187+ }
169188 /* mark it as inactive */
170189 trk -> ev_active = false;
171190 /* break the event loop - this will cause the loop to exit
@@ -207,6 +226,8 @@ int opal_restart_progress_thread(char *name)
207226 OPAL_ERROR_LOG (OPAL_ERR_NOT_SUPPORTED );
208227 return OPAL_ERR_NOT_SUPPORTED ;
209228 }
229+ /* up the refcount */
230+ ++ trk -> refcount ;
210231 /* ensure the block is set, if requested */
211232 if (0 <= trk -> pipe [0 ] && !trk -> block_active ) {
212233 opal_event_add (& trk -> block , 0 );
0 commit comments