Mercurial > libjeffpc
changeset 859:c5a5b39f464b
synch: improve mutex deadlock panic message
On FreeBSD (and possibly other systems) the strerror(EDEADLK) returns
"Resource deadlock avoided". This makes sense, but makes for a really
strange panic message:
PANIC mutex lock failed @ .../obj.c:188: Resource deadlock avoided
The simplest fix is to catch EDEADLK and use a custom string instead.
This could have been done in xstrerror, but I'm not convinced that libc's
string is universally bad.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 13 Jan 2023 10:40:17 -0500 |
parents | 797cc20540c6 |
children | 3c2e349df2d1 |
files | synch.c |
diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/synch.c Thu Nov 24 22:28:53 2022 -0500 +++ b/synch.c Fri Jan 13 10:40:17 2023 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2011-2021,2023 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -801,7 +801,8 @@ ret = pthread_mutex_lock(&l->lock); if (ret) panic("mutex lock failed @ %s:%d: %s", - where->file, where->line, strerror(ret)); + where->file, where->line, + (ret == EDEADLK) ? "Deadlock" : strerror(ret)); } void mxunlock(const struct lock_context *where, struct lock *l)