get all currently tracked CommandCtxs
| 244 | |
| 245 | // get all currently tracked CommandCtxs |
| 246 | void Globals_GetCommandCtxs |
| 247 | ( |
| 248 | CommandCtx **commands, // array to populate |
| 249 | uint32_t *count // [input/output] number of entries in 'commands' |
| 250 | ) { |
| 251 | ASSERT(count != NULL); |
| 252 | ASSERT(commands != NULL); |
| 253 | ASSERT(_globals.command_ctxs != NULL); |
| 254 | |
| 255 | // make a copy of the command contexts |
| 256 | uint32_t nthreads = ThreadPools_ThreadCount() + 1; |
| 257 | uint32_t cap = *count; // capacity of 'commands' |
| 258 | uint32_t found = 0; // number of command contexts found |
| 259 | |
| 260 | // acquire write lock |
| 261 | pthread_rwlock_wrlock(&_globals.lock); |
| 262 | |
| 263 | // increase ref count of each CommandCtx |
| 264 | for(uint32_t i = 0; i < nthreads && found < cap; i++) { |
| 265 | CommandCtx *cmd = _globals.command_ctxs[i]; |
| 266 | if(cmd != NULL) { |
| 267 | CommandCtx_Incref(cmd); |
| 268 | commands[found++] = cmd; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // release lock |
| 273 | pthread_rwlock_unlock(&_globals.lock); |
| 274 | |
| 275 | // update number of command contexts found |
| 276 | *count = found; |
| 277 | } |
| 278 | |
| 279 | // free globals |
| 280 | void Globals_Free(void) { |
no test coverage detected