Final patch for the WinCE integration (should be applied after the previous one).

Besides the copyright update, the main goal was to remove #ifdefs that could be avoided, which hopefully will help improve code readability.

This was tested on both Windows and WinCE.

Regards,

/Pete
>From baf714f5e0f22b968cea0e747c23eeced44f602e Mon Sep 17 00:00:00 2001
From: Pete Batard <p...@akeo.ie>
Date: Sun, 3 Mar 2013 00:56:06 +0000
Subject: [PATCH] WinCE: Post integration cleanup

* Update copyrights and switch to UTF-8 everywhere
* Add SleepEx() to missing.h, and move include to libusbi.h
* Remove ifdef for GetSystemTimeAsFileTime()
---
 libusb/core.c               |  3 ---
 libusb/libusbi.h            |  3 +++
 libusb/os/poll_windows.c    | 15 +++++----------
 libusb/os/poll_windows.h    |  3 ++-
 libusb/os/threads_windows.c | 15 ++-------------
 libusb/os/wince_usb.c       |  6 +++---
 libusb/os/wince_usb.h       |  6 +++---
 libusb/os/windows_common.h  |  1 +
 msvc/missing.h              |  5 ++++-
 10 files changed, 24 insertions(+), 35 deletions(-)

diff --git a/libusb/core.c b/libusb/core.c
index 01b8082..b3df73a 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -33,9 +33,6 @@
 #endif
 
 #include "libusbi.h"
-#ifdef HAVE_MISSING_H
-#include "missing.h"
-#endif
 
 #if defined(OS_LINUX)
 const struct usbi_os_backend * const usbi_backend = &linux_usbfs_backend;
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index e296a2c..eed549e 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -31,6 +31,9 @@
 #include <poll.h>
 #endif
 
+#ifdef HAVE_MISSING_H
+#include "missing.h"
+#endif
 #include "libusb.h"
 #include "version.h"
 
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 559988a..da97ca9 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -1,6 +1,7 @@
 /*
  * poll_windows: poll compatibility wrapper for Windows
- * Copyright © 2009-2010 Pete Batard <pbat...@gmail.com>
+ * Copyright © 2012-2013 RealVNC Ltd.
+ * Copyright © 2009-2010 Pete Batard <p...@akeo.ie>
  * With contributions from Michael Plante, Orin Eman et al.
  * Parts of poll implementation from libusb-win32, by Stephan Meyer et al.
  *
@@ -52,7 +53,7 @@
 #else
 // MSVC++ < 2005 cannot use a variadic argument and non MSVC
 // compilers produce warnings if parenthesis are ommitted.
-#if defined(_MSC_VER) && _MSC_VER < 1400
+#if defined(_MSC_VER) && (_MSC_VER < 1400)
 #define poll_dbg
 #else
 #define poll_dbg(...)
@@ -63,12 +64,6 @@
 #pragma warning(disable:28719)
 #endif
 
-#if defined(_WIN32_WCE)
-#define usbi_sleep(ms) Sleep(ms)
-#else
-#define usbi_sleep(ms) SleepEx(ms, TRUE)
-#endif
-
 #define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0)
 
 // public fd data
@@ -157,7 +152,7 @@ void init_polling(void)
        int i;
 
        while (InterlockedExchange((LONG *)&compat_spinlock, 1) == 1) {
-               usbi_sleep(0);
+               SleepEx(0, TRUE);
        }
        if (!is_polling_set) {
                setup_cancel_io();
@@ -225,7 +220,7 @@ void exit_polling(void)
        int i;
 
        while (InterlockedExchange((LONG *)&compat_spinlock, 1) == 1) {
-               usbi_sleep(0);
+               SleepEx(0, TRUE);
        }
        if (is_polling_set) {
                is_polling_set = FALSE;
diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h
index 32145fd..1e92dda 100644
--- a/libusb/os/poll_windows.h
+++ b/libusb/os/poll_windows.h
@@ -1,6 +1,7 @@
 /*
  * Windows compat: POSIX compatibility wrapper
- * Copyright © 2009-2010 Pete Batard <pbat...@gmail.com>
+ * Copyright © 2012-2013 RealVNC Ltd.
+ * Copyright © 2009-2010 Pete Batard <p...@akeo.ie>
  * With contributions from Michael Plante, Orin Eman et al.
  * Parts of poll implementation from libusb-win32, by Stephan Meyer et al.
  *
diff --git a/libusb/os/threads_windows.c b/libusb/os/threads_windows.c
index 9548252..cad27e9 100644
--- a/libusb/os/threads_windows.c
+++ b/libusb/os/threads_windows.c
@@ -25,12 +25,6 @@
 
 #include "libusbi.h"
 
-#if defined(_WIN32_WCE)
-#define usbi_sleep(ms) Sleep(ms)
-#else
-#define usbi_sleep(ms) SleepEx(ms, TRUE)
-#endif
-
 extern const uint64_t epoch_time;
 
 int usbi_mutex_init(usbi_mutex_t *mutex,
@@ -77,7 +71,7 @@ int usbi_mutex_unlock(usbi_mutex_t *mutex) {
 int usbi_mutex_static_lock(usbi_mutex_static_t *mutex) {
        if(!mutex)               return ((errno=EINVAL));
        while (InterlockedExchange((LONG *)mutex, 1) == 1) {
-               usbi_sleep(0);
+               SleepEx(0, TRUE);
        }
        return 0;
 }
@@ -87,8 +81,6 @@ int usbi_mutex_static_unlock(usbi_mutex_static_t *mutex) {
        return 0;
 }
 
-
-
 int usbi_cond_init(usbi_cond_t *cond,
                                   const usbi_condattr_t *attr) {
        UNUSED(attr);
@@ -190,13 +182,10 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
        struct timespec cur_time_ns;
        DWORD millis;
 
-#ifdef _WIN32_WCE
+       // GetSystemTimeAsFileTime() is not available on CE
        SYSTEMTIME st;
        GetSystemTime(&st);
        SystemTimeToFileTime(&st, &filetime);
-#else
-       GetSystemTimeAsFileTime(&filetime);
-#endif
        rtime.LowPart   = filetime.dwLowDateTime;
        rtime.HighPart  = filetime.dwHighDateTime;
        rtime.QuadPart -= epoch_time;
diff --git a/libusb/os/wince_usb.c b/libusb/os/wince_usb.c
index b90950f..354c0e6 100644
--- a/libusb/os/wince_usb.c
+++ b/libusb/os/wince_usb.c
@@ -1,8 +1,8 @@
 /*
- * Windows CE backend for libusb 1.0
- * Copyright (C) 2011-2012 RealVNC Ltd.
+ * Windows CE backend for libusbx 1.0
+ * Copyright © 2011-2013 RealVNC Ltd.
  * Large portions taken from Windows backend, which is
- * Copyright (C) 2009-2010 Pete Batard <pbat...@gmail.com>
+ * Copyright © 2009-2010 Pete Batard <pbat...@gmail.com>
  * With contributions from Michael Plante, Orin Eman et al.
  * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
  * Major code testing contribution by Xiaofan Chen
diff --git a/libusb/os/wince_usb.h b/libusb/os/wince_usb.h
index b125721..3db9693 100644
--- a/libusb/os/wince_usb.h
+++ b/libusb/os/wince_usb.h
@@ -1,8 +1,8 @@
 /*
- * Windows CE backend for libusb 1.0
- * Copyright (C) 2011-2012 RealVNC Ltd.
+ * Windows CE backend for libusbx 1.0
+ * Copyright © 2011-2013 RealVNC Ltd.
  * Portions taken from Windows backend, which is
- * Copyright (C) 2009-2010 Pete Batard <pbat...@gmail.com>
+ * Copyright © 2009-2010 Pete Batard <pbat...@gmail.com>
  * With contributions from Michael Plante, Orin Eman et al.
  * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
  * Major code testing contribution by Xiaofan Chen
diff --git a/libusb/os/windows_common.h b/libusb/os/windows_common.h
index c063678..3230b02 100644
--- a/libusb/os/windows_common.h
+++ b/libusb/os/windows_common.h
@@ -3,6 +3,7 @@
  *
  * This file brings together header code common between
  * the desktop Windows and Windows CE backends.
+ * Copyright © 2012-2013 RealVNC Ltd.
  * Copyright © 2009-2012 Pete Batard <p...@akeo.ie>
  * With contributions from Michael Plante, Orin Eman et al.
  * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
diff --git a/msvc/missing.h b/msvc/missing.h
index 7846976..183b9d3 100644
--- a/msvc/missing.h
+++ b/msvc/missing.h
@@ -1,6 +1,6 @@
 /*
  * Header file for missing WinCE functionality
- * Copyright © 2012 RealVNC Ltd.
+ * Copyright © 2012-2013 RealVNC Ltd.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,9 @@
 #ifndef MISSING_H
 #define MISSING_H
 
+/* Windows CE doesn't have SleepEx() - Fallback to Sleep() */
+#define SleepEx(m, a) Sleep(m)
+
 /* Windows CE doesn't have any APIs to query environment variables.
  *
  * This contains a registry based implementation of getenv.
-- 
1.8.0.msysgit.0

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to