Changeset 5320:d583f3008d43 in roaraudio for libroar
- Timestamp:
- 12/04/11 20:02:31 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/plugincontainer.c
r5317 r5320 42 42 struct roar_dl_librarypara * default_para; 43 43 struct roar_dl_lhandle * handle[MAX_PLUGINS]; 44 size_t deprefc[MAX_PLUGINS]; 45 size_t numhandles; 44 46 // TODO: add a depref counter so we do not unload libs we depend on. 45 47 }; … … 115 117 return 0; 116 118 117 for (i = 0; i < MAX_PLUGINS; i++) { 118 if ( cont->handle[i] == NULL ) 119 continue; 120 121 roar_dl_close(cont->handle[i]); 119 while (cont->numhandles) { 120 for (i = 0; i < MAX_PLUGINS; i++) { 121 if ( cont->handle[i] == NULL ) 122 continue; 123 124 // skip plugins in use by others. We will unload them in a later loop. 125 if ( cont->deprefc[i] ) 126 continue; 127 128 roar_dl_close(cont->handle[i]); 129 } 122 130 } 123 131 … … 131 139 132 140 // plugin loading and unloading: 133 int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para); 141 int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para) { 142 ssize_t idx = -1; 143 size_t i; 144 145 if ( cont == NULL || name == NULL ) { 146 roar_err_set(ROAR_ERROR_FAULT); 147 return -1; 148 } 149 150 if ( para == NULL ) 151 para = cont->default_para; 152 // we do not need to _ref(para) here. This will be done by the roardl open function. 153 154 155 // search for a free index. 156 if ( cont->numhandles == MAX_PLUGINS ) { 157 // return early if we are full. 158 roar_err_set(ROAR_ERROR_NOSPC); 159 return -1; 160 } 161 for (i = 0; i < MAX_PLUGINS; i++) { 162 if ( cont->handle[i] == NULL ) { 163 idx = i; 164 break; 165 } 166 } 167 168 if ( idx == -1 ) { 169 roar_err_set(ROAR_ERROR_NOSPC); 170 return -1; 171 } 172 173 if ( strstr(name, "/") != NULL ) { 174 cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para); 175 if ( cont->handle[idx] == NULL ) 176 return -1; 177 178 cont->deprefc[idx] = 0; 179 cont->numhandles++; 180 181 return 0; 182 } else { 183 roar_err_set(ROAR_ERROR_NOSYS); 184 return -1; 185 } 186 187 roar_err_set(ROAR_ERROR_NOSYS); 188 return -1; 189 } 190 134 191 int roar_plugincontainer_unload(struct roar_plugincontainer * cont, const char * name) { 135 192 // get b name, then call roar_plugincontainer_unload_lhandle(). … … 153 210 for (i = 0; i < MAX_PLUGINS; i++) { 154 211 if ( cont->handle[i] == lhandle ) { 212 if ( cont->deprefc[i] ) { 213 // still in use. 214 roar_err_set(ROAR_ERROR_BUSY); 215 return -1; 216 } 155 217 roar_dl_close(cont->handle[i]); 156 218 cont->handle[i] = NULL; 219 cont->numhandles--; 157 220 return 0; 158 221 }
Note: See TracChangeset
for help on using the changeset viewer.