From c751cc80fce8018dba44754ad5492650dcb9a198 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 29 Oct 2013 21:15:46 +0100 Subject: [PATCH] issue #642 --- arangod/VocBase/datafile.c | 3 +-- arangod/VocBase/datafile.h | 8 ++++---- arangod/VocBase/replication-applier.c | 10 ++++++++-- lib/Basics/Thread.cpp | 14 ++++++++++++-- lib/BasicsC/logging.c | 9 ++++++--- lib/BasicsC/operating-system.h | 1 + lib/BasicsC/system-compiler.h | 24 +++++++++++++++++------- lib/BasicsC/threads.h | 6 +++--- 8 files changed, 52 insertions(+), 23 deletions(-) diff --git a/arangod/VocBase/datafile.c b/arangod/VocBase/datafile.c index 97518d1e38..9841cd4b13 100644 --- a/arangod/VocBase/datafile.c +++ b/arangod/VocBase/datafile.c @@ -394,8 +394,7 @@ static int TruncateAndSealDatafile (TRI_datafile_t* datafile, TRI_FreeString(TRI_CORE_MEM_ZONE, filename); TRI_FreeString(TRI_CORE_MEM_ZONE, oldname); - TRI_SealDatafile(datafile); - return TRI_ERROR_NO_ERROR; + return TRI_SealDatafile(datafile); } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/VocBase/datafile.h b/arangod/VocBase/datafile.h index 2aade6d266..2043852c5a 100644 --- a/arangod/VocBase/datafile.h +++ b/arangod/VocBase/datafile.h @@ -540,7 +540,7 @@ void TRI_FillCrcKeyMarkerDatafile (TRI_datafile_t* datafile, int TRI_ReserveElementDatafile (TRI_datafile_t* datafile, TRI_voc_size_t size, TRI_df_marker_t** position, - TRI_voc_size_t maximalJournalSize); + TRI_voc_size_t maximalJournalSize) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief writes a marker to the datafile @@ -551,7 +551,7 @@ int TRI_WriteElementDatafile (TRI_datafile_t* datafile, void* position, TRI_df_marker_t const* marker, TRI_voc_size_t markerSize, - bool sync); + bool sync) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief checksums and writes a marker to the datafile @@ -563,7 +563,7 @@ int TRI_WriteCrcElementDatafile (TRI_datafile_t* datafile, void* position, TRI_df_marker_t* marker, TRI_voc_size_t markerSize, - bool sync); + bool sync) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief iterates over a datafile @@ -598,7 +598,7 @@ bool TRI_CloseDatafile (TRI_datafile_t* datafile); /// @brief seals a database, writes a footer, sets it to read-only //////////////////////////////////////////////////////////////////////////////// -int TRI_SealDatafile (TRI_datafile_t* datafile); +int TRI_SealDatafile (TRI_datafile_t* datafile) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief renames a datafile diff --git a/arangod/VocBase/replication-applier.c b/arangod/VocBase/replication-applier.c index 7c87ca978e..ea097b9503 100644 --- a/arangod/VocBase/replication-applier.c +++ b/arangod/VocBase/replication-applier.c @@ -803,8 +803,14 @@ int TRI_StopReplicationApplier (TRI_replication_applier_t* applier, res = TRI_JoinThread(&applier->_thread); } else { - // keep original error code - TRI_JoinThread(&applier->_thread); + // stop the thread but keep original error code + int res2 = TRI_JoinThread(&applier->_thread); + + if (res2 != TRI_ERROR_NO_ERROR) { + LOG_ERROR("could not join replication applier for database '%s': %s", + applier->_databaseName, + TRI_errno_string(res2)); + } } SetTerminateFlag(applier, false); diff --git a/lib/Basics/Thread.cpp b/lib/Basics/Thread.cpp index d13c0712c4..f42df23fc6 100644 --- a/lib/Basics/Thread.cpp +++ b/lib/Basics/Thread.cpp @@ -130,12 +130,22 @@ Thread::Thread (std::string const& name) //////////////////////////////////////////////////////////////////////////////// Thread::~Thread () { + int res; + if (_running != 0) { LOG_WARNING("forcefully shutting down thread '%s'", _name.c_str()); - TRI_StopThread(&_thread); + res = TRI_StopThread(&_thread); + + if (res != TRI_ERROR_NO_ERROR) { + LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), TRI_errno_string(res)); + } } - TRI_DetachThread(&_thread); + res = TRI_DetachThread(&_thread); + + if (res != TRI_ERROR_NO_ERROR) { + LOG_WARNING("unable to detached thread '%s': %s", _name.c_str(), TRI_errno_string(res)); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/logging.c b/lib/BasicsC/logging.c index afa689c099..3fb69c39f6 100644 --- a/lib/BasicsC/logging.c +++ b/lib/BasicsC/logging.c @@ -2034,8 +2034,11 @@ bool TRI_ShutdownLogging (bool clearBuffers) { TRI_SignalCondition(&LogCondition); TRI_UnlockCondition(&LogCondition); - // ignore all errors here as we cannot log them anywhere... - TRI_JoinThread(&LoggingThread); + if (TRI_JoinThread(&LoggingThread) != TRI_ERROR_NO_ERROR) { + // ignore all errors for now as we cannot log them anywhere... + // TODO: find some means to signal errors on shutdown + } + TRI_DestroyMutex(&LogMessageQueueLock); TRI_DestroyVector(&LogMessageQueue); TRI_DestroyCondition(&LogCondition); @@ -2048,7 +2051,7 @@ bool TRI_ShutdownLogging (bool clearBuffers) { // cleanup prefix TRI_LockSpin(&OutputPrefixLock); - if (OutputPrefix) { + if (OutputPrefix != NULL) { TRI_FreeString(TRI_CORE_MEM_ZONE, OutputPrefix); OutputPrefix = NULL; } diff --git a/lib/BasicsC/operating-system.h b/lib/BasicsC/operating-system.h index 7cf5e979f8..add501f350 100644 --- a/lib/BasicsC/operating-system.h +++ b/lib/BasicsC/operating-system.h @@ -736,6 +736,7 @@ typedef unsigned char bool; //////////////////////////////////////////////////////////////////////////////// #ifdef __GNUC__ +#define TRI_HAVE_GCC_UNUSED 1 #define TRI_HAVE_GCC_ATTRIBUTE 1 #define TRI_HAVE_GCC_BUILTIN 1 #endif diff --git a/lib/BasicsC/system-compiler.h b/lib/BasicsC/system-compiler.h index 50450029a0..91cb7de7f9 100644 --- a/lib/BasicsC/system-compiler.h +++ b/lib/BasicsC/system-compiler.h @@ -45,14 +45,24 @@ extern "C" { /// @{ //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// @brief mark a value as unused +//////////////////////////////////////////////////////////////////////////////// + +#ifdef TRI_HAVE_GCC_UNUSED +#define TRI_UNUSED __attribute__ ((unused)) +#else +#define TRI_UNUSED /* unused */ +#endif + //////////////////////////////////////////////////////////////////////////////// /// @brief warn if return is unused //////////////////////////////////////////////////////////////////////////////// -#ifdef HAVE_GCC_ATTRIBUTE -#define WARN_UNUSED __attribute__ ((warn_unused_result)) +#ifdef TRI_HAVE_GCC_ATTRIBUTE +#define TRI_WARN_UNUSED __attribute__ ((warn_unused_result)) #else -#define WARN_UNUSED /* unused */ +#define TRI_WARN_UNUSED /* unused */ #endif //////////////////////////////////////////////////////////////////////////////// @@ -62,7 +72,7 @@ extern "C" { /// a the value //////////////////////////////////////////////////////////////////////////////// -#ifdef HAVE_GCC_BUILTIN +#ifdef TRI_HAVE_GCC_BUILTIN #define EF(a) __builtin_expect(a, false) #else #define EF(a) a @@ -75,7 +85,7 @@ extern "C" { /// a the value //////////////////////////////////////////////////////////////////////////////// -#ifdef HAVE_GCC_BUILTIN +#ifdef TRI_HAVE_GCC_BUILTIN #define ET(a) __builtin_expect(a, true) #else #define ET(a) a @@ -88,7 +98,7 @@ extern "C" { /// a the value to prefetch //////////////////////////////////////////////////////////////////////////////// -#ifdef HAVE_GCC_BUILTIN +#ifdef TRI_HAVE_GCC_BUILTIN #define PR(a) __builtin_prefetch(a, 0, 0) #else #define PR(a) /* prefetch read */ @@ -101,7 +111,7 @@ extern "C" { /// a the value to prefetch //////////////////////////////////////////////////////////////////////////////// -#ifdef HAVE_GCC_BUILTIN +#ifdef TRI_HAVE_GCC_BUILTIN #define PW(a) __builtin_prefetch(a, 1, 0) #else #define PW(a) /* prefetch write */ diff --git a/lib/BasicsC/threads.h b/lib/BasicsC/threads.h index 6174bf7c72..c3977e2795 100644 --- a/lib/BasicsC/threads.h +++ b/lib/BasicsC/threads.h @@ -110,19 +110,19 @@ bool TRI_StartThread (TRI_thread_t*, char const*, void (*starter)(void*), void* /// @brief trys to stops a thread //////////////////////////////////////////////////////////////////////////////// -int TRI_StopThread (TRI_thread_t*); +int TRI_StopThread (TRI_thread_t*) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief detachs a thread //////////////////////////////////////////////////////////////////////////////// -int TRI_DetachThread (TRI_thread_t*); +int TRI_DetachThread (TRI_thread_t*) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief waits for a thread to finish //////////////////////////////////////////////////////////////////////////////// -int TRI_JoinThread (TRI_thread_t*); +int TRI_JoinThread (TRI_thread_t*) TRI_WARN_UNUSED; //////////////////////////////////////////////////////////////////////////////// /// @brief sends a signal to the thread