summaryrefslogtreecommitdiff
path: root/rbutil/jztool/src/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/jztool/src/context.c')
-rw-r--r--rbutil/jztool/src/context.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/rbutil/jztool/src/context.c b/rbutil/jztool/src/context.c
index 94b21b5196..d269d1eece 100644
--- a/rbutil/jztool/src/context.c
+++ b/rbutil/jztool/src/context.c
@@ -27,6 +27,10 @@
27#include <stdio.h> 27#include <stdio.h>
28#include <time.h> 28#include <time.h>
29 29
30#ifdef WIN32
31# include <windows.h>
32#endif
33
30/** \brief Allocate a library context 34/** \brief Allocate a library context
31 * \returns New context or NULL if out of memory 35 * \returns New context or NULL if out of memory
32 */ 36 */
@@ -137,13 +141,18 @@ void jz_log_cb_stderr(jz_log_level lev, const char* msg)
137 */ 141 */
138void jz_sleepms(int ms) 142void jz_sleepms(int ms)
139{ 143{
144#ifdef WIN32
145 Sleep(ms);
146#else
140 struct timespec ts; 147 struct timespec ts;
141 long ns = ms % 1000; 148 long ns = ms % 1000;
142 ts.tv_nsec = ns * 1000 * 1000; 149 ts.tv_nsec = ns * 1000 * 1000;
143 ts.tv_sec = ms / 1000; 150 ts.tv_sec = ms / 1000;
144 nanosleep(&ts, NULL); 151 nanosleep(&ts, NULL);
152#endif
145} 153}
146 154
155/** \brief Add reference to libusb context, allocating it if necessary */
147int jz_context_ref_libusb(jz_context* jz) 156int jz_context_ref_libusb(jz_context* jz)
148{ 157{
149 if(jz->usb_ctxref == 0) { 158 if(jz->usb_ctxref == 0) {
@@ -158,6 +167,7 @@ int jz_context_ref_libusb(jz_context* jz)
158 return JZ_SUCCESS; 167 return JZ_SUCCESS;
159} 168}
160 169
170/** \brief Remove reference to libusb context, freeing if it hits zero */
161void jz_context_unref_libusb(jz_context* jz) 171void jz_context_unref_libusb(jz_context* jz)
162{ 172{
163 if(--jz->usb_ctxref == 0) { 173 if(--jz->usb_ctxref == 0) {