keep a reference to the device for each active transfer and let the backend handle cancelling active transfers when a device is disconnected

This commit should fix issues with active transfers when a device is
disconnected. The backend is responsible for making sure the completion
callbacks are made, not the hotplug code. This should fix a number of
issues including duplicate callbacks and segmentation faults.

References #124.
Add checks for headers needed by linux/netlink.h

These headers are required by netlink.h. I am not sure how this
worked at all. It certainly doesn't work with older versions of Linux
2.6.

References #124.
Silence automake 1.14 warning

The warning is:

libusb/Makefile.am:57: warning: source file 'os/threads_windows.c' is in a subdirectory,
libusb/Makefile.am:57: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled.  For now, the corresponding output
automake: object file(s) will be placed in the top-level directory.  However,
automake: this behaviour will change in future Automake versions: they will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.

Fixed by setting the subdir-objects option.

Closes #125.
include stdlib.h for free and realloc in libusbi.h

References #124.
fix warnings in linux_get_device_address

Warnings:

os/linux_usbfs.c: In function 'linux_get_device_address':
os/linux_usbfs.c:620: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:624: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:628: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:628: warning: comparison is always false due to limited range of data type
work around Linux systems that don't provide SOCK_CLOEXEC or SOCK_NONBLOCK

These options were added in 2.6.27 and are not available on all kernels
that support netlink. Set these options using fcntl when SOCK_CLOEXEC and
SOCK_NONBLOCK are not available.

Closes #124.
linux: Use a separate lock to serialize start/stop vs hotplug events

Using one lock for this is a bad idea, as we should not be holding any
locks used by the hotplug thread when trying to stop otherwise the stop
function may wait indefinetely in pthread_join, while the event-thread
is waiting for the lock the caller of the stop function holds.

Using 2 separate locks for this should fix this deadlock, which has been
reported here: https://bugzilla.redhat.com/show_bug.cgi?id=985484

Many thanks to Chris Dickens for figuring out the cause of this deadlock!

CC: Chris Dickens <christopher.a.dickens@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
hotplug: Remove use of pthread_cancel from linux_udev

Using pthread_cancel() presents the opportunity for deadlock, so
use a control pipe to cause the event thread to gracefully exit.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
linux_netlink: close netlink socket on init error

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
linux_netlink: Remove use of pthread_cancel

Using pthread_cancel() presents the opportunity for deadlock, so
use a control pipe to cause the event thread to gracefully exit.

Inspired on the identical patch for linux_udev from Chris Dickens.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Xcode project
Move Xcode project in Xcode/ directory

This is to use Xcode special config.h file in a independent directory.
The same is already done for MS Visual C with msvc/ directory.
Adapt Xcode project to the new paths
Add minimal config.h for Xcode

Xcode do not use ./configure so the config.h file needs to be generated
by hand.
This config.h is the minimal file for libusbx built using Xcode.
Xcode: remove implicit/default configuration
Xcode: build for 32 and 64 bits
make targets for examples depend on library target.  Generate library named libusb-1.0.0.dylib not libusbx.dylib.  Added several xcconfig files to make source control and documentation easier.  Reorganised a few files' positions within the project.  Disable strict aliasing since libusbx breaks strict aliasing rules anyway. Set project format as 3.1-compatible.

Conflicts:
	Xcode/libusbx.xcodeproj/project.pbxproj
fixed compiler warning about possible uninitialized use by zero initializing
fixed some clang -Wdocumentation warnings from bad doxygen markup
made some globals static to fix warnings