mirror of
https://github.com/plasma-umass/coz.git
synced 2024-09-11 04:55:25 +03:00
--HG-- rename : tests/Makefile => benchmarks/Makefile rename : tests/experiment.py => benchmarks/experiment.py rename : tests/histogram/Makefile => benchmarks/histogram/Makefile rename : tests/histogram/histogram-pthread.c => benchmarks/histogram/histogram-pthread.c rename : tests/histogram/stddefines.h => benchmarks/histogram/stddefines.h rename : tests/kmeans/Makefile => benchmarks/kmeans/Makefile rename : tests/kmeans/kmeans-pthread.c => benchmarks/kmeans/kmeans-pthread.c rename : tests/kmeans/stddefines.h => benchmarks/kmeans/stddefines.h rename : tests/linear_regression/Makefile => benchmarks/linear_regression/Makefile rename : tests/linear_regression/linear_regression-pthread.c => benchmarks/linear_regression/linear_regression-pthread.c rename : tests/linear_regression/stddefines.h => benchmarks/linear_regression/stddefines.h rename : tests/matrix_multiply/Makefile => benchmarks/matrix_multiply/Makefile rename : tests/matrix_multiply/map_reduce.h => benchmarks/matrix_multiply/map_reduce.h rename : tests/matrix_multiply/matrix_multiply-pthread.c => benchmarks/matrix_multiply/matrix_multiply-pthread.c rename : tests/matrix_multiply/stddefines.h => benchmarks/matrix_multiply/stddefines.h rename : tests/pbzip2/AUTHORS => benchmarks/pbzip2/AUTHORS rename : tests/pbzip2/BZ2StreamScanner.cpp => benchmarks/pbzip2/BZ2StreamScanner.cpp rename : tests/pbzip2/BZ2StreamScanner.h => benchmarks/pbzip2/BZ2StreamScanner.h rename : tests/pbzip2/COPYING => benchmarks/pbzip2/COPYING rename : tests/pbzip2/ErrorContext.cpp => benchmarks/pbzip2/ErrorContext.cpp rename : tests/pbzip2/ErrorContext.h => benchmarks/pbzip2/ErrorContext.h rename : tests/pbzip2/Makefile => benchmarks/pbzip2/Makefile rename : tests/pbzip2/README => benchmarks/pbzip2/README rename : tests/pbzip2/pbzip2.cpp => benchmarks/pbzip2/pbzip2.cpp rename : tests/pbzip2/pbzip2.h => benchmarks/pbzip2/pbzip2.h rename : tests/pca/Makefile => benchmarks/pca/Makefile rename : tests/pca/pca-pthread.c => benchmarks/pca/pca-pthread.c rename : tests/pca/stddefines.h => benchmarks/pca/stddefines.h rename : tests/producer_consumer/Makefile => benchmarks/producer_consumer/Makefile rename : tests/producer_consumer/producer_consumer.cpp => benchmarks/producer_consumer/producer_consumer.cpp rename : tests/string_match/Makefile => benchmarks/string_match/Makefile rename : tests/string_match/map_reduce.h => benchmarks/string_match/map_reduce.h rename : tests/string_match/stddefines.h => benchmarks/string_match/stddefines.h rename : tests/string_match/string_match-pthread.c => benchmarks/string_match/string_match-pthread.c rename : tests/unbalanced/Makefile => benchmarks/unbalanced/Makefile rename : tests/unbalanced/unbalanced.cpp => benchmarks/unbalanced/unbalanced.cpp rename : tests/word_count/Makefile => benchmarks/word_count/Makefile rename : tests/word_count/sort-pthread.c => benchmarks/word_count/sort-pthread.c rename : tests/word_count/sort-pthread.h => benchmarks/word_count/sort-pthread.h rename : tests/word_count/stddefines.h => benchmarks/word_count/stddefines.h rename : tests/word_count/word_count-pthread.c => benchmarks/word_count/word_count-pthread.c rename : tests/work_queue/Makefile => benchmarks/work_queue/Makefile rename : tests/work_queue/work_queue.cpp => benchmarks/work_queue/work_queue.cpp
93 lines
1.8 KiB
C++
93 lines
1.8 KiB
C++
/*
|
|
* File: ErrorContext.cpp
|
|
* Author: Yavor Nikolov
|
|
*
|
|
* Created on 29 October 2011, 18:14
|
|
*/
|
|
|
|
#include "pbzip2.h"
|
|
#include "ErrorContext.h"
|
|
|
|
#include <cstring>
|
|
#include <cerrno>
|
|
|
|
namespace pbzip2
|
|
{
|
|
|
|
ErrorContext * ErrorContext::_instance = 0;
|
|
pthread_mutex_t ErrorContext::_err_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
ErrorContext * ErrorContext::getInstance()
|
|
{
|
|
pthread_mutex_lock( &_err_ctx_mutex );
|
|
|
|
if ( ErrorContext::_instance == NULL )
|
|
{
|
|
_instance = new(std::nothrow) ErrorContext;
|
|
|
|
if ( _instance == NULL )
|
|
{
|
|
fprintf( stderr, "pbzip2: *ERROR: Can't initialize error context - out of memory!\n" );
|
|
}
|
|
}
|
|
|
|
pthread_mutex_unlock( &_err_ctx_mutex );
|
|
|
|
return _instance;
|
|
}
|
|
|
|
void ErrorContext::printErrnoMsg( FILE * out, int err )
|
|
{
|
|
if ( err != 0 )
|
|
{
|
|
fprintf( out, "pbzip2: *ERROR: system call failed with errno=[%d: %s]!\n",
|
|
err, std::strerror( err ) );
|
|
}
|
|
}
|
|
|
|
void ErrorContext::syncPrintErrnoMsg( FILE * out, int err )
|
|
{
|
|
pthread_mutex_lock( &_err_ctx_mutex );
|
|
printErrnoMsg( out, err );
|
|
pthread_mutex_unlock( &_err_ctx_mutex );
|
|
}
|
|
|
|
void ErrorContext::printErrorMessages( FILE * out )
|
|
{
|
|
pthread_mutex_lock( &_err_ctx_mutex );
|
|
|
|
printErrnoMsg( out, _first_kernel_err_no );
|
|
printErrnoMsg( out, _last_kernel_err_no );
|
|
|
|
pthread_mutex_unlock( &_err_ctx_mutex );
|
|
}
|
|
|
|
void ErrorContext::saveError()
|
|
{
|
|
int newerr = errno;
|
|
|
|
pthread_mutex_lock( &_err_ctx_mutex );
|
|
|
|
if ( newerr != 0 )
|
|
{
|
|
int & err_ref = ( _first_kernel_err_no == 0 )
|
|
? _first_kernel_err_no
|
|
: _last_kernel_err_no;
|
|
|
|
err_ref = newerr;
|
|
}
|
|
|
|
_last_kernel_err_no = errno;
|
|
|
|
pthread_mutex_unlock( &_err_ctx_mutex );
|
|
}
|
|
|
|
void ErrorContext::reset()
|
|
{
|
|
pthread_mutex_lock( &_err_ctx_mutex );
|
|
_first_kernel_err_no = _last_kernel_err_no = 0;
|
|
pthread_mutex_unlock( &_err_ctx_mutex );
|
|
}
|
|
|
|
} // namespace pbzip2
|