libusb10.c (234684) | libusb10.c (236944) |
---|---|
1/* $FreeBSD: head/lib/libusb/libusb10.c 234684 2012-04-25 17:54:26Z hselasky $ */ | 1/* $FreeBSD: head/lib/libusb/libusb10.c 236944 2012-06-12 07:28:25Z hselasky $ */ |
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: 9 * 1. Redistributions of source code must retain the above copyright --- 77 unchanged lines hidden (view full) --- 87 flags |= O_NONBLOCK; 88 fcntl(f, F_SETFL, flags); 89} 90 91int 92libusb_init(libusb_context **context) 93{ 94 struct libusb_context *ctx; | 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: 9 * 1. Redistributions of source code must retain the above copyright --- 77 unchanged lines hidden (view full) --- 87 flags |= O_NONBLOCK; 88 fcntl(f, F_SETFL, flags); 89} 90 91int 92libusb_init(libusb_context **context) 93{ 94 struct libusb_context *ctx; |
95 pthread_condattr_t attr; |
|
95 char *debug; 96 int ret; 97 98 ctx = malloc(sizeof(*ctx)); 99 if (!ctx) 100 return (LIBUSB_ERROR_INVALID_PARAM); 101 102 memset(ctx, 0, sizeof(*ctx)); 103 104 debug = getenv("LIBUSB_DEBUG"); 105 if (debug != NULL) { 106 ctx->debug = atoi(debug); 107 if (ctx->debug != 0) 108 ctx->debug_fixed = 1; 109 } 110 TAILQ_INIT(&ctx->pollfds); 111 TAILQ_INIT(&ctx->tr_done); 112 | 96 char *debug; 97 int ret; 98 99 ctx = malloc(sizeof(*ctx)); 100 if (!ctx) 101 return (LIBUSB_ERROR_INVALID_PARAM); 102 103 memset(ctx, 0, sizeof(*ctx)); 104 105 debug = getenv("LIBUSB_DEBUG"); 106 if (debug != NULL) { 107 ctx->debug = atoi(debug); 108 if (ctx->debug != 0) 109 ctx->debug_fixed = 1; 110 } 111 TAILQ_INIT(&ctx->pollfds); 112 TAILQ_INIT(&ctx->tr_done); 113 |
113 pthread_mutex_init(&ctx->ctx_lock, NULL); 114 pthread_cond_init(&ctx->ctx_cond, NULL); | 114 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { 115 free(ctx); 116 return (LIBUSB_ERROR_NO_MEM); 117 } 118 if (pthread_condattr_init(&attr) != 0) { 119 pthread_mutex_destroy(&ctx->ctx_lock); 120 free(ctx); 121 return (LIBUSB_ERROR_NO_MEM); 122 } 123 if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) { 124 pthread_mutex_destroy(&ctx->ctx_lock); 125 pthread_condattr_destroy(&attr); 126 free(ctx); 127 return (LIBUSB_ERROR_OTHER); 128 } 129 if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) { 130 pthread_mutex_destroy(&ctx->ctx_lock); 131 pthread_condattr_destroy(&attr); 132 free(ctx); 133 return (LIBUSB_ERROR_NO_MEM); 134 } 135 pthread_condattr_destroy(&attr); |
115 116 ctx->ctx_handler = NO_THREAD; 117 118 ret = pipe(ctx->ctrl_pipe); 119 if (ret < 0) { 120 pthread_mutex_destroy(&ctx->ctx_lock); 121 pthread_cond_destroy(&ctx->ctx_cond); 122 free(ctx); --- 1418 unchanged lines hidden --- | 136 137 ctx->ctx_handler = NO_THREAD; 138 139 ret = pipe(ctx->ctrl_pipe); 140 if (ret < 0) { 141 pthread_mutex_destroy(&ctx->ctx_lock); 142 pthread_cond_destroy(&ctx->ctx_cond); 143 free(ctx); --- 1418 unchanged lines hidden --- |