24
24
#include < memory>
25
25
#include < atomic>
26
26
#include < cassert>
27
+ #include < limits>
27
28
28
29
#include < dispatch/dispatch.h>
29
30
#ifndef __OBJC__
@@ -71,8 +72,8 @@ inline namespace CO_DISPATCH_NS {
71
72
This is a very simple intrusive refcounting smart pointer to avoid pulling some external library in
72
73
*/
73
74
74
- template <class T > struct Ref { T * __nullable ptr; };
75
- template <class T > struct Noref { T * __nullable ptr; };
75
+ template <class T > struct Ref { T * _Nullable ptr; };
76
+ template <class T > struct Noref { T * _Nullable ptr; };
76
77
77
78
template <class T >
78
79
class [[clang::trivial_abi]] RefcntPtr {
@@ -107,23 +108,23 @@ inline namespace CO_DISPATCH_NS {
107
108
m_ptr = nullptr ;
108
109
}
109
110
110
- auto operator ->() const noexcept -> T * __nullable
111
+ auto operator ->() const noexcept -> T * _Nullable
111
112
{ return m_ptr; }
112
113
auto operator *() const noexcept -> T &
113
114
{ return *m_ptr; }
114
- auto get () const noexcept -> T * __nullable
115
+ auto get () const noexcept -> T * _Nullable
115
116
{ return m_ptr; }
116
117
operator bool () const noexcept
117
118
{ return m_ptr != nullptr ; }
118
119
private:
119
- T * __nullable m_ptr;
120
+ T * _Nullable m_ptr;
120
121
};
121
122
122
123
template <class T >
123
- auto ref (T * __nullable ptr) noexcept
124
+ auto ref (T * _Nullable ptr) noexcept
124
125
{ return RefcntPtr{Ref<T>{ptr}}; }
125
126
template <class T >
126
- auto noref (T * __nullable ptr) noexcept
127
+ auto noref (T * _Nullable ptr) noexcept
127
128
{ return RefcntPtr{Noref<T>{ptr}}; }
128
129
129
130
// MARK: - Dispatch object holders
@@ -132,7 +133,7 @@ inline namespace CO_DISPATCH_NS {
132
133
133
134
#if OS_OBJECT_USE_OBJC
134
135
template <class D >
135
- using DispatchHolder = D __nullable ;
136
+ using DispatchHolder = D _Nullable ;
136
137
137
138
#else
138
139
template <class D >
@@ -383,7 +384,7 @@ inline namespace CO_DISPATCH_NS {
383
384
/* *
384
385
Resumes execution for generators or coroutines that start suspended
385
386
*/
386
- auto resumeExecution (dispatch_queue_t __nullable queue) noexcept {
387
+ auto resumeExecution (dispatch_queue_t _Nullable queue) noexcept {
387
388
m_value.clear ();
388
389
m_awaiterOnResumeQueue = false ;
389
390
[[maybe_unused]] auto oldstate = m_state.exchange (s_runningMarker, std::memory_order_acq_rel);
@@ -467,7 +468,7 @@ inline namespace CO_DISPATCH_NS {
467
468
/* *
468
469
Specify a queue on which resume client
469
470
*/
470
- void setResumeQueue (dispatch_queue_t __nullable queue, dispatch_time_t when) noexcept {
471
+ void setResumeQueue (dispatch_queue_t _Nullable queue, dispatch_time_t when) noexcept {
471
472
m_resumeQueue = queue;
472
473
m_when = when;
473
474
}
@@ -510,14 +511,14 @@ inline namespace CO_DISPATCH_NS {
510
511
// the only way to optimize unnecessary dispatches.
511
512
// Setting the key is probably not cheap but likely much cheaper than suspending and
512
513
// scheduling dispatch when none is needed.
513
- auto isCurrentQueue (dispatch_queue_t __nonnull queue) const {
514
+ auto isCurrentQueue (dispatch_queue_t _Nonnull queue) const {
514
515
dispatch_queue_set_specific (queue, this , const_cast <BasicPromise *>(this ), nullptr );
515
516
bool ret = (dispatch_get_specific (this ) == this );
516
517
dispatch_queue_set_specific (queue, this , nullptr , nullptr );
517
518
return ret;
518
519
}
519
520
520
- void resumeHandleAsync (void * __nonnull handleAddr) {
521
+ void resumeHandleAsync (void * _Nonnull handleAddr) {
521
522
522
523
auto resumer = [](void * addr) {
523
524
std::coroutine_handle<>::from_address (addr).resume ();
@@ -544,7 +545,7 @@ inline namespace CO_DISPATCH_NS {
544
545
545
546
template <class Promise >
546
547
struct PromiseClientAbandoner {
547
- void operator ()(Promise * __nonnull ptr) const noexcept
548
+ void operator ()(Promise * _Nonnull ptr) const noexcept
548
549
{ ptr->clientAbandon (); }
549
550
};
550
551
template <class Promise >
@@ -633,21 +634,21 @@ inline namespace CO_DISPATCH_NS {
633
634
#ifndef __OBJC__
634
635
template <class Ret >
635
636
struct StateForFunc <Ret (^)()> : State {
636
- StateForFunc (Ret (^ __nonnull block)()) noexcept :
637
+ StateForFunc (Ret (^ _Nonnull block)()) noexcept :
637
638
func (Block_copy(block))
638
639
{}
639
640
~StateForFunc () noexcept
640
641
{ Block_release (func); }
641
642
StateForFunc (StateForFunc &&) = delete ;
642
643
StateForFunc (const StateForFunc &) = delete ;
643
644
644
- Ret (^ __nonnull func)();
645
+ Ret (^ _Nonnull func)();
645
646
};
646
647
#endif
647
648
public:
648
649
class Promise {
649
650
public:
650
- Promise (State * __nonnull state):
651
+ Promise (State * _Nonnull state):
651
652
m_sharedState (noref(state))
652
653
{}
653
654
@@ -687,7 +688,7 @@ inline namespace CO_DISPATCH_NS {
687
688
return awaiter{std::move (m_sharedState)};
688
689
}
689
690
690
- auto resumeOn (dispatch_queue_t __nullable queue,
691
+ auto resumeOn (dispatch_queue_t _Nullable queue,
691
692
dispatch_time_t when = DISPATCH_TIME_NOW) && noexcept -> DispatchAwaitable && {
692
693
m_sharedState->setResumeQueue (queue, when);
693
694
return std::move (*this );
@@ -697,7 +698,7 @@ inline namespace CO_DISPATCH_NS {
697
698
698
699
template <class Func >
699
700
requires (std::is_invocable_v<FunctionFromReference<Func>>)
700
- static auto invokeOnQueue(dispatch_queue_t __nonnull queue, Func && func) -> DispatchAwaitable {
701
+ static auto invokeOnQueue(dispatch_queue_t _Nonnull queue, Func && func) -> DispatchAwaitable {
701
702
auto * state = new StateForFunc<FunctionFromReference<Func>>(std::forward<Func>(func));
702
703
dispatch_async_f (queue, state, DispatchAwaitable::invokeFromState<Func>);
703
704
return DispatchAwaitable (state);
@@ -722,13 +723,13 @@ inline namespace CO_DISPATCH_NS {
722
723
}
723
724
724
725
private:
725
- DispatchAwaitable (State * __nonnull state) noexcept :
726
+ DispatchAwaitable (State * _Nonnull state) noexcept :
726
727
m_sharedState (state)
727
728
{}
728
729
729
730
template <class Func >
730
731
requires (std::is_invocable_v<FunctionFromReference<Func>>)
731
- static void invokeFromState (void * __nonnull ptr) noexcept {
732
+ static void invokeFromState (void * _Nonnull ptr) noexcept {
732
733
auto * state = static_cast <StateForFunc<FunctionFromReference<Func>> *>(ptr);
733
734
Promise promise (state);
734
735
#ifdef __cpp_exceptions
@@ -805,7 +806,7 @@ inline namespace CO_DISPATCH_NS {
805
806
*/
806
807
template <class Func >
807
808
requires (std::is_invocable_v<Func>)
808
- auto co_dispatch (dispatch_queue_t __nonnull queue, Func && func) {
809
+ auto co_dispatch (dispatch_queue_t _Nonnull queue, Func && func) {
809
810
return DispatchAwaitableFor<Func>::invokeOnQueue (queue, std::forward<Func>(func));
810
811
}
811
812
@@ -891,15 +892,15 @@ inline namespace CO_DISPATCH_NS {
891
892
}
892
893
893
894
894
- auto resumeOn (dispatch_queue_t __nullable queue, dispatch_time_t when = DISPATCH_TIME_NOW) && noexcept -> DispatchTask && {
895
+ auto resumeOn (dispatch_queue_t _Nullable queue, dispatch_time_t when = DISPATCH_TIME_NOW) && noexcept -> DispatchTask && {
895
896
m_promise->setResumeQueue (queue, when);
896
897
return std::move (*this );
897
898
}
898
899
auto resumeOnMainQueue (dispatch_time_t when = DISPATCH_TIME_NOW) && noexcept -> DispatchTask &&
899
900
{ return std::move (*this ).resumeOn (dispatch_get_main_queue (), when); }
900
901
901
902
private:
902
- DispatchTask (Promise * __nonnull promise) noexcept :
903
+ DispatchTask (Promise * _Nonnull promise) noexcept :
903
904
m_promise(promise)
904
905
{}
905
906
@@ -995,13 +996,13 @@ inline namespace CO_DISPATCH_NS {
995
996
};
996
997
struct NextAwaitable {
997
998
Util::ClientAbandonPtr<Promise> promise;
998
- Iterator * __nonnull it;
999
+ Iterator * _Nonnull it;
999
1000
1000
1001
void operator co_await () & = delete;
1001
1002
void operator co_await () const & = delete;
1002
1003
auto operator co_await () && noexcept {
1003
1004
struct awaiter : AwaiterBase {
1004
- Iterator * __nonnull it;
1005
+ Iterator * _Nonnull it;
1005
1006
void await_resume () noexcept (noexcept (it->m_promise->getValueToken ())) {
1006
1007
it->m_promise = std::move (AwaiterBase::promise);
1007
1008
it->m_valueToken = it->m_promise ->getValueToken ();
@@ -1024,7 +1025,7 @@ inline namespace CO_DISPATCH_NS {
1024
1025
return m_valueToken;
1025
1026
}
1026
1027
private:
1027
- Iterator (Util::ClientAbandonPtr<Promise> && promise, dispatch_queue_t __nullable queue, DelayedValue::ValueToken valueToken):
1028
+ Iterator (Util::ClientAbandonPtr<Promise> && promise, dispatch_queue_t _Nullable queue, DelayedValue::ValueToken valueToken):
1028
1029
m_promise(std::move(promise)),
1029
1030
m_queue(queue),
1030
1031
m_valueToken(valueToken)
@@ -1035,7 +1036,7 @@ inline namespace CO_DISPATCH_NS {
1035
1036
DelayedValue::ValueToken m_valueToken;
1036
1037
};
1037
1038
1038
- auto beginOn (dispatch_queue_t __nullable queue) && noexcept {
1039
+ auto beginOn (dispatch_queue_t _Nullable queue) && noexcept {
1039
1040
m_promise->resumeExecution (queue);
1040
1041
return typename Iterator::FirstAwaitable{{std::move (m_promise)}, Util::QueueHolder{queue}};
1041
1042
}
@@ -1046,15 +1047,15 @@ inline namespace CO_DISPATCH_NS {
1046
1047
auto beginSync () && noexcept
1047
1048
{ return std::move (*this ).beginOn (nullptr ); }
1048
1049
1049
- auto resumingOn (dispatch_queue_t __nullable queue) && noexcept -> DispatchGenerator && {
1050
+ auto resumingOn (dispatch_queue_t _Nullable queue) && noexcept -> DispatchGenerator && {
1050
1051
m_promise->setResumeQueue (queue, DISPATCH_TIME_NOW);
1051
1052
return std::move (*this );
1052
1053
}
1053
1054
auto resumingOnMainQueue () && noexcept -> DispatchGenerator &&
1054
1055
{ return std::move (*this ).resumingOn (dispatch_get_main_queue ()); }
1055
1056
1056
1057
private:
1057
- DispatchGenerator (Promise * __nonnull promise) noexcept :
1058
+ DispatchGenerator (Promise * _Nonnull promise) noexcept :
1058
1059
m_promise(promise)
1059
1060
{}
1060
1061
@@ -1071,7 +1072,7 @@ inline namespace CO_DISPATCH_NS {
1071
1072
If you pass your current queue and non default `when` this is equivalent to an asynchronous sleep
1072
1073
until `when` - now.
1073
1074
*/
1074
- inline auto resumeOn (dispatch_queue_t __nonnull queue, dispatch_time_t when = DISPATCH_TIME_NOW) noexcept {
1075
+ inline auto resumeOn (dispatch_queue_t _Nonnull queue, dispatch_time_t when = DISPATCH_TIME_NOW) noexcept {
1075
1076
struct Awaitable
1076
1077
{
1077
1078
dispatch_queue_t queue;
@@ -1115,7 +1116,7 @@ inline namespace CO_DISPATCH_NS {
1115
1116
struct DispatchIOResult {
1116
1117
DispatchIOResult () noexcept = default ;
1117
1118
1118
- DispatchIOResult (dispatch_data_t __nullable data, int error) noexcept :
1119
+ DispatchIOResult (dispatch_data_t _Nullable data, int error) noexcept :
1119
1120
m_data (data),
1120
1121
m_error (error)
1121
1122
{}
@@ -1126,7 +1127,7 @@ inline namespace CO_DISPATCH_NS {
1126
1127
For reads this is the data read. For writes the data that could not be written.
1127
1128
Can be nullptr
1128
1129
*/
1129
- auto data () const noexcept -> dispatch_data_t __nullable
1130
+ auto data () const noexcept -> dispatch_data_t _Nullable
1130
1131
{ return m_data; }
1131
1132
/* *
1132
1133
This value is 0 if the data was read/written successfully. If an error occurred, it contains the error number.
@@ -1146,7 +1147,7 @@ inline namespace CO_DISPATCH_NS {
1146
1147
want to monitor the operation progress. The final result is returned as coroutine result.
1147
1148
@return DispatchIOResult object with operation result
1148
1149
*/
1149
- inline auto co_dispatch_io_read (dispatch_io_t __nonnull channel, off_t offset, size_t length, dispatch_queue_t __nonnull queue, dispatch_io_handler_t __nullable progressHandler = nullptr ) {
1150
+ inline auto co_dispatch_io_read (dispatch_io_t _Nonnull channel, off_t offset, size_t length, dispatch_queue_t _Nonnull queue, dispatch_io_handler_t _Nullable progressHandler = nullptr ) {
1150
1151
return makeAwaitable<DispatchIOResult, SupportsExceptions::No>([channel, offset, length, queue, progressHandler](auto promise) {
1151
1152
dispatch_io_read (channel, offset, length, queue, ^ (bool done, dispatch_data_t data, int error){
1152
1153
if (progressHandler)
@@ -1163,7 +1164,7 @@ inline namespace CO_DISPATCH_NS {
1163
1164
1164
1165
@return DispatchIOResult object with operation result
1165
1166
*/
1166
- inline auto co_dispatch_read (dispatch_fd_t fd, size_t length, dispatch_queue_t __nonnull queue) {
1167
+ inline auto co_dispatch_read (dispatch_fd_t fd, size_t length, dispatch_queue_t _Nonnull queue) {
1167
1168
return makeAwaitable<DispatchIOResult, SupportsExceptions::No>([fd, length, queue](auto promise) {
1168
1169
dispatch_read (fd, length, queue, ^ (dispatch_data_t data, int error) {
1169
1170
promise.success (data, error);
@@ -1180,7 +1181,7 @@ inline namespace CO_DISPATCH_NS {
1180
1181
1181
1182
@return DispatchIOResult object with operation result
1182
1183
*/
1183
- inline auto co_dispatch_io_write (dispatch_io_t __nonnull channel, off_t offset, dispatch_data_t __nonnull data, dispatch_queue_t __nonnull queue, dispatch_io_handler_t __nullable progressHandler = nullptr ) {
1184
+ inline auto co_dispatch_io_write (dispatch_io_t _Nonnull channel, off_t offset, dispatch_data_t _Nonnull data, dispatch_queue_t _Nonnull queue, dispatch_io_handler_t _Nullable progressHandler = nullptr ) {
1184
1185
return makeAwaitable<DispatchIOResult, SupportsExceptions::No>([channel, offset, data, queue, progressHandler](auto promise) {
1185
1186
dispatch_io_write (channel, offset, data, queue, ^ (bool done, dispatch_data_t dataRemaining, int error){
1186
1187
if (progressHandler)
@@ -1197,7 +1198,7 @@ inline namespace CO_DISPATCH_NS {
1197
1198
1198
1199
@return DispatchIOResult object with operation result
1199
1200
*/
1200
- inline auto co_dispatch_write (dispatch_fd_t fd, dispatch_data_t __nonnull data, dispatch_queue_t __nonnull queue) {
1201
+ inline auto co_dispatch_write (dispatch_fd_t fd, dispatch_data_t _Nonnull data, dispatch_queue_t _Nonnull queue) {
1201
1202
return makeAwaitable<DispatchIOResult, SupportsExceptions::No>([fd, data, queue](auto promise) {
1202
1203
dispatch_write (fd, data, queue, ^ (dispatch_data_t dataRemaining, int error) {
1203
1204
promise.success (dataRemaining, error);
0 commit comments