| 129 | static pthread_mutex_t device_list_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 130 | |
| 131 | static hid_device *new_hid_device(void) |
| 132 | { |
| 133 | hid_device *dev = calloc(1, sizeof(hid_device)); |
| 134 | dev->device_handle = NULL; |
| 135 | dev->blocking = 1; |
| 136 | dev->uses_numbered_reports = 0; |
| 137 | dev->disconnected = 0; |
| 138 | dev->run_loop_mode = NULL; |
| 139 | dev->run_loop = NULL; |
| 140 | dev->source = NULL; |
| 141 | dev->input_report_buf = NULL; |
| 142 | dev->input_reports = NULL; |
| 143 | dev->shutdown_thread = 0; |
| 144 | dev->next = NULL; |
| 145 | |
| 146 | /* Thread objects */ |
| 147 | pthread_mutex_init(&dev->mutex, NULL); |
| 148 | pthread_cond_init(&dev->condition, NULL); |
| 149 | pthread_barrier_init(&dev->barrier, NULL, 2); |
| 150 | pthread_barrier_init(&dev->shutdown_barrier, NULL, 2); |
| 151 | |
| 152 | /* Add the new record to the device_list. */ |
| 153 | pthread_mutex_lock(&device_list_mutex); |
| 154 | if (!device_list) |
| 155 | device_list = dev; |
| 156 | else { |
| 157 | hid_device *d = device_list; |
| 158 | while (d) { |
| 159 | if (!d->next) { |
| 160 | d->next = dev; |
| 161 | break; |
| 162 | } |
| 163 | d = d->next; |
| 164 | } |
| 165 | } |
| 166 | pthread_mutex_unlock(&device_list_mutex); |
| 167 | |
| 168 | return dev; |
| 169 | } |
| 170 | |
| 171 | static void free_hid_device(hid_device *dev) |
| 172 | { |
no test coverage detected