Skip to content

Commit

Permalink
core: Refactor initialization and how the default context is handled
Browse files Browse the repository at this point in the history
Highlights for this change:

 - usbi_default_context is only set if libusb_init() is called with NULL.
 - All hotplug related functionality (e.g. initialization, processing) has been
   moved to hotplug.c
 - Backends are simplified by removing initialization mutexes. Mutual exclusion
   between init()/exit() is provided by default_context_lock.
 - Make hotplug types and functions part of libusbi.h with the common usbi_
   prefixes (removes hotplug.h).

Addresses issue highlighted in #855

Closes #856

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
  • Loading branch information
dickens authored and hjelmn committed Jun 3, 2021
1 parent a2b81ae commit 32a2206
Show file tree
Hide file tree
Showing 28 changed files with 333 additions and 451 deletions.
4 changes: 0 additions & 4 deletions Xcode/libusb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
008FC0211628BC5200BC5BE2 /* ezusb.c in Sources */ = {isa = PBXBuildFile; fileRef = 008FBFDC1628BA0E00BC5BE2 /* ezusb.c */; };
008FC0301628BC7400BC5BE2 /* listdevs.c in Sources */ = {isa = PBXBuildFile; fileRef = 008FBFE71628BA0E00BC5BE2 /* listdevs.c */; };
1438D77A17A2ED9F00166101 /* hotplug.c in Sources */ = {isa = PBXBuildFile; fileRef = 1438D77817A2ED9F00166101 /* hotplug.c */; };
1438D77B17A2ED9F00166101 /* hotplug.h in Headers */ = {isa = PBXBuildFile; fileRef = 1438D77917A2ED9F00166101 /* hotplug.h */; };
1438D77F17A2F0EA00166101 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 1438D77E17A2F0EA00166101 /* strerror.c */; };
2018D95F24E453BA001589B2 /* events_posix.c in Sources */ = {isa = PBXBuildFile; fileRef = 2018D95E24E453BA001589B2 /* events_posix.c */; };
2018D96124E453D0001589B2 /* events_posix.h in Headers */ = {isa = PBXBuildFile; fileRef = 2018D96024E453D0001589B2 /* events_posix.h */; };
Expand Down Expand Up @@ -266,7 +265,6 @@
008FC0151628BC0300BC5BE2 /* fxload */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fxload; sourceTree = BUILT_PRODUCTS_DIR; };
008FC0261628BC6B00BC5BE2 /* listdevs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = listdevs; sourceTree = BUILT_PRODUCTS_DIR; };
1438D77817A2ED9F00166101 /* hotplug.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.c; path = hotplug.c; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
1438D77917A2ED9F00166101 /* hotplug.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = hotplug.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
1438D77E17A2F0EA00166101 /* strerror.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.c; path = strerror.c; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
1443EE8416417E63007E0579 /* common.xcconfig */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = SOURCE_ROOT; tabWidth = 4; usesTabs = 1; };
1443EE8516417E63007E0579 /* debug.xcconfig */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.xcconfig; path = debug.xcconfig; sourceTree = SOURCE_ROOT; tabWidth = 4; usesTabs = 1; };
Expand Down Expand Up @@ -417,7 +415,6 @@
008FBF541628B7E800BC5BE2 /* core.c */,
008FBF551628B7E800BC5BE2 /* descriptor.c */,
1438D77817A2ED9F00166101 /* hotplug.c */,
1438D77917A2ED9F00166101 /* hotplug.h */,
008FBF561628B7E800BC5BE2 /* io.c */,
008FBF5A1628B7E800BC5BE2 /* libusb.h */,
008FBF671628B7E800BC5BE2 /* libusbi.h */,
Expand Down Expand Up @@ -498,7 +495,6 @@
008FBFA51628B84200BC5BE2 /* config.h in Headers */,
008FBF931628B7E800BC5BE2 /* darwin_usb.h in Headers */,
2018D96124E453D0001589B2 /* events_posix.h in Headers */,
1438D77B17A2ED9F00166101 /* hotplug.h in Headers */,
008FBF901628B7E800BC5BE2 /* libusbi.h in Headers */,
008FBF9B1628B7E800BC5BE2 /* threads_posix.h in Headers */,
008FBFA11628B7E800BC5BE2 /* version.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LIBUSB_SRC_DIR = @top_srcdir@/libusb
EXCLUDED_FILES = hotplug.h libusbi.h version.h version_nano.h
EXCLUDED_FILES = libusbi.h version.h version_nano.h
LIBUSB_SRC = $(wildcard $(LIBUSB_SRC_DIR)/*.c) $(wildcard $(LIBUSB_SRC_DIR)/*.h)
LIBUSB_DOC_SRC = $(filter-out $(addprefix $(LIBUSB_SRC_DIR)/,$(EXCLUDED_FILES)),$(LIBUSB_SRC))

Expand Down
3 changes: 1 addition & 2 deletions doc/doxygen.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,7 @@ RECURSIVE = NO
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = @top_srcdir@/libusb/hotplug.h \
@top_srcdir@/libusb/libusbi.h \
EXCLUDE = @top_srcdir@/libusb/libusbi.h \
@top_srcdir@/libusb/version.h \
@top_srcdir@/libusb/version_nano.h \
@top_srcdir@/libusb/os
Expand Down
2 changes: 1 addition & 1 deletion libusb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ endif

libusb_1_0_la_LDFLAGS = $(LT_LDFLAGS)
libusb_1_0_la_SOURCES = libusbi.h version.h version_nano.h \
core.c descriptor.c hotplug.h hotplug.c io.c strerror.c sync.c \
core.c descriptor.c hotplug.c io.c strerror.c sync.c \
$(PLATFORM_SRC) $(OS_SRC)

pkginclude_HEADERS = libusb.h
Loading

2 comments on commit 32a2206

@mcuee
Copy link
Member

@mcuee mcuee commented on 32a2206 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to #951 and #952. This commit may introduce significant performance regression for exising codes.

@mcuee
Copy link
Member

@mcuee mcuee commented on 32a2206 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, this is based on discussions in #855.

Please sign in to comment.