Skip to content

Commit

Permalink
convert source code to pure C
Browse files Browse the repository at this point in the history
List<T> is now a really ugly macro.

Added a workaround for jack.h not putting `void` in function
prototypes for functions that take no arguments. I made upstream
pull requests to jack1 and jack2 but I don't have high hopes
about them getting merged.

I removed the lock-free atomic asserts. clang reports
non-lock-free atomics when in fact it does have lock-free
atomics. I inspected the generated code for gcc and clang
for fetch_add, load, and store, on x86_64 and armhf, and
it's all lock free.

Closes #45.
  • Loading branch information
andrewrk committed Nov 10, 2015
1 parent baba806 commit ee7c0d3
Show file tree
Hide file tree
Showing 30 changed files with 1,868 additions and 1,785 deletions.
35 changes: 15 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8.5)
project(libsoundio C CXX)
project(libsoundio C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

if(CMAKE_VERSION VERSION_LESS 3.0.0)
Expand Down Expand Up @@ -135,12 +135,12 @@ endif()


set(LIBSOUNDIO_SOURCES
"${CMAKE_SOURCE_DIR}/src/soundio.cpp"
"${CMAKE_SOURCE_DIR}/src/util.cpp"
"${CMAKE_SOURCE_DIR}/src/os.cpp"
"${CMAKE_SOURCE_DIR}/src/dummy.cpp"
"${CMAKE_SOURCE_DIR}/src/channel_layout.cpp"
"${CMAKE_SOURCE_DIR}/src/ring_buffer.cpp"
"${CMAKE_SOURCE_DIR}/src/soundio.c"
"${CMAKE_SOURCE_DIR}/src/util.c"
"${CMAKE_SOURCE_DIR}/src/os.c"
"${CMAKE_SOURCE_DIR}/src/dummy.c"
"${CMAKE_SOURCE_DIR}/src/channel_layout.c"
"${CMAKE_SOURCE_DIR}/src/ring_buffer.c"
)

set(CONFIGURE_OUT_FILE "${CMAKE_BINARY_DIR}/config.h")
Expand All @@ -152,27 +152,27 @@ set(LIBSOUNDIO_HEADERS

if(SOUNDIO_HAVE_JACK)
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
"${CMAKE_SOURCE_DIR}/src/jack.cpp"
"${CMAKE_SOURCE_DIR}/src/jack.c"
)
endif()
if(SOUNDIO_HAVE_PULSEAUDIO)
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
"${CMAKE_SOURCE_DIR}/src/pulseaudio.cpp"
"${CMAKE_SOURCE_DIR}/src/pulseaudio.c"
)
endif()
if(SOUNDIO_HAVE_ALSA)
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
"${CMAKE_SOURCE_DIR}/src/alsa.cpp"
"${CMAKE_SOURCE_DIR}/src/alsa.c"
)
endif()
if(SOUNDIO_HAVE_COREAUDIO)
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
"${CMAKE_SOURCE_DIR}/src/coreaudio.cpp"
"${CMAKE_SOURCE_DIR}/src/coreaudio.c"
)
endif()
if(SOUNDIO_HAVE_WASAPI)
set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES}
"${CMAKE_SOURCE_DIR}/src/wasapi.cpp"
"${CMAKE_SOURCE_DIR}/src/wasapi.c"
)
endif()

Expand All @@ -195,15 +195,10 @@ set(LIBSOUNDIO_LIBS



# GTFO, -lstdc++ !!
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -pedantic")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -pedantic")


set(LIB_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -Wno-c99-extensions")
set(LIB_CFLAGS "-std=c11 -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -D_REENTRANT -D_POSIX_C_SOURCE=200809L")
set(EXAMPLE_CFLAGS "-std=c99 -Wall")
set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage")
set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage")
Expand Down Expand Up @@ -277,15 +272,15 @@ if(BUILD_EXAMPLE_PROGRAMS)
endif()

if(BUILD_TESTS)
add_executable(unit_tests "${CMAKE_SOURCE_DIR}/test/unit_tests.cpp" ${LIBSOUNDIO_SOURCES})
add_executable(unit_tests "${CMAKE_SOURCE_DIR}/test/unit_tests.c" ${LIBSOUNDIO_SOURCES})
target_link_libraries(unit_tests LINK_PUBLIC ${LIBSOUNDIO_LIBS})
set_target_properties(unit_tests PROPERTIES
LINKER_LANGUAGE C
COMPILE_FLAGS ${TEST_CFLAGS}
LINK_FLAGS ${TEST_LDFLAGS}
)

add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.cpp" ${LIBSOUNDIO_SOURCES})
add_executable(latency "${CMAKE_SOURCE_DIR}/test/latency.c" ${LIBSOUNDIO_SOURCES})
target_link_libraries(latency LINK_PUBLIC ${LIBSOUNDIO_LIBS} m)
set_target_properties(latency PROPERTIES
LINKER_LANGUAGE C
Expand Down
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,6 @@ and `soundio_get_backend` to get the list of available backends.
[API Documentation](http://libsound.io/doc)
## Contributing
libsoundio is programmed in a tiny subset of C++11:
* No STL.
* No `new` or `delete`.
* No `class`. All fields in structs are `public`.
* No constructors or destructors.
* No exceptions or run-time type information.
* No references.
* No linking against libstdc++.
Do not be fooled - this is a *C library*, not a C++ library. We just take
advantage of a select few C++11 compiler features such as templates, and then
link against libc.
### Building
Install the dependencies:
Expand Down
Loading

0 comments on commit ee7c0d3

Please sign in to comment.