| 46 | |
| 47 | |
| 48 | int ThreadMgr::Occupy(const int machineId) |
| 49 | { |
| 50 | const unsigned m = static_cast<unsigned>(machineId); |
| 51 | if (m >= numMachineThreads) |
| 52 | { |
| 53 | numMachineThreads = m + 1; |
| 54 | machineThreads.resize(numMachineThreads); |
| 55 | for (unsigned t = m; t < numMachineThreads; t++) |
| 56 | machineThreads[t] = -1; |
| 57 | } |
| 58 | |
| 59 | if (machineThreads[m] != -1) |
| 60 | { |
| 61 | // Error: Already in use. |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | int res = -1; |
| 66 | |
| 67 | do |
| 68 | { |
| 69 | mtx.lock(); |
| 70 | for (unsigned t = 0; t < numRealThreads; t++) |
| 71 | { |
| 72 | if (realThreads[t] == false) |
| 73 | { |
| 74 | const int ti = static_cast<int>(t); |
| 75 | realThreads[t] = true; |
| 76 | machineThreads[m] = ti; |
| 77 | res = ti; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | // ThreadMgr::Print("thr.txt", "In Occupy " + |
| 82 | // to_string(machineId) + " " + to_string(res)); |
| 83 | mtx.unlock(); |
| 84 | |
| 85 | if (res == -1) |
| 86 | { |
| 87 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); |
| 88 | } |
| 89 | } |
| 90 | while (res == -1); |
| 91 | |
| 92 | return res; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | bool ThreadMgr::Release(const int machineId) |
nothing calls this directly
no outgoing calls
no test coverage detected