----------------------------------------------------------------------------- Wait for one of multiple objects to become signalled. -----------------------------------------------------------------------------
| 120 | // Wait for one of multiple objects to become signalled. |
| 121 | //----------------------------------------------------------------------------- |
| 122 | int32 Wait::Multiple |
| 123 | ( |
| 124 | Wait** _objects, |
| 125 | uint32 _numObjects, |
| 126 | int32 _timeout // = -1 |
| 127 | ) |
| 128 | { |
| 129 | uint32 i; |
| 130 | |
| 131 | // Create an event that will be set when any of the objects in the list becomes signalled. |
| 132 | Event* waitEvent = new Event(); |
| 133 | |
| 134 | // Add a watcher to each object in the list, passing in the event as the context. |
| 135 | for( i=0; i<_numObjects; ++i ) |
| 136 | { |
| 137 | // Log::Write( LogLevel_Info, "Wait::Multiple - Object %p %d", _objects[i], _objects[i]->IsSignalled()); |
| 138 | _objects[i]->AddWatcher( WaitMultipleCallback, waitEvent ); |
| 139 | } |
| 140 | |
| 141 | int32 res = -1; // Default to timeout result |
| 142 | string str = ""; |
| 143 | if( waitEvent->Wait( _timeout ) ) |
| 144 | { |
| 145 | // An object was signalled. Run through the list |
| 146 | // and see which one it was. |
| 147 | for( i=0; i<_numObjects; ++i ) |
| 148 | { |
| 149 | if( _objects[i]->IsSignalled() ) |
| 150 | { |
| 151 | if( res == -1 ) |
| 152 | res = (int32)i; |
| 153 | char buf[15]; |
| 154 | snprintf(buf, sizeof(buf), "%d, ", i); |
| 155 | str += buf; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | // Log::Write( LogLevel_Debug, "Wait::Multiple res=%d num=%d >%s", res, _numObjects, str.c_str() ); |
| 160 | |
| 161 | // Remove the watchers |
| 162 | for( i=0; i<_numObjects; ++i ) |
| 163 | { |
| 164 | _objects[i]->RemoveWatcher( WaitMultipleCallback, waitEvent ); |
| 165 | } |
| 166 | |
| 167 | // We're done with the event now |
| 168 | waitEvent->Release(); |
| 169 | return res; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | //----------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected