mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 18:55:40 +03:00
shared/async: simplify asynchronous_job a bit
This commit is contained in:
parent
374c22b351
commit
c1d630d5fd
@ -41,24 +41,18 @@ int asynchronous_job(void* (*func)(void *p), void *arg) {
|
||||
* only in long running processes. */
|
||||
|
||||
r = pthread_attr_init(&a);
|
||||
if (r != 0)
|
||||
if (r > 0)
|
||||
return -r;
|
||||
|
||||
r = pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
|
||||
if (r != 0) {
|
||||
r = -r;
|
||||
if (r > 0)
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = pthread_create(&t, &a, func, arg);
|
||||
if (r != 0) {
|
||||
r = -r;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
finish:
|
||||
pthread_attr_destroy(&a);
|
||||
return r;
|
||||
return -r;
|
||||
}
|
||||
|
||||
static void *sync_thread(void *p) {
|
||||
|
@ -38,7 +38,9 @@ int main(int argc, char *argv[]) {
|
||||
fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
asynchronous_close(fd);
|
||||
|
||||
assert_se(asynchronous_job(async_func, NULL) >= 0);
|
||||
|
||||
assert_se(asynchronous_sync() >= 0);
|
||||
|
||||
sleep(1);
|
||||
|
Loading…
Reference in New Issue
Block a user