Skip to content

Commit 8a6e5d1

Browse files
committed
update CMake support for internal workqueue
remove libpwq support and add internal_workqueue. also add dtrace rules to generate provider.h
1 parent 56f36b6 commit 8a6e5d1

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

CMakeLists.txt

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
1616
find_package(Threads REQUIRED)
1717

1818
include(GNUInstallDirs)
19-
include(ExternalProject)
2019

2120
set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")
22-
set(WITH_PTHREAD_WORKQUEUES "" CACHE PATH "Path to pthread-workqueues")
2321

2422
include(DispatchAppleOptions)
2523

@@ -34,27 +32,15 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3432
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via __thread" ON)
3533
set(DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE})
3634

37-
if(EXISTS "${CMAKE_SOURCE_DIR}/libpwq/CMakeLists.txt")
38-
ExternalProject_Add(pwq
39-
SOURCE_DIR
40-
"${CMAKE_SOURCE_DIR}/libpwq"
41-
CMAKE_ARGS
42-
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
43-
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
44-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
45-
BUILD_BYPRODUCTS
46-
<INSTALL_DIR>/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
47-
ExternalProject_Get_Property(pwq install_dir)
48-
add_library(PTHREAD::workqueue UNKNOWN IMPORTED)
49-
set_target_properties(PTHREAD::workqueue
50-
PROPERTIES
51-
IMPORTED_LOCATION ${install_dir}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
52-
set(WITH_PTHREAD_WORKQUEUES "${install_dir}" CACHE PATH "Path to pthread-workqueues" FORCE)
53-
set(HAVE_PTHREAD_WORKQUEUES 1)
35+
# TODO: Real CMake logic for internal workqueues
36+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
37+
CMAKE_SYSTEM_NAME STREQUAL Android OR
38+
CMAKE_SYSTEM_NAME STREQUAL Windows)
39+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
40+
set(HAVE_PTHREAD_WORKQUEUES 0)
5441
else()
55-
# TODO(compnerd) support system installed pthread-workqueues
56-
# find_package(pthread_workqueues REQUIRED)
57-
# set(HAVE_PTHREAD_WORKQUEUES 1)
42+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 0)
43+
set(HAVE_PTHREAD_WORKQUEUES 1)
5844
endif()
5945

6046
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
@@ -179,12 +165,13 @@ check_symbol_exists(VQ_VERYLOWDISK "sys/mount.h" HAVE_DECL_VQ_VERYLOWDISK)
179165

180166
check_symbol_exists(program_invocation_name "errno.h" HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
181167

182-
find_program(dtrace_EXECUTABLE dtrace)
183-
if(dtrace_EXECUTABLE)
168+
find_program(DTRACE dtrace)
169+
if(DTRACE)
184170
add_definitions(-DDISPATCH_USE_DTRACE=1)
185171
else()
186172
add_definitions(-DDISPATCH_USE_DTRACE=0)
187173
endif()
174+
include(DTrace)
188175

189176
find_program(leaks_EXECUTABLE leaks)
190177
if(leaks_EXECUTABLE)

cmake/config.h.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
2-
/* Define if building pthread work queues from source */
3-
#cmakedefine BUILD_OWN_PTHREAD_WORKQUEUES
1+
/* Use libdispatch's own implementation of pthread workqueues */
2+
#cmakedefine01 DISPATCH_USE_INTERNAL_WORKQUEUE
43

54
/* Enable usage of thread local storage via __thread */
65
#cmakedefine01 DISPATCH_USE_THREAD_LOCAL_STORAGE

cmake/modules/DTrace.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MACRO (DTRACE_HEADER provider header)
2+
if (DTRACE)
3+
ADD_CUSTOM_COMMAND(
4+
OUTPUT ${header}
5+
COMMAND ${DTRACE} -h -s ${provider} -o ${header}
6+
DEPENDS ${provider}
7+
)
8+
ENDIF()
9+
ENDMACRO()
10+

src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11

22
include(SwiftSupport)
33

4+
set(dispatch_DTRACE_HEADERS)
5+
if(DTRACE)
6+
list(APPEND dispatch_DTRACE_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/provider.h)
7+
endif()
8+
DTRACE_HEADER(${CMAKE_CURRENT_SOURCE_DIR}/provider.d ${CMAKE_CURRENT_BINARY_DIR}/provider.h)
9+
410
set(dispatch_BLOCK_SOURCES block.cpp)
511
if(HAVE_OBJC)
612
list(APPEND dispatch_BLOCK_SOURCES data.m object.m)
713
endif()
14+
815
set(dispatch_SWIFT_SOURCES)
916
if(CMAKE_SWIFT_COMPILER)
1017
set(swift_optimization_flags)
@@ -39,7 +46,9 @@ if(CMAKE_SWIFT_COMPILER)
3946
list(APPEND dispatch_SWIFT_SOURCES
4047
swift/DispatchStubs.cc;${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
4148
endif()
49+
4250
add_library(dispatch
51+
${dispatch_DTRACE_HEADERS}
4352
allocator.c
4453
apply.c
4554
benchmark.c
@@ -77,6 +86,8 @@ add_library(dispatch
7786
event/event_epoll.c
7887
event/event_internal.h
7988
event/event_kevent.c
89+
event/workqueue_internal.h
90+
event/workqueue.c
8091
firehose/firehose_internal.h
8192
shims/android_stubs.h
8293
shims/atomic.h
@@ -96,6 +107,7 @@ add_library(dispatch
96107
target_include_directories(dispatch
97108
PRIVATE
98109
${CMAKE_BINARY_DIR}
110+
${CMAKE_CURRENT_BINARY_DIR}
99111
${CMAKE_SOURCE_DIR}
100112
${CMAKE_CURRENT_SOURCE_DIR}
101113
${CMAKE_SOURCE_DIR}/private)

0 commit comments

Comments
 (0)