aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-04-13 00:46:50 +0200
committerMattias Andrée <maandree@kth.se>2019-04-13 00:46:50 +0200
commit5a50dba2c0832c58593e6aa88dd2144f64f0c544 (patch)
treed0467a2b3a5b05143e578899341946e8d28e1a91
parentFix makefile (diff)
downloadliberror-5a50dba2c0832c58593e6aa88dd2144f64f0c544.tar.gz
liberror-5a50dba2c0832c58593e6aa88dd2144f64f0c544.tar.bz2
liberror-5a50dba2c0832c58593e6aa88dd2144f64f0c544.tar.xz
Enable prefetching backtace
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--internal.c1
-rw-r--r--internal.h4
-rw-r--r--liberror.h18
-rw-r--r--set_error.c7
4 files changed, 26 insertions, 4 deletions
diff --git a/internal.c b/internal.c
index 034a2db..bad884e 100644
--- a/internal.c
+++ b/internal.c
@@ -4,3 +4,4 @@
_Thread_local struct liberror_error liberror_error_;
_Thread_local int liberror_have_error_;
+_Thread_local struct liberror_backtrace *liberror_saved_backtrace;
diff --git a/internal.h b/internal.h
index eb122ed..db33be9 100644
--- a/internal.h
+++ b/internal.h
@@ -29,6 +29,4 @@ struct liberror_backtrace {
HIDDEN extern _Thread_local struct liberror_error liberror_error_;
HIDDEN extern _Thread_local int liberror_have_error_;
-
-
-int liberror_save_backtrace(struct liberror_error *);
+extern _Thread_local struct liberror_backtrace *liberror_saved_backtrace;
diff --git a/liberror.h b/liberror.h
index 508dbac..7b5176a 100644
--- a/liberror.h
+++ b/liberror.h
@@ -180,6 +180,24 @@ void liberror_reset_error(void);
void liberror_print_backtrace(struct liberror_error *, FILE *, const char *);
/**
+ * Get backtrace and save backtrace
+ *
+ * This function will never change `errno`
+ *
+ * Note: this library does not actually save
+ * a backtrace, `-lerror-backtrace` is needed
+ * for that functionallity (it will replace
+ * some things in this library, so no other
+ * action is required)
+ *
+ * @param error The error the backtrace shall be stored in,
+ * if `NULL`, the backtrafe is saved for the
+ * next error in the thread
+ * @return 0 on success, -1 on failure
+ */
+int liberror_save_backtrace(struct liberror_error *);
+
+/**
* Set the current error for the thread
*
* If the thread already has an error saved,
diff --git a/set_error.c b/set_error.c
index 38617c7..a44aac6 100644
--- a/set_error.c
+++ b/set_error.c
@@ -33,7 +33,12 @@ liberror_set_error(const char description[256], const char source[64], const cha
stpcpy(error->source, source);
stpcpy(error->code_group, code_group);
error->code = code;
- liberror_save_backtrace(error);
+ if (liberror_saved_backtrace) {
+ error->backtrace = liberror_saved_backtrace;
+ liberror_saved_backtrace = NULL;
+ } else {
+ liberror_save_backtrace(error);
+ }
error->cause = cause;
error->failed_to_allocate_cause = have_cause && !cause;
}