...
Code Block |
---|
/// Accessor to next ceph pool index
/// Note that this is not thread safe, but we do not care
/// as we only want a rough load balancing
unsigned int getCephPoolIdxAndIncrease() {
if (g_radosStripers.size() == 0) {
// make sure we do not have a race condition here
XrdSysMutexHelper lock(g_init_mutex);
// double check now that we have the lock
if (g_radosStripers.size() == 0) {
// initialization phase : allocate corresponding places in the vectors
for (unsigned int i = 0; i < g_maxCephPoolIdx; i++) {
g_radosStripers.push_back(StriperDict());
g_ioCtx.push_back(IOCtxDict());
g_cluster.push_back(0);
}
}
}
unsigned int res = g_cephPoolIdx;
unsigned nextValue = g_cephPoolIdx+1;
if (nextValue >= g_maxCephPoolIdx) {
nextValue = 0;
}
g_cephPoolIdx = nextValue;
// JW logging of accesses:
++g_idxCntr[res];
return res;
} |
would moving the mutex up a level make this thread safe? (lock-> check->release after init)
...