| 500 | } |
| 501 | |
| 502 | void |
| 503 | SDL_SensorUpdate(void) |
| 504 | { |
| 505 | int i; |
| 506 | SDL_Sensor *sensor, *next; |
| 507 | |
| 508 | if (!SDL_WasInit(SDL_INIT_SENSOR)) { |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | SDL_LockSensors(); |
| 513 | |
| 514 | if (SDL_updating_sensor) { |
| 515 | /* The sensors are already being updated */ |
| 516 | SDL_UnlockSensors(); |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | SDL_updating_sensor = SDL_TRUE; |
| 521 | |
| 522 | /* Make sure the list is unlocked while dispatching events to prevent application deadlocks */ |
| 523 | SDL_UnlockSensors(); |
| 524 | |
| 525 | for (sensor = SDL_sensors; sensor; sensor = sensor->next) { |
| 526 | sensor->driver->Update(sensor); |
| 527 | } |
| 528 | |
| 529 | SDL_LockSensors(); |
| 530 | |
| 531 | SDL_updating_sensor = SDL_FALSE; |
| 532 | |
| 533 | /* If any sensors were closed while updating, free them here */ |
| 534 | for (sensor = SDL_sensors; sensor; sensor = next) { |
| 535 | next = sensor->next; |
| 536 | if (sensor->ref_count <= 0) { |
| 537 | SDL_SensorClose(sensor); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | /* this needs to happen AFTER walking the sensor list above, so that any |
| 542 | dangling hardware data from removed devices can be free'd |
| 543 | */ |
| 544 | for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { |
| 545 | SDL_sensor_drivers[i]->Detect(); |
| 546 | } |
| 547 | |
| 548 | SDL_UnlockSensors(); |
| 549 | } |
| 550 | |
| 551 | /* vi: set ts=4 sw=4 expandtab: */ |
no test coverage detected