Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
947e3b06
Commit
947e3b06
authored
Apr 30, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use template to get lambda for RAII
parent
5fd574a1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
14 deletions
+11
-14
misc.cpp
native/jni/utils/misc.cpp
+4
-4
misc.hpp
native/jni/utils/misc.hpp
+7
-10
No files found.
native/jni/utils/misc.cpp
View file @
947e3b06
...
...
@@ -126,9 +126,9 @@ int exec_command_sync(exec_t &exec) {
return
WEXITSTATUS
(
status
);
}
int
new_daemon_thread
(
void
*
(
*
start_routine
)
(
void
*
)
,
void
*
arg
,
const
pthread_attr_t
*
attr
)
{
int
new_daemon_thread
(
thread_entry
entry
,
void
*
arg
,
const
pthread_attr_t
*
attr
)
{
pthread_t
thread
;
int
ret
=
xpthread_create
(
&
thread
,
attr
,
start_routine
,
arg
);
int
ret
=
xpthread_create
(
&
thread
,
attr
,
entry
,
arg
);
if
(
ret
==
0
)
pthread_detach
(
thread
);
return
ret
;
...
...
@@ -141,8 +141,8 @@ static void *proxy_routine(void *fp) {
return
nullptr
;
}
int
new_daemon_thread
(
std
::
function
<
void
()
>
&&
fn
)
{
return
new_daemon_thread
(
proxy_routine
,
new
std
::
function
<
void
()
>
(
std
::
move
(
fn
)));
int
new_daemon_thread
(
std
::
function
<
void
()
>
&&
entry
)
{
return
new_daemon_thread
(
proxy_routine
,
new
std
::
function
<
void
()
>
(
std
::
move
(
entry
)));
}
static
char
*
argv0
;
...
...
native/jni/utils/misc.hpp
View file @
947e3b06
...
...
@@ -29,16 +29,13 @@ private:
pthread_mutex_t
*
mutex
;
};
template
<
class
Func
>
class
run_finally
{
public
:
explicit
run_finally
(
std
::
function
<
void
()
>
&&
fn
)
:
fn
(
std
::
move
(
fn
))
{}
void
disable
()
{
fn
=
nullptr
;
}
~
run_finally
()
{
if
(
fn
)
fn
();
}
explicit
run_finally
(
const
Func
&
fn
)
:
fn
(
fn
)
{}
~
run_finally
()
{
fn
();
}
private
:
std
::
function
<
void
()
>
fn
;
const
Func
&
fn
;
};
template
<
typename
T
>
...
...
@@ -64,9 +61,9 @@ int parse_int(const char *s);
static
inline
int
parse_int
(
std
::
string
s
)
{
return
parse_int
(
s
.
data
());
}
static
inline
int
parse_int
(
std
::
string_view
s
)
{
return
parse_int
(
s
.
data
());
}
int
new_daemon_thread
(
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
=
nullptr
,
const
pthread_attr_t
*
attr
=
nullptr
);
int
new_daemon_thread
(
std
::
function
<
void
()
>
&&
fn
);
using
thread_entry
=
void
*
(
*
)(
void
*
);
int
new_daemon_thread
(
thread_entry
entry
,
void
*
arg
=
nullptr
,
const
pthread_attr_t
*
attr
=
nullptr
);
int
new_daemon_thread
(
std
::
function
<
void
()
>
&&
entry
);
struct
exec_t
{
bool
err
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment