Skip to content

Commit 708257f

Browse files
ktopley-applerokhinip
authored andcommitted
libdispatch open source import fixups.
rdar://problem/54572081
1 parent d7be6c5 commit 708257f

12 files changed

+646
-8047
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ check_function_exists(malloc_create_zone HAVE_MALLOC_CREATE_ZONE)
192192
check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
193193
check_function_exists(posix_spawnp HAVE_POSIX_SPAWNP)
194194
check_function_exists(pthread_key_init_np HAVE_PTHREAD_KEY_INIT_NP)
195+
check_function_exists(pthread_attr_setcpupercent_np HAVE_PTHREAD_ATTR_SETCPUPERCENT_NP)
196+
check_function_exists(pthread_yield_np HAVE_PTHREAD_YIELD_NP)
195197
check_function_exists(pthread_main_np HAVE_PTHREAD_MAIN_NP)
198+
check_function_exists(pthread_workqueue_setdispatch_np HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP)
196199
check_function_exists(strlcpy HAVE_STRLCPY)
197200
check_function_exists(sysconf HAVE_SYSCONF)
198201
check_function_exists(arc4random HAVE_ARC4RANDOM)

cmake/config.h.in

+6
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,18 @@
145145
/* Define to 1 if you have the `pthread_key_init_np' function. */
146146
#cmakedefine HAVE_PTHREAD_KEY_INIT_NP
147147

148+
/* Define to 1 if you have the `pthread_attr_setcpupercent_np' function. */
149+
#cmakedefine HAVE_PTHREAD_ATTR_SETCPUPERCENT_NP
150+
148151
/* Define to 1 if you have the <pthread_machdep.h> header file. */
149152
#cmakedefine HAVE_PTHREAD_MACHDEP_H
150153

151154
/* Define to 1 if you have the `pthread_main_np' function. */
152155
#cmakedefine01 HAVE_PTHREAD_MAIN_NP
153156

157+
/* Define to 1 if you have the `pthread_yield_np' function. */
158+
#cmakedefine01 HAVE_PTHREAD_YIELD_NP
159+
154160
/* Define to 1 if you have the <pthread_np.h> header file. */
155161
#cmakedefine01 HAVE_PTHREAD_NP_H
156162

private/queue_private.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ dispatch_set_qos_class_fallback(dispatch_object_t object,
149149

150150
#define DISPATCH_QUEUE_FLAGS_MASK (DISPATCH_QUEUE_OVERCOMMIT)
151151

152+
// On FreeBSD pthread_attr_t is a typedef to a pointer type
153+
#if defined(__FreeBSD__)
154+
# define DISPATCH_QUEUE_NULLABLE_PTHREAD_ATTR_PTR _Nullable
155+
#else
156+
# define DISPATCH_QUEUE_NULLABLE_PTHREAD_ATTR_PTR
157+
#endif
158+
152159
/*!
153160
* @function dispatch_queue_attr_make_with_overcommit
154161
*
@@ -329,7 +336,7 @@ DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
329336
DISPATCH_NOTHROW
330337
dispatch_queue_global_t
331338
dispatch_pthread_root_queue_create(const char *_Nullable label,
332-
unsigned long flags, const pthread_attr_t *_Nullable attr,
339+
unsigned long flags, const pthread_attr_t DISPATCH_QUEUE_NULLABLE_PTHREAD_ATTR_PTR *_Nullable attr,
333340
dispatch_block_t _Nullable configure);
334341

335342
/*!

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ add_library(dispatch
5454
shims/perfmon.h
5555
shims/time.h
5656
shims/tsd.h
57+
shims/yield.c
5758
shims/yield.h)
5859

5960
set_target_properties(dispatch

src/event/event_kevent.c

+1
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ _dispatch_kq_unote_set_kevent(dispatch_unote_t _du, dispatch_kevent_t dk,
873873
du->du_priority),
874874
#endif
875875
};
876+
(void)pp; // if DISPATCH_USE_KEVENT_QOS == 0
876877
}
877878

878879
DISPATCH_ALWAYS_INLINE

src/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ dispatch_get_global_queue(intptr_t priority, uintptr_t flags)
374374
dispatch_assert(countof(_dispatch_root_queues) ==
375375
DISPATCH_ROOT_QUEUE_COUNT);
376376

377-
if (flags & ~(uintptr_t)DISPATCH_QUEUE_OVERCOMMIT) {
377+
if (flags & ~(unsigned long)DISPATCH_QUEUE_OVERCOMMIT) {
378378
return DISPATCH_BAD_INPUT;
379379
}
380380
dispatch_qos_t qos = _dispatch_qos_from_queue_priority(priority);

src/internal.h

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ upcast(dispatch_object_t dou)
290290
#include <sys/mman.h>
291291
#include <netinet/in.h>
292292
#endif
293-
#include <inttypes.h>
294293

295294
#ifdef __BLOCKS__
296295
#if __has_include(<Block_private.h>)

src/io.c

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#include "internal.h"
2222

23+
#if defined(__FreeBSD__)
24+
#include <fcntl.h>
25+
#define F_RDADVISE F_RDAHEAD
26+
#endif
27+
2328
#ifndef DISPATCH_IO_DEBUG
2429
#define DISPATCH_IO_DEBUG DISPATCH_DEBUG
2530
#endif

0 commit comments

Comments
 (0)