From a9633313ec8e578c805cd53b37ba3360d83157bc Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 15 Aug 2017 21:59:55 -0700 Subject: Provide versions of mutex, condvar, and aio init that never fail. If the underlying platform fails (FreeBSD is the only one I'm aware of that does this!), we use a global lock or condition variable instead. This means that our lock initializers never ever fail. Probably we could eliminate most of this for Linux and Darwin, since on those platforms, mutex and condvar initialization reasonably never fails. Initial benchmarks show little difference either way -- so we can revisit (optimize) later. This removes a lot of otherwise untested code in error cases and so forth, improving coverage and resilience in the face of allocation failures. Platforms other than POSIX should follow a similar pattern if they need this. (VxWorks, I'm thinking of you.) Most sane platforms won't have an issue here, since normally these initializations do not need to allocate memory. (Reportedly, even FreeBSD has plans to "fix" this in libthr2.) While here, some bugs were fixed in initialization & teardown. The fallback code is properly tested with dedicated test cases. --- src/core/thread.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/thread.h') diff --git a/src/core/thread.h b/src/core/thread.h index 94b2a984..ee83b196 100644 --- a/src/core/thread.h +++ b/src/core/thread.h @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore +// Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -25,9 +26,8 @@ struct nni_thr { int init; }; -// nni_mtx_init initializes the mutex. (Win32 programmers take note; -// our mutexes are actually CriticalSections on Win32.) -extern int nni_mtx_init(nni_mtx *mtx); +// nni_mtx_init initializes the mutex. +extern void nni_mtx_init(nni_mtx *mtx); // nni_mtx_fini destroys the mutex and releases any resources used by it. extern void nni_mtx_fini(nni_mtx *mtx); @@ -43,7 +43,7 @@ extern void nni_mtx_unlock(nni_mtx *mtx); // nni_cv_init initializes the condition variable. The mutex supplied // must always be locked with the condition variable. -extern int nni_cv_init(nni_cv *cv, nni_mtx *); +extern void nni_cv_init(nni_cv *cv, nni_mtx *); // nni_cv_fini releases resources associated with the condition variable, // which must not be in use at the time. -- cgit v1.2.3-70-g09d2