Skip to content

Commit

Permalink
fix: cr
Browse files Browse the repository at this point in the history
1. Compile pthread_atfork.c when target contains "android".
2. Use original definition of "pthread_atfork".
  • Loading branch information
fengys1996 committed Apr 30, 2024
1 parent 19f57f2 commit fad8165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
13 changes: 9 additions & 4 deletions jemalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@ fn main() {
}
println!("cargo:rerun-if-changed=jemalloc");

cc::Build::new()
.file("src/pthread_atfork.c")
.compile("pthread_atfork");
println!("cargo:rerun-if-changed=src/pthread_atfork.c");
if target.contains("android") {
// These symbols are used by jemalloc on android but the really old android
// we're building on doesn't have them defined, so just make sure the symbols
// are available.
cc::Build::new()
.file("src/pthread_atfork.c")
.compile("pthread_atfork");
println!("cargo:rerun-if-changed=src/pthread_atfork.c");
}
}

fn run_and_log(cmd: &mut Command, log_file: &Path) {
Expand Down
16 changes: 9 additions & 7 deletions jemalloc-sys/src/pthread_atfork.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <stdint.h>
#include <pthread.h>

// These symbols are used by jemalloc on android but the really old android
// we're building on doesn't have them defined, so just make sure the symbols
// are available.
/*
* These symbols are used by jemalloc on android but the really old android
* we're building on doesn't have them defined, so just make sure the symbols
* are available.
*/
__attribute__((weak)) int
pthread_atfork(uint8_t *prefork __attribute__((unused)),
uint8_t *postfork_parent __attribute__((unused)),
uint8_t *postfork_child __attribute__((unused))) {
pthread_atfork(void (*prepare)(void) __attribute__((unused)),
void (*parent)(void) __attribute__((unused)),
void (*child)(void) __attribute__((unused))) {
return 0;
}

0 comments on commit fad8165

Please sign in to comment.