libusb10.c (a3d81a8a8a4f8379b0870238ae417f7986d7d299) | libusb10.c (7bdc064b0b644d15bd9614d9e7db5c4279736d75) |
---|---|
1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 120 unchanged lines hidden (view full) --- 129 debug = getenv("LIBUSB_DEBUG"); 130 if (debug != NULL) { 131 ctx->debug = atoi(debug); 132 if (ctx->debug != 0) 133 ctx->debug_fixed = 1; 134 } 135 TAILQ_INIT(&ctx->pollfds); 136 TAILQ_INIT(&ctx->tr_done); | 1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 120 unchanged lines hidden (view full) --- 129 debug = getenv("LIBUSB_DEBUG"); 130 if (debug != NULL) { 131 ctx->debug = atoi(debug); 132 if (ctx->debug != 0) 133 ctx->debug_fixed = 1; 134 } 135 TAILQ_INIT(&ctx->pollfds); 136 TAILQ_INIT(&ctx->tr_done); |
137 TAILQ_INIT(&ctx->hotplug_cbh); 138 TAILQ_INIT(&ctx->hotplug_devs); |
|
137 138 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { 139 free(ctx); 140 return (LIBUSB_ERROR_NO_MEM); 141 } | 139 140 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { 141 free(ctx); 142 return (LIBUSB_ERROR_NO_MEM); 143 } |
144 if (pthread_mutex_init(&ctx->hotplug_lock, NULL) != 0) { 145 pthread_mutex_destroy(&ctx->ctx_lock); 146 free(ctx); 147 return (LIBUSB_ERROR_NO_MEM); 148 } |
|
142 if (pthread_condattr_init(&attr) != 0) { 143 pthread_mutex_destroy(&ctx->ctx_lock); | 149 if (pthread_condattr_init(&attr) != 0) { 150 pthread_mutex_destroy(&ctx->ctx_lock); |
151 pthread_mutex_destroy(&ctx->hotplug_lock); |
|
144 free(ctx); 145 return (LIBUSB_ERROR_NO_MEM); 146 } 147 if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) { 148 pthread_mutex_destroy(&ctx->ctx_lock); | 152 free(ctx); 153 return (LIBUSB_ERROR_NO_MEM); 154 } 155 if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) { 156 pthread_mutex_destroy(&ctx->ctx_lock); |
157 pthread_mutex_destroy(&ctx->hotplug_lock); |
|
149 pthread_condattr_destroy(&attr); 150 free(ctx); 151 return (LIBUSB_ERROR_OTHER); 152 } 153 if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) { 154 pthread_mutex_destroy(&ctx->ctx_lock); | 158 pthread_condattr_destroy(&attr); 159 free(ctx); 160 return (LIBUSB_ERROR_OTHER); 161 } 162 if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) { 163 pthread_mutex_destroy(&ctx->ctx_lock); |
164 pthread_mutex_destroy(&ctx->hotplug_lock); |
|
155 pthread_condattr_destroy(&attr); 156 free(ctx); 157 return (LIBUSB_ERROR_NO_MEM); 158 } 159 pthread_condattr_destroy(&attr); 160 161 ctx->ctx_handler = NO_THREAD; | 165 pthread_condattr_destroy(&attr); 166 free(ctx); 167 return (LIBUSB_ERROR_NO_MEM); 168 } 169 pthread_condattr_destroy(&attr); 170 171 ctx->ctx_handler = NO_THREAD; |
172 ctx->hotplug_handler = NO_THREAD; |
|
162 163 ret = pipe(ctx->ctrl_pipe); 164 if (ret < 0) { 165 pthread_mutex_destroy(&ctx->ctx_lock); | 173 174 ret = pipe(ctx->ctrl_pipe); 175 if (ret < 0) { 176 pthread_mutex_destroy(&ctx->ctx_lock); |
177 pthread_mutex_destroy(&ctx->hotplug_lock); |
|
166 pthread_cond_destroy(&ctx->ctx_cond); 167 free(ctx); 168 return (LIBUSB_ERROR_OTHER); 169 } 170 /* set non-blocking mode on the control pipe to avoid deadlock */ 171 libusb_set_nonblocking(ctx->ctrl_pipe[0]); 172 libusb_set_nonblocking(ctx->ctrl_pipe[1]); 173 --- 16 unchanged lines hidden (view full) --- 190void 191libusb_exit(libusb_context *ctx) 192{ 193 ctx = GET_CONTEXT(ctx); 194 195 if (ctx == NULL) 196 return; 197 | 178 pthread_cond_destroy(&ctx->ctx_cond); 179 free(ctx); 180 return (LIBUSB_ERROR_OTHER); 181 } 182 /* set non-blocking mode on the control pipe to avoid deadlock */ 183 libusb_set_nonblocking(ctx->ctrl_pipe[0]); 184 libusb_set_nonblocking(ctx->ctrl_pipe[1]); 185 --- 16 unchanged lines hidden (view full) --- 202void 203libusb_exit(libusb_context *ctx) 204{ 205 ctx = GET_CONTEXT(ctx); 206 207 if (ctx == NULL) 208 return; 209 |
210 /* stop hotplug thread, if any */ 211 212 if (ctx->hotplug_handler != NO_THREAD) { 213 pthread_t td; 214 void *ptr; 215 216 HOTPLUG_LOCK(ctx); 217 td = ctx->hotplug_handler; 218 ctx->hotplug_handler = NO_THREAD; 219 HOTPLUG_UNLOCK(ctx); 220 221 pthread_join(td, &ptr); 222 } 223 |
|
198 /* XXX cleanup devices */ 199 200 libusb10_remove_pollfd(ctx, &ctx->ctx_poll); 201 close(ctx->ctrl_pipe[0]); 202 close(ctx->ctrl_pipe[1]); 203 pthread_mutex_destroy(&ctx->ctx_lock); | 224 /* XXX cleanup devices */ 225 226 libusb10_remove_pollfd(ctx, &ctx->ctx_poll); 227 close(ctx->ctrl_pipe[0]); 228 close(ctx->ctrl_pipe[1]); 229 pthread_mutex_destroy(&ctx->ctx_lock); |
230 pthread_mutex_destroy(&ctx->hotplug_lock); |
|
204 pthread_cond_destroy(&ctx->ctx_cond); 205 206 pthread_mutex_lock(&default_context_lock); 207 if (ctx == usbi_default_context) { 208 usbi_default_context = NULL; 209 } 210 pthread_mutex_unlock(&default_context_lock); 211 --- 1417 unchanged lines hidden --- | 231 pthread_cond_destroy(&ctx->ctx_cond); 232 233 pthread_mutex_lock(&default_context_lock); 234 if (ctx == usbi_default_context) { 235 usbi_default_context = NULL; 236 } 237 pthread_mutex_unlock(&default_context_lock); 238 --- 1417 unchanged lines hidden --- |