-
Notifications
You must be signed in to change notification settings - Fork 39
[feat] mutex + fiber + thread + io || DRAFT #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ms-jpq
wants to merge
169
commits into
matsadler:main
Choose a base branch
from
ms-jpq:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
169 commits
Select commit
Hold shift + click to select a range
5b0124c
[feat] mutex + fiber + thread + io
ms-jpq 261a9d2
CI (AGP) - 2022-08-15 01:01
ed2e39e
CI (AGP) - 2022-08-16 01:06
2adb96a
CI (AGP) - 2022-08-17 01:04
bd34e70
CI (AGP) - 2022-08-18 01:08
1063358
CI (AGP) - 2022-08-19 01:01
53bc5a9
CI (AGP) - 2022-08-20 00:57
8522f13
CI (AGP) - 2022-08-21 00:59
092858c
CI (AGP) - 2022-08-22 01:00
fc5f137
CI (AGP) - 2022-08-23 01:08
4eb361d
CI (AGP) - 2022-08-24 01:04
9a89efe
CI (AGP) - 2022-08-25 01:09
13abff1
CI (AGP) - 2022-08-26 01:04
c7b7d36
CI (AGP) - 2022-08-27 00:57
482c794
CI (AGP) - 2022-08-28 01:03
926e847
CI (AGP) - 2022-08-29 01:07
6ef3626
CI (AGP) - 2022-08-30 01:10
3dc24a3
CI (AGP) - 2022-08-31 01:13
18423e5
CI (AGP) - 2022-09-01 01:00
b2fb66d
CI (AGP) - 2022-09-02 01:02
66f539b
CI (AGP) - 2022-09-04 01:02
fc51e7a
CI (AGP) - 2022-09-05 01:14
f008157
CI (AGP) - 2022-09-06 01:07
6338563
CI (AGP) - 2022-09-07 01:10
68c490c
CI (AGP) - 2022-09-08 01:05
606e9cc
CI (AGP) - 2022-09-09 01:08
442c1ff
CI (AGP) - 2022-09-10 01:06
05a4fc6
CI (AGP) - 2022-09-11 01:08
dce599f
CI (AGP) - 2022-09-12 01:07
3eb3518
CI (AGP) - 2022-09-13 01:07
2c178f9
CI (AGP) - 2022-09-14 01:04
9e05cf2
CI (AGP) - 2022-09-15 01:10
ac20327
CI (AGP) - 2022-09-16 01:10
85ff03c
CI (AGP) - 2022-09-17 01:05
07a25f6
CI (AGP) - 2022-09-18 01:11
18f9a80
CI (AGP) - 2022-09-19 01:07
b09ed2e
CI (AGP) - 2022-09-20 01:09
f2c45f6
CI (AGP) - 2022-09-21 01:11
5f67029
CI (AGP) - 2022-09-22 01:06
079a522
CI (AGP) - 2022-09-23 01:13
f46b0cf
CI (AGP) - 2022-09-24 01:11
d9b95b7
CI (AGP) - 2022-09-25 01:06
a6944a6
CI (AGP) - 2022-09-26 01:08
277ba3c
CI (AGP) - 2022-09-27 01:11
fcbdcf5
CI (AGP) - 2022-09-28 01:10
f3b142a
CI (AGP) - 2022-09-29 01:15
473ef2e
CI (AGP) - 2022-09-30 01:28
2b1b7ad
CI (AGP) - 2022-10-01 01:23
9b0799e
CI (AGP) - 2022-10-02 01:18
1a54828
CI (AGP) - 2022-10-03 01:08
bb95663
CI (AGP) - 2022-10-04 01:16
9480a42
CI (AGP) - 2022-10-05 01:15
0ef9d1e
CI (AGP) - 2022-10-06 01:09
4a6240c
CI (AGP) - 2022-10-07 01:19
2d78c7d
CI (AGP) - 2022-10-08 01:03
75189f4
CI (AGP) - 2022-10-09 01:09
056f1c1
CI (AGP) - 2022-10-10 01:14
e6578e1
CI (AGP) - 2022-10-11 01:06
50bd75a
CI (AGP) - 2022-10-12 01:21
60e3342
CI (AGP) - 2022-10-13 01:12
9f8179c
CI (AGP) - 2022-10-14 01:21
b6d0eab
CI (AGP) - 2022-10-15 01:14
8233753
CI (AGP) - 2022-10-16 01:18
51d3e69
CI (AGP) - 2022-10-17 01:20
7774e27
CI (AGP) - 2022-10-18 01:14
3dbbe1d
CI (AGP) - 2022-10-19 01:14
27ebb5f
CI (AGP) - 2022-10-20 01:10
70c71f6
CI (AGP) - 2022-10-21 01:08
c15e2ed
CI (AGP) - 2022-10-22 01:16
8a01b90
CI (AGP) - 2022-10-23 01:12
84c30c7
CI (AGP) - 2022-10-24 01:23
c16ce94
CI (AGP) - 2022-10-25 01:20
c988cff
CI (AGP) - 2022-10-26 01:05
92555a4
CI (AGP) - 2022-10-27 01:05
6d898cd
CI (AGP) - 2022-10-28 01:10
90cac10
CI (AGP) - 2022-10-29 00:58
e8340b8
CI (AGP) - 2022-10-30 01:11
6a44e24
CI (AGP) - 2022-10-31 01:12
cbe26d1
CI (AGP) - 2022-11-01 01:16
4a55530
CI (AGP) - 2022-11-02 01:09
c0ffaa3
CI (AGP) - 2022-11-03 01:03
269fd5d
CI (AGP) - 2022-11-04 01:04
0332f2b
CI (AGP) - 2022-11-05 01:03
9a3df1e
CI (AGP) - 2022-11-06 01:02
8beaec8
CI (AGP) - 2022-11-07 00:59
eb1f3fd
CI (AGP) - 2022-11-08 01:00
d270692
CI (AGP) - 2022-11-09 01:02
539e6fc
CI (AGP) - 2022-11-10 01:01
d4b9918
CI (AGP) - 2022-11-11 01:04
1619ab9
CI (AGP) - 2022-11-12 01:00
942a4bc
CI (AGP) - 2022-11-13 00:59
e3c51b6
CI (AGP) - 2022-11-14 00:58
c787613
CI (AGP) - 2022-11-15 00:58
dd8e03e
CI (AGP) - 2022-11-16 00:59
d395704
CI (AGP) - 2022-11-17 00:58
33f33d3
CI (AGP) - 2022-11-18 01:01
42f70b9
CI (AGP) - 2022-11-19 00:59
fd7b69f
CI (AGP) - 2022-11-20 01:01
3070c28
CI (AGP) - 2022-11-21 00:59
e045b44
CI (AGP) - 2022-11-22 00:59
69c80c8
CI (AGP) - 2022-11-23 00:52
ac70c9f
CI (AGP) - 2022-11-24 00:58
7c20c9b
CI (AGP) - 2022-11-25 00:54
ff9848c
CI (AGP) - 2022-11-26 00:49
488fb68
CI (AGP) - 2022-11-27 00:57
a86102c
CI (AGP) - 2022-11-28 00:51
3cf634a
CI (AGP) - 2022-11-29 00:54
ab6307f
CI (AGP) - 2022-11-30 00:54
d4fb86c
CI (AGP) - 2022-12-01 00:59
6a53e33
CI (AGP) - 2022-12-02 00:51
62a33e8
CI (AGP) - 2022-12-03 00:47
4820b30
CI (AGP) - 2022-12-04 00:50
efe85e6
CI (AGP) - 2022-12-05 00:49
7f03842
CI (AGP) - 2022-12-06 00:48
5ba0279
CI (AGP) - 2022-12-07 00:52
124fdea
CI (AGP) - 2022-12-08 00:48
fa78592
CI (AGP) - 2022-12-09 00:51
d793b62
CI (AGP) - 2022-12-10 00:46
86d0401
CI (AGP) - 2022-12-11 00:55
dad0d67
CI (AGP) - 2022-12-12 00:52
bccac15
CI (AGP) - 2022-12-13 00:54
591255c
CI (AGP) - 2022-12-14 00:50
59791b7
CI (AGP) - 2022-12-15 00:52
d7d0244
CI (AGP) - 2022-12-16 00:49
2c1c4bb
CI (AGP) - 2022-12-17 00:44
36b2b1a
CI (AGP) - 2022-12-18 00:46
693b318
CI (AGP) - 2022-12-19 00:44
85ef3e4
CI (AGP) - 2022-12-20 00:50
99500a8
CI (AGP) - 2022-12-21 00:44
d2f6dd1
CI (AGP) - 2022-12-22 00:48
bfd37fa
CI (AGP) - 2022-12-23 00:47
f03f687
CI (AGP) - 2022-12-25 01:01
a13fa4a
CI (AGP) - 2023-01-08 01:04
385b8ec
CI (AGP) - 2023-01-15 01:04
a71222c
CI (AGP) - 2023-01-22 01:04
a6718a0
CI (AGP) - 2023-01-29 01:06
71bd137
CI (AGP) - 2023-02-05 01:06
6b988b3
CI (AGP) - 2023-02-12 01:06
c1b5798
CI (AGP) - 2023-02-19 01:05
b0b1e66
CI (AGP) - 2023-02-26 01:10
16d8e0b
CI (AGP) - 2023-03-05 01:12
88e29be
CI (AGP) - 2023-03-12 01:06
722b4fb
CI (AGP) - 2023-03-19 01:07
dd3db90
CI (AGP) - 2023-03-26 01:03
c002ffb
CI (AGP) - 2023-04-02 01:01
92403bb
CI (AGP) - 2023-04-09 00:57
cb01555
CI (AGP) - 2023-04-16 00:59
9f1b920
CI (AGP) - 2023-04-23 01:02
4d0b82d
CI (AGP) - 2023-04-30 01:03
206ebbf
CI (AGP) - 2023-05-07 01:01
30feb6e
CI (AGP) - 2023-05-14 01:00
4e70264
CI (AGP) - 2023-05-21 01:01
2f76cf5
CI (AGP) - 2023-05-28 01:04
c688438
CI (AGP) - 2023-06-04 01:15
bc04893
CI (AGP) - 2023-06-11 01:13
e3dc4a2
CI (AGP) - 2023-06-18 01:12
de64107
CI (AGP) - 2023-06-25 01:18
71856a1
CI (AGP) - 2023-07-02 01:15
c2e2e75
CI (AGP) - 2023-07-09 01:17
48d2cf2
CI (AGP) - 2023-07-16 01:21
6cfdb88
CI (AGP) - 2023-07-23 01:07
875bc25
CI (AGP) - 2023-07-30 01:00
b65dd1b
CI (AGP) - 2023-08-06 00:53
2d7651d
CI (AGP) - 2023-08-13 00:50
7880c66
CI (AGP) - 2023-08-22 04:55
922bbbe
CI (AGP) - 2023-08-22 04:57
25ba72e
CI (AGP) - 2023-08-22 05:05
78304fa
CI (AGP) - 2023-08-22 05:17
810a348
CI (AGP) - 2023-08-22 05:28
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
Auto Github Push (AGP) | ||
https://github.com/ms-jpq/auto-github-push | ||
|
||
--- | ||
2023-08-22 05:28 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
//! | ||
|
||
use { | ||
crate::{ | ||
error::Error, | ||
ruby_sys::{rb_thread_call_with_gvl, rb_thread_call_without_gvl}, | ||
}, | ||
std::{ | ||
any::Any, | ||
marker::PhantomData, | ||
os::raw::c_void, | ||
panic::{catch_unwind, AssertUnwindSafe}, | ||
ptr::null_mut, | ||
}, | ||
}; | ||
|
||
struct ExecutionContext<F, R> { | ||
closure: *mut F, | ||
rval: Option<R>, | ||
} | ||
|
||
/// Rust's panic type | ||
pub type Panic = Box<dyn 'static + Send + Any>; | ||
|
||
/// A `!Send` guard for invoking thread local GVL operations | ||
pub struct GVLContext(PhantomData<*const ()>); | ||
|
||
impl GVLContext { | ||
fn new() -> Self { | ||
Self(PhantomData) | ||
} | ||
} | ||
|
||
impl GVLContext { | ||
/// Reacquire GVL for the duration of funtion | ||
pub fn with_gvl<F, R>(&mut self, f: F) -> Result<R, Error> | ||
where | ||
F: FnOnce() -> R, | ||
{ | ||
unsafe extern "C" fn call<F, R>(context: *mut c_void) -> *mut c_void | ||
where | ||
F: FnOnce() -> R, | ||
{ | ||
let ctx = context as *mut ExecutionContext<F, Result<R, Error>>; | ||
let closure = Box::from_raw((*ctx).closure); | ||
let r = catch_unwind(AssertUnwindSafe(closure)).map_err(Error::from_panic); | ||
let prev = (*ctx).rval.replace(r); | ||
debug_assert!(prev.is_none()); | ||
null_mut() | ||
} | ||
|
||
let handle = Box::into_raw(Box::new(ExecutionContext { | ||
closure: Box::into_raw(Box::new(f)), | ||
rval: None::<Result<R, Error>>, | ||
})); | ||
let call_func = call::<F, R> as unsafe extern "C" fn(*mut c_void) -> *mut c_void; | ||
|
||
unsafe { | ||
rb_thread_call_with_gvl(Some(call_func), handle as *mut _); | ||
Box::from_raw(handle) | ||
.rval | ||
.expect("rb_thread_call_without_gvl should have finished execution") | ||
} | ||
} | ||
} | ||
|
||
/// Release GVL for the duration of the closure | ||
/// See `RThread::from_fn`'s example. | ||
/// | ||
/// Optional `cancel` fn will execute on various thread interrupts. | ||
/// Including signals. | ||
/// | ||
/// Pass in `None::<fn()>` if not required. | ||
pub fn without_gvl<F, C, FR, CR>( | ||
f: F, | ||
cancel: Option<C>, | ||
) -> (Result<FR, Error>, Option<Result<CR, Error>>) | ||
where | ||
F: FnOnce(GVLContext) -> FR, | ||
C: FnOnce() -> CR, | ||
{ | ||
unsafe extern "C" fn call<F, R>(context: *mut c_void) -> *mut c_void | ||
where | ||
F: FnOnce(GVLContext) -> R, | ||
{ | ||
let ctx = context as *mut ExecutionContext<F, Result<R, Panic>>; | ||
let closure = Box::from_raw((*ctx).closure); | ||
let r = catch_unwind(AssertUnwindSafe(|| (closure)(GVLContext::new()))); | ||
let prev = (*ctx).rval.replace(r); | ||
debug_assert!(prev.is_none()); | ||
null_mut() | ||
} | ||
|
||
unsafe extern "C" fn recall<F, R>(context: *mut c_void) | ||
where | ||
F: FnOnce() -> R, | ||
{ | ||
let ctx = context as *mut ExecutionContext<F, Result<R, Panic>>; | ||
let closure = Box::from_raw((*ctx).closure); | ||
let r = catch_unwind(AssertUnwindSafe(closure)); | ||
let prev = (*ctx).rval.replace(r); | ||
debug_assert!(prev.is_none()); | ||
} | ||
|
||
let call_handle = Box::into_raw(Box::new(ExecutionContext { | ||
closure: Box::into_raw(Box::new(f)), | ||
rval: None::<Result<FR, Panic>>, | ||
})); | ||
let recall_handle = cancel.map(|c| { | ||
Box::into_raw(Box::new(ExecutionContext { | ||
closure: Box::into_raw(Box::new(c)), | ||
rval: None::<Result<CR, Panic>>, | ||
})) | ||
}); | ||
|
||
let call_func = call::<F, FR> as unsafe extern "C" fn(*mut c_void) -> *mut c_void; | ||
let recall_func = recall_handle.map(|_| recall::<C, CR> as unsafe extern "C" fn(*mut c_void)); | ||
|
||
unsafe { | ||
rb_thread_call_without_gvl( | ||
Some(call_func), | ||
call_handle as *mut _, | ||
recall_func, | ||
match recall_handle { | ||
Some(handle) => handle as *mut _, | ||
None => null_mut(), | ||
}, | ||
); | ||
|
||
let lhs = Box::from_raw(call_handle) | ||
.rval | ||
.expect("rb_thread_call_without_gvl should have finished execution") | ||
.map_err(Error::from_panic); | ||
let rhs = recall_handle | ||
.and_then(|handle| Box::from_raw(handle).rval) | ||
.map(|rval| rval.map_err(Error::from_panic)); | ||
(lhs, rhs) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this because this needed to be polymorphic over different types of closures