...
 
Commits (7)
......@@ -137,18 +137,7 @@ set(processlib_srcs
tasks/src/Rotation.cpp
tasks/src/PeakFinder.cpp
)
if(WIN32)
list(APPEND processlib_srcs
core/src/WindowSpecific/pthread_cancelling.cpp
core/src/WindowSpecific/pthread_cond.cpp
core/src/WindowSpecific/pthread_key.cpp
core/src/WindowSpecific/pthread_mutex.cpp
core/src/WindowSpecific/pthread_rwlock.cpp
core/src/WindowSpecific/pthread_thread.cpp
core/src/WindowSpecific/stdio_compat.cpp
core/src/WindowSpecific/time_compat.cpp
)
endif()
file(GLOB_RECURSE core_incs "core/include/*.h")
file(GLOB_RECURSE tasks_incs "tasks/include/*.h")
......@@ -189,6 +178,7 @@ endif(PROCESSLIB_ENABLE_GSL)
target_include_directories(processlib PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tasks/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
if(WIN32)
......@@ -206,7 +196,7 @@ if(CMAKE_THREAD_LIBS_INIT)
endif()
if(WIN32)
target_compile_definitions(processlib PRIVATE LIBPROCESSLIB_EXPORTS)
target_compile_definitions(processlib PRIVATE processlib_EXPORTS)
set_target_properties(processlib PROPERTIES PREFIX "lib")
set_target_properties(processlib PROPERTIES IMPORT_PREFIX "lib")
endif()
......@@ -220,6 +210,7 @@ if(PROCESSLIB_ENABLE_PYTHON)
set(SIP_DISABLE_FEATURES "BPM_SUPPORT")
endif(NOT PROCESSLIB_ENABLE_GSL)
add_sip_python_module(processlib "${CMAKE_CURRENT_BINARY_DIR}/sip/processlib.sip")
target_compile_definitions(python_module_processlib PRIVATE processlib_EXPORTS)
target_include_directories(python_module_processlib PRIVATE ${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/sip)
target_link_libraries(python_module_processlib PRIVATE processlib)
endif()
......
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_H__
#define __PTHREAD_H__
#define PTHREAD_CANCEL_DISABLE 0
#define PTHREAD_CANCEL_ENABLE 0x01
#define PTHREAD_CANCEL_DEFERRED 0
#define PTHREAD_CANCEL_ASYNCHRONOUS 0x02
#define PTHREAD_CANCELED ((void *)int(0xDEADBEEF))
#include "pthread_cancelling.h"
#include "pthread_cond.h"
#include "pthread_key.h"
#include "pthread_mutex.h"
#include "pthread_rwlock.h"
#include "pthread_thread.h"
#include "stdio_compat.h"
#include "time_compat.h"
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_CANCELLING_H__
#define __PTHREAD_CANCELLING_H__
#include "processlib/Compatibility.h"
#include "pthread_thread.h"
#include <Windows.h>
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT int pthread_once(pthread_once_t *o, void (*func)(void));
DLL_EXPORT void pthread_testcancel(void);
DLL_EXPORT int pthread_cancel(pthread_t t);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_COND__H__
#define __PTHREAD_COND__H__
#include "processlib/Compatibility.h"
#include <Windows.h>
#include <pthread_mutex.h>
#ifndef PTHREAD_WIN_XP_SYNC
typedef CONDITION_VARIABLE pthread_cond_t;
#else
struct pthread_cond_t
{
HANDLE mutex;
HANDLE sema;
HANDLE sema_signal;
int count_waiting;
};
#endif
typedef int pthread_condattr_t;
#define PTHREAD_COND_INITIALIZER \
{ \
0 \
}
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT int pthread_cond_init(pthread_cond_t *c, pthread_condattr_t *a);
DLL_EXPORT int pthread_cond_signal(pthread_cond_t *c);
DLL_EXPORT int pthread_cond_broadcast(pthread_cond_t *c);
DLL_EXPORT int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
DLL_EXPORT int pthread_cond_destroy(pthread_cond_t *c);
DLL_EXPORT int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, struct timespec *t);
typedef int pthread_condattr_t;
DLL_EXPORT int pthread_condattr_destroy(pthread_condattr_t *a);
#define pthread_condattr_getclock(A, C) ENOTSUP
#define pthread_condattr_setclock(A, C) ENOTSUP
DLL_EXPORT int pthread_condattr_init(pthread_condattr_t *a);
DLL_EXPORT int pthread_condattr_getpshared(pthread_condattr_t *a, int *s);
DLL_EXPORT int pthread_condattr_setpshared(pthread_condattr_t *a, int s);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_KEY_H__
#define __PTHREAD_KEY_H__
#include "processlib/Compatibility.h"
typedef long pthread_key_t;
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT int pthread_key_create(pthread_key_t *key, void (*dest)(void *));
DLL_EXPORT int pthread_key_delete(pthread_key_t key);
DLL_EXPORT void *pthread_getspecific(pthread_key_t key);
DLL_EXPORT int pthread_setspecific(pthread_key_t key, const void *pointer);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_MUTEX_H__
#define __PTHREAD_MUTEX_H__
#include "processlib/Compatibility.h"
#include <Windows.h>
#include <errno.h>
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef CRITICAL_SECTION pthread_mutex_t;
DLL_EXPORT int pthread_mutex_lock(pthread_mutex_t *m);
DLL_EXPORT int pthread_mutex_unlock(pthread_mutex_t *m);
DLL_EXPORT int pthread_mutex_trylock(pthread_mutex_t *m);
typedef int pthread_mutexattr_t;
DLL_EXPORT int pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t *a);
DLL_EXPORT int pthread_mutex_destroy(pthread_mutex_t *m);
#define PTHREAD_MUTEX_INITIALIZER \
{ \
(PRTL_CRITICAL_SECTION_DEBUG) - 1, -1, 0, 0, 0, 0 \
}
/* MSC 14 2015 provides this struct */
#if _MSC_VER < 1900
struct timespec
{
/* long long in windows is the same as long in unix for 64bit */
long long tv_sec;
long long tv_nsec;
};
#else
#include <time.h>
#endif
unsigned long long _pthread_time_in_ms(void);
unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts);
unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts);
DLL_EXPORT int pthread_mutex_timedlock(pthread_mutex_t *m, struct timespec *ts);
#ifndef ETIMEDOUT
#define ETIMEDOUT 110
#endif
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_ERRORCHECK 1
#define PTHREAD_MUTEX_RECURSIVE 2
#define PTHREAD_MUTEX_DEFAULT 3
#define PTHREAD_MUTEX_SHARED 4
#define PTHREAD_MUTEX_PRIVATE 0
#define PTHREAD_PRIO_MULT 32
#ifndef ENOTSUP
#define ENOTSUP 134
#endif
#define pthread_mutex_getprioceiling(M, P) ENOTSUP
#define pthread_mutex_setprioceiling(M, P) ENOTSUP
DLL_EXPORT int pthread_mutexattr_init(pthread_mutexattr_t *a);
DLL_EXPORT int pthread_mutexattr_destroy(pthread_mutexattr_t *a);
DLL_EXPORT int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type);
DLL_EXPORT int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type);
DLL_EXPORT int pthread_mutexattr_getpshared(pthread_mutexattr_t *a, int *type);
DLL_EXPORT int pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int type);
DLL_EXPORT int pthread_mutexattr_getprotocol(pthread_mutexattr_t *a, int *type);
DLL_EXPORT int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int type);
DLL_EXPORT int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *a, int *prio);
DLL_EXPORT int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *a, int prio);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_RWLOCK_H__
#define __PTHREAD_RWLOCK_H__
#include "processlib/Compatibility.h"
#include <Windows.h>
#ifndef PTHREAD_WIN_XP_SYNC
typedef SRWLOCK pthread_rwlock_t;
#else
struct pthread_rwlock_t
{
HANDLE mutex;
HANDLE sema_read;
HANDLE sema_write;
int reader_count;
int nb_waiting_reader;
int nb_waiting_writer;
};
#endif
typedef int pthread_rwlockattr_t;
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT int pthread_rwlock_init(pthread_rwlock_t *l, pthread_rwlockattr_t *a);
DLL_EXPORT int pthread_rwlock_destroy(pthread_rwlock_t *l);
DLL_EXPORT int pthread_rwlock_rdlock(pthread_rwlock_t *l);
DLL_EXPORT int pthread_rwlock_wrlock(pthread_rwlock_t *l);
#define PTHREAD_RWLOCK_INITIALIZER \
{ \
0 \
}
DLL_EXPORT int pthread_rwlock_tryrdlock(pthread_rwlock_t *l);
DLL_EXPORT int pthread_rwlock_trywrlock(pthread_rwlock_t *l);
DLL_EXPORT int pthread_rwlock_unlock(pthread_rwlock_t *l);
DLL_EXPORT int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const struct timespec *ts);
DLL_EXPORT int pthread_rwlock_timedwrlock(pthread_rwlock_t *l, const struct timespec *ts);
typedef int pthread_rwlockattr_t;
DLL_EXPORT int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a);
DLL_EXPORT int pthread_rwlockattr_init(pthread_rwlockattr_t *a);
DLL_EXPORT int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int *s);
DLL_EXPORT int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int s);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __PTHREAD_THREAD_H__
#define __PTHREAD_THREAD_H__
#include "processlib/Compatibility.h"
#include <Windows.h>
#include <setjmp.h>
#define PTHREAD_ONCE_INIT 0
typedef long pthread_once_t;
typedef struct _pthread_cleanup _pthread_cleanup;
struct _pthread_cleanup
{
void (*func)(void *);
void *arg;
_pthread_cleanup *next;
};
struct _pthread_v
{
void *ret_arg;
void *(*func)(void *);
_pthread_cleanup *clean;
HANDLE h;
int cancelled;
unsigned p_state;
int keymax;
void **keyval;
jmp_buf jb;
};
typedef struct _pthread_v *pthread_t;
typedef struct pthread_attr_t pthread_attr_t;
struct pthread_attr_t
{
unsigned p_state;
void *stack;
size_t s_size;
};
#define PTHREAD_DEFAULT_ATTR 0
#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 0x04
#define PTHREAD_EXPLICT_SCHED 0
#define PTHREAD_INHERIT_SCHED 0x08
#define PTHREAD_SCOPE_PROCESS 0
#define PTHREAD_SCOPE_SYSTEM 0x10
#define PTHREAD_DESTRUCTOR_ITERATIONS 256
#define PTHREAD_PRIO_NONE 0
#define PTHREAD_PRIO_INHERIT 8
#define PTHREAD_PRIO_PROTECT 16
#define PTHREAD_PROCESS_SHARED 0
#define PTHREAD_PROCESS_PRIVATE 1
#ifdef __cplusplus
extern "C" {
#endif
int _pthread_once_raw(pthread_once_t *o, void (*func)(void));
void pthread_tls_init(void);
void _pthread_cleanup_dest(pthread_t t);
DLL_EXPORT pthread_t pthread_self(void);
DLL_EXPORT int pthread_get_concurrency(int *val);
DLL_EXPORT int pthread_set_concurrency(int val);
#define pthread_getschedparam(T, P, S) ENOTSUP
#define pthread_setschedparam(T, P, S) ENOTSUP
#define pthread_getcpuclockid(T, C) ENOTSUP
DLL_EXPORT int pthread_exit(void *res);
unsigned _pthread_get_state(pthread_attr_t *attr, unsigned flag);
int _pthread_set_state(pthread_attr_t *attr, unsigned flag, unsigned val);
DLL_EXPORT int pthread_attr_init(pthread_attr_t *attr);
DLL_EXPORT int pthread_attr_destroy(pthread_attr_t *attr);
DLL_EXPORT int pthread_attr_setdetachstate(pthread_attr_t *a, int flag);
DLL_EXPORT int pthread_attr_getdetachstate(pthread_attr_t *a, int *flag);
DLL_EXPORT int pthread_attr_setinheritsched(pthread_attr_t *a, int flag);
DLL_EXPORT int pthread_attr_getinheritsched(pthread_attr_t *a, int *flag);
DLL_EXPORT int pthread_attr_setscope(pthread_attr_t *a, int flag);
DLL_EXPORT int pthread_attr_getscope(pthread_attr_t *a, int *flag);
DLL_EXPORT int pthread_attr_getstackaddr(pthread_attr_t *attr, void **stack);
DLL_EXPORT int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack);
DLL_EXPORT int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *size);
DLL_EXPORT int pthread_attr_setstacksize(pthread_attr_t *attr, size_t size);
#define pthread_attr_getguardsize(A, S) ENOTSUP
#define pthread_attr_setgaurdsize(A, S) ENOTSUP
#define pthread_attr_getschedparam(A, S) ENOTSUP
#define pthread_attr_setschedparam(A, S) ENOTSUP
#define pthread_attr_getschedpolicy(A, S) ENOTSUP
#define pthread_attr_setschedpolicy(A, S) ENOTSUP
DLL_EXPORT int pthread_setcancelstate(int state, int *oldstate);
DLL_EXPORT int pthread_setcanceltype(int type, int *oldtype);
DLL_EXPORT unsigned int pthread_create_wrapper(void *args);
DLL_EXPORT int pthread_create(pthread_t *th, pthread_attr_t *attr, void *(*func)(void *), void *arg);
DLL_EXPORT int pthread_join(pthread_t t, void **res);
DLL_EXPORT int pthread_detach(pthread_t t);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __STDIO_COMPAT_H__
#define __STDIO_COMPAT_H__
#include <math.h>
#if _MSC_VER < 1900
#ifndef snprintf
#define snprintf sprintf_s
#endif
#endif
#ifndef NAN
#define NAN NAN_func()
double NAN_func();
#endif
double win_specific_round(double a);
#endif
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __TIME_COMPAT_H__
#define __TIME_COMPAT_H__
//#include <WinSock2.h>
#include <Windows.h>
#include <time.h>
#include "processlib/Compatibility.h"
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
#define ctime_r(rTime, buffer) ctime_s(buffer, sizeof(buffer), rTime)
#define localtime_r(timep, result) localtime_s(result, timep)
struct compat_timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
#ifdef __cplusplus
extern "C" {
#endif
DLL_EXPORT int gettimeofday(struct timeval *tv, struct compat_timezone *tz);
#ifdef __cplusplus
} // Assume C declarations for C++
#endif // C++
#endif //__GETTIMEOFDAY__
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef _UNISTD_H
#define _UNISTD_H 1
/* This file intended to serve as a drop-in replacement for
* unistd.h on Windows
* Please add functionality as neeeded
*/
#include <io.h>
#include <stdlib.h>
#define srandom srand
#define random rand
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
#define X_OK 1 /* Test for execute permission. */
#define F_OK 0 /* Test for existence. */
#define access _access
#define ftruncate _chsize
#define ssize_t int
#define usleep(val) ::Sleep(val / 1000)
#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
#endif
#endif /* unistd.h */
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#if !defined(PROCESSLIB_COMPATIBILITY_H)
#define PROCESSLIB_COMPATIBILITY_H
#ifdef WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#ifdef WIN32
#if (_WIN32_WINNT < _WIN32_WINNT_LONGHORN)
#define PTHREAD_WIN_XP_SYNC
#endif
#endif
#endif //! defined(PROCESSLIB_COMPATIBILITY_H)
......@@ -34,17 +34,17 @@
#include <cstring>
#include <iostream>
#include <map>
#include <pthread.h>
#include <mutex>
#include <stdlib.h>
#include <string>
#include <vector>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
#include "processlib/ProcessExceptions.h"
struct DLL_EXPORT Buffer
struct PROCESSLIB_EXPORT Buffer
{
class DLL_EXPORT Callback
class PROCESSLIB_EXPORT Callback
{
public:
virtual ~Callback() {}
......@@ -56,9 +56,8 @@ struct DLL_EXPORT Buffer
{
if (callback)
callback->destroy(data);
pthread_mutex_destroy(&_lock);
}
Buffer() : owner(SHARED), refcount(1), data(NULL), callback(NULL) { pthread_mutex_init(&_lock, NULL); }
Buffer() : owner(SHARED), refcount(1), data(NULL), callback(NULL) {}
explicit Buffer(int aSize) : owner(SHARED), refcount(1), callback(NULL)
{
#ifdef __unix
......@@ -68,12 +67,10 @@ struct DLL_EXPORT Buffer
if (!data)
#endif
std::cerr << "Can't allocate memory" << std::endl;
pthread_mutex_init(&_lock, NULL);
}
void unref()
{
while (pthread_mutex_lock(&_lock))
;
std::lock_guard<std::mutex> lock(_mutex);
if (!(--refcount))
{
if (owner == SHARED && data)
......@@ -82,27 +79,23 @@ struct DLL_EXPORT Buffer
#else
_aligned_free(data);
#endif
pthread_mutex_unlock(&_lock);
delete this;
} else
pthread_mutex_unlock(&_lock);
}
}
void ref()
{
while (pthread_mutex_lock(&_lock))
;
std::lock_guard<std::mutex> lock(_mutex);
++refcount;
pthread_mutex_unlock(&_lock);
}
Ownership owner;
volatile int refcount;
void *data;
pthread_mutex_t _lock;
std::mutex _mutex;
Callback *callback;
};
struct DLL_EXPORT Data
struct PROCESSLIB_EXPORT Data
{
class DLL_EXPORT HeaderContainer
class PROCESSLIB_EXPORT HeaderContainer
{
public:
typedef std::map<std::string, std::string> Header;
......@@ -123,10 +116,7 @@ struct DLL_EXPORT Data
HeaderContainer &operator=(const HeaderContainer &);
// ExpertMethodes for macro insertion a loop
void lock();
void unlock();
pthread_mutex_t *mutex() const;
std::recursive_mutex &mutex() const;
Header &header();
const Header &header() const;
......@@ -577,7 +567,7 @@ Data Data::cast(Data::TYPE aType)
return aReturnData;
}
DLL_EXPORT std::ostream &operator<<(std::ostream &os, const Data::HeaderContainer &aHeader);
PROCESSLIB_EXPORT std::ostream &operator<<(std::ostream &os, const Data::HeaderContainer &aHeader);
inline std::ostream &operator<<(std::ostream &os, const Buffer &aBuffer)
{
......
......@@ -31,20 +31,21 @@
#endif
#include <map>
#include <pthread.h>
#include <mutex>
#include <string>
#include <thread>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
/** @brief this class manage error message in thread safe maner
*/
class DLL_EXPORT GslErrorMgr
class PROCESSLIB_EXPORT GslErrorMgr
{
typedef std::map<pthread_t, std::string> ErrorMessageType;
typedef std::map<pthread_t, int> ErrnoType;
typedef std::map<std::thread::id, std::string> ErrorMessageType;
typedef std::map<std::thread::id, int> ErrnoType;
public:
static inline GslErrorMgr &get() throw() { return GslErrorMgr::_errorMgr; }
static inline GslErrorMgr &get() { return GslErrorMgr::_errorMgr; }
const char *lastErrorMsg() const;
int lastErrno() const;
void resetErrorMsg();
......@@ -52,7 +53,9 @@ class DLL_EXPORT GslErrorMgr
private:
ErrorMessageType _errorMessage;
ErrnoType _lastGslErrno;
static GslErrorMgr _errorMgr;
static std::mutex _lock;
GslErrorMgr();
static void _error_handler(const char *, const char *, int, int);
......
......@@ -28,9 +28,9 @@
#include "processlib/Data.h"
#include "processlib/TaskEventCallback.h"
#include <pthread.h>
class DLL_EXPORT LinkTask
class PROCESSLIB_EXPORT LinkTask
{
public:
LinkTask();
......@@ -67,7 +67,7 @@ class DLL_EXPORT LinkTask
bool _processingInPlaceFlag;
TaskEventCallback *_eventCbkPt;
mutable pthread_mutex_t _lock;
mutable std::mutex _lock;
private:
int _refCounter;
......
......@@ -30,65 +30,43 @@
#pragma warning(disable : 4251)
#endif
#include <condition_variable>
#include <map>
#include <pthread.h>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
class TaskMgr;
struct Data;
class DLL_EXPORT PoolThreadMgr
class PROCESSLIB_EXPORT PoolThreadMgr
{
public:
typedef std::pair<int, int> TaskPriority;
PoolThreadMgr();
~PoolThreadMgr();
static PoolThreadMgr &get() throw();
static PoolThreadMgr &get();
void addProcess(TaskMgr *aProcess, bool lock = true);
void removeProcess(TaskMgr *aProcess, bool lock = true);
void setNumberOfThread(int);
void setNumberOfThread(size_t nbThread);
void setTaskMgr(const TaskMgr *);
void abort();
void suspend(bool);
bool wait(double timeout = -1.);
/// Wait until queue is empty or exit after timeout specified with rel_time_ms
/// (ms)
bool wait(int rel_time_ms);
void quit();
class Lock
{
public:
Lock(pthread_mutex_t *aLock, bool aLockFlag = true) : _lock(aLock), _lockFlag(false)
{
if (aLockFlag)
lock();
}
~Lock() { unLock(); }
inline void lock()
{
if (!_lockFlag)
while (pthread_mutex_lock(_lock))
;
_lockFlag = true;
}
inline void unLock()
{
if (_lockFlag)
{
_lockFlag = false;
pthread_mutex_unlock(_lock);
}
}
private:
pthread_mutex_t *_lock;
bool _lockFlag;
};
private:
// Thread safe Singleton (guaranted in C++11)
PoolThreadMgr() : _stopFlag(false), _suspendFlag(false), _runningThread(0), _taskMgr(NULL) {}
~PoolThreadMgr()= default;
PoolThreadMgr(const PoolThreadMgr&)= delete;
PoolThreadMgr& operator=(const PoolThreadMgr&)= delete;
struct cmp
{
bool operator()(const TaskPriority &a, const TaskPriority &b)
......@@ -101,23 +79,19 @@ class DLL_EXPORT PoolThreadMgr
};
typedef std::multimap<TaskPriority, TaskMgr *, cmp> QueueType;
pthread_mutex_t _lock;
pthread_cond_t _cond;
std::mutex m_mutex;
std::condition_variable m_cond;
std::vector<std::thread> m_threads;
static std::once_flag init_flag;
volatile bool _stopFlag;
volatile bool _suspendFlag;
volatile int _runningThread;
QueueType _processQueue;
std::vector<pthread_t> _threadID;
TaskMgr *_taskMgr;
static void *_run(void *);
void _createProcessThread(int aNumber);
#ifdef __unix
static void atfork_prepare();
static void atfork_parent();
static void atfork_child();
#endif
void _createProcessThread(size_t aNumber);
};
#endif //! defined(PROCESSLIB_POOLTHREAD_H)
......@@ -26,11 +26,13 @@
#if !defined(PROCESSLIB_SINKTASK_H)
#define PROCESSLIB_SINKTASK_H
#include <mutex>
#include "processlib/Data.h"
#include "processlib/SinkTaskMgr.h"
#include "processlib/TaskEventCallback.h"
class DLL_EXPORT SinkTaskBase
class PROCESSLIB_EXPORT SinkTaskBase
{
public:
SinkTaskBase();
......@@ -51,7 +53,7 @@ class DLL_EXPORT SinkTaskBase
protected:
virtual ~SinkTaskBase();
mutable pthread_mutex_t _lock;
mutable std::mutex _lock;
private:
TaskEventCallback *_eventCbkPt;
......
......@@ -26,20 +26,16 @@
#if !defined(PROCESSLIB_SINKTASKMGR_H)
#define PROCESSLIB_SINKTASKMGR_H
#include <pthread.h>
#ifdef __unix
#include <sys/time.h>
#endif
#include <errno.h>
#include <time.h>
#include <chrono>
#include <condition_variable>
#include <list>
#include <mutex>
#include <vector>
#include "processlib/PoolThreadMgr.h"
template <class Result>
class DLL_EXPORT SinkTaskMgr
class PROCESSLIB_EXPORT SinkTaskMgr
{
typedef std::vector<Result> FrameResultList;
......@@ -51,10 +47,10 @@ class DLL_EXPORT SinkTaskMgr
void setMode(RUN_MODE);
Result getResult(double timeout = 0., int frameNumber = -1) const;
Result getResult(int rel_time_ms = 0, int frameNumber = -1) const;
void getHistory(std::list<Result> &aHistory, int fromFrameNumber = 0) const;
void resizeHistory(int aSize);
void resetHistory(bool alockFlag = true);
void resetHistory();
int historySize() const;
//@brief return the last available frame with no hole before
int lastFrameNumber() const;
......@@ -65,14 +61,14 @@ class DLL_EXPORT SinkTaskMgr
void unref();
protected:
virtual ~SinkTaskMgr();
virtual ~SinkTaskMgr() = default;
private:
bool _isFrameAvailable(int frameNumber) const;
volatile int _currentFrameNumber;
mutable pthread_mutex_t _lock;
mutable pthread_cond_t _cond;
mutable std::mutex _lock;
mutable std::condition_variable m_cond;
FrameResultList _historyResult;
RUN_MODE _mode;
int _refCounter;
......@@ -88,22 +84,14 @@ inline bool _history_sort(const Result &A, const Result &B)
template <class Result>
SinkTaskMgr<Result>::SinkTaskMgr(int historySize) : _currentFrameNumber(0), _mode(SinkTaskMgr::Counter), _refCounter(1)
{
pthread_mutex_init(&_lock, NULL);
pthread_cond_init(&_cond, NULL);
_historyResult.resize(historySize);
resetHistory();
}
template <class Result>
SinkTaskMgr<Result>::~SinkTaskMgr()
{
pthread_mutex_destroy(&_lock);
pthread_cond_destroy(&_cond);
}
template <class Result>
void SinkTaskMgr<Result>::setMode(typename SinkTaskMgr<Result>::RUN_MODE aMode)
{
PoolThreadMgr::Lock aLock(&_lock);
std::lock_guard<std::mutex> aLock(_lock);
_mode = aMode;
}
......@@ -112,31 +100,20 @@ void SinkTaskMgr<Result>::setMode(typename SinkTaskMgr<Result>::RUN_MODE aMode)
@param frameNumber the frame id you want or last frame if < 0
*/
template <class Result>
Result SinkTaskMgr<Result>::getResult(double askedTimeout, int frameNumber) const
Result SinkTaskMgr<Result>::getResult(int rel_time_ms, int frameNumber) const
{
if (askedTimeout >= 0.)
if (rel_time_ms > 0)
{
struct timeval now;
struct timespec timeout;
int retcode = 0;
gettimeofday(&now, NULL);
timeout.tv_sec = now.tv_sec + long(askedTimeout);
timeout.tv_nsec = (now.tv_usec * 1000) + long((askedTimeout - long(askedTimeout)) * 1e9);
if (timeout.tv_nsec >= 1000000000L) // Carry
++timeout.tv_sec, timeout.tv_nsec -= 1000000000L;
PoolThreadMgr::Lock aLock(&_lock);
while (!_isFrameAvailable(frameNumber))
{
retcode = pthread_cond_timedwait(&_cond, &_lock, &timeout);
if (retcode == ETIMEDOUT)
return Result(SinkTaskMgr<Result>::TIMEDOUT);
}
std::unique_lock<std::mutex> lock(_lock);
bool res = m_cond.wait_for(lock, std::chrono::milliseconds(rel_time_ms),
[&] { return _isFrameAvailable(frameNumber); });
if (res)
return Result(SinkTaskMgr<Result>::TIMEDOUT);
} else
{
PoolThreadMgr::Lock aLock(&_lock);
while (!_isFrameAvailable(frameNumber))
pthread_cond_wait(&_cond, &_lock);
std::unique_lock<std::mutex> lock(_lock);
m_cond.wait(lock, [&] { return _isFrameAvailable(frameNumber); });
}
if (frameNumber < 0)
......@@ -151,7 +128,7 @@ Result SinkTaskMgr<Result>::getResult(double askedTimeout, int frameNumber) cons
template <class Result>
void SinkTaskMgr<Result>::setResult(const Result &aResult)
{
PoolThreadMgr::Lock aLock(&_lock);
std::lock_guard<std::mutex> aLock(_lock);
if (aResult.frameNumber > _currentFrameNumber)
_currentFrameNumber = aResult.frameNumber;
int aResultPos = aResult.frameNumber % _historyResult.size();
......@@ -163,13 +140,13 @@ void SinkTaskMgr<Result>::setResult(const Result &aResult)
{
_historyResult[aResultPos] = aResult;
}
pthread_cond_broadcast(&_cond);
m_cond.notify_all();
}
template <class Result>
void SinkTaskMgr<Result>::resetHistory(bool lockFlag)
void SinkTaskMgr<Result>::resetHistory()
{
PoolThreadMgr::Lock aLock(&_lock, lockFlag);
std::lock_guard<std::mutex> aLock(_lock);
typename std::vector<Result>::iterator i;
for (i = _historyResult.begin(); i != _historyResult.end(); ++i)
i->frameNumber = -1;
......@@ -182,7 +159,7 @@ template <class Result>
void SinkTaskMgr<Result>::getHistory(std::list<Result> &anHistory, int fromFrameNumber) const
{
bool sort_needed = false;
PoolThreadMgr::Lock aLock(&_lock);
std::lock_guard<std::mutex> aLock(_lock);
if (fromFrameNumber > _currentFrameNumber)
return; // not yet available
else if (fromFrameNumber < 0)
......@@ -237,7 +214,7 @@ void SinkTaskMgr<Result>::getHistory(std::list<Result> &anHistory, int fromFrame
}
}
}
aLock.unLock();
if (sort_needed)
anHistory.sort(_history_sort<Result>);
}
......@@ -250,15 +227,17 @@ void SinkTaskMgr<Result>::resizeHistory(int aSize)
{
if (aSize < 1)
aSize = 1;
PoolThreadMgr::Lock aLock(&_lock);
_historyResult.resize(aSize);
resetHistory(false);
{
std::lock_guard<std::mutex> aLock(_lock);
_historyResult.resize(aSize);
}
resetHistory();
}
template <class Result>
int SinkTaskMgr<Result>::historySize() const
{
PoolThreadMgr::Lock aLock(&_lock);
std::lock_guard<std::mutex> aLock(_lock);
return int(_historyResult.size());
}
......@@ -308,17 +287,17 @@ bool SinkTaskMgr<Result>::_isFrameAvailable(int aFrameNumber) const
template <class Result>
void SinkTaskMgr<Result>::ref()
{
PoolThreadMgr::Lock aLock(&_lock);
std::lock_guard<std::mutex> aLock(_lock);
++_refCounter;
}
template <class Result>
void SinkTaskMgr<Result>::unref()
{
PoolThreadMgr::Lock aLock(&_lock);
_lock.lock();
if (!(--_refCounter))
{
aLock.unLock();
_lock.unlock();
delete this;
}
}
......
......@@ -26,30 +26,26 @@
#if !defined(PROCESSLIB_STAT_H)
#define PROCESSLIB_STAT_H
#include <stdio.h> /* for printf() and fprintf() */
#ifdef __unix
#include <sys/time.h>
#endif
#include <sstream>
#include <stdlib.h>
#include <string>
class DLL_EXPORT Stat
class PROCESSLIB_EXPORT Stat
{
public:
Stat(const Data &data, const std::string &info) : _data(data), _info(info)
{
if (!info.empty())
gettimeofday(&_start, NULL);
_start = std::chrono::high_resolution_clock::now();
}
~Stat()
{
if (!_info.empty())
{
gettimeofday(&_end, NULL);
double diff = (_end.tv_sec - _start.tv_sec) + (_end.tv_usec - _start.tv_usec) / 1e6;
_end = std::chrono::high_resolution_clock::now();
auto diff = _end - _start;
std::stringstream str;
str << "take : " << diff << "s";
str << "take : " << std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() << "ms";
_data.header.insertOrIncKey(_info, str.str());
}
......@@ -58,7 +54,7 @@ class DLL_EXPORT Stat
private:
Data _data;
std::string _info;
struct timeval _start, _end;
std::chrono::high_resolution_clock::time_point _start, _end;
};
#endif //! defined(PROCESSLIB_STAT_H)
......@@ -26,10 +26,11 @@
#if !defined(PROCESSLIB_TASKEVENTCALLBACK_H)
#define PROCESSLIB_TASKEVENTCALLBACK_H
#include <mutex>
#include "processlib/Data.h"
#include <pthread.h>
class DLL_EXPORT TaskEventCallback
class PROCESSLIB_EXPORT TaskEventCallback
{
public:
TaskEventCallback();
......@@ -40,11 +41,8 @@ class DLL_EXPORT TaskEventCallback
void ref();
void unref();
protected:
virtual ~TaskEventCallback();
private:
pthread_mutex_t _lock;
std::mutex _lock;
int _refCounter;
};
......
......@@ -26,7 +26,7 @@
#if !defined(PROCESSLIB_TASKMGR_H)
#define PROCESSLIB_TASKMGR_H
#include "processlib/Compatibility.h"
#include <processlib_export.h>
#include "processlib/Data.h"
#include <deque>
......@@ -34,7 +34,7 @@ class LinkTask;
class SinkTaskBase;
class PoolThreadMgr;
class DLL_EXPORT TaskMgr
class PROCESSLIB_EXPORT TaskMgr
{
friend class PoolThreadMgr;
struct Task
......
......@@ -27,7 +27,8 @@
// Static variable
GslErrorMgr GslErrorMgr::_errorMgr;
static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
std::mutex GslErrorMgr::_lock;
static const int MAX_ERROR_SIZE = 1024;
/** @brief just set the gsl handler
......@@ -40,25 +41,25 @@ GslErrorMgr::GslErrorMgr()
*/
const char *GslErrorMgr::lastErrorMsg() const
{
PoolThreadMgr::Lock aLock(&_lock);
std::map<pthread_t, std::string>::const_iterator i = _errorMessage.find(pthread_self());
std::lock_guard<std::mutex> lock(_lock);
auto i = _errorMessage.find(std::this_thread::get_id());
return (i != _errorMessage.end()) ? i->second.c_str() : "";
}
/** @brief return the last errno
*/
int GslErrorMgr::lastErrno() const
{
PoolThreadMgr::Lock aLock(&_lock);
std::map<pthread_t, int>::const_iterator i = _lastGslErrno.find(pthread_self());
std::lock_guard<std::mutex> lock(_lock);
auto i = _lastGslErrno.find(std::this_thread::get_id());
return (i != _lastGslErrno.end()) ? i->second : 0;
}
/** @brief reset the error gsl string for this thread
*/
void GslErrorMgr::resetErrorMsg()
{
PoolThreadMgr::Lock aLock(&_lock);
_errorMessage.insert(ErrorMessageType::value_type(pthread_self(), ""));
_lastGslErrno.insert(ErrnoType::value_type(pthread_self(), 0));
std::lock_guard<std::mutex> lock(_lock);
_errorMessage.insert(ErrorMessageType::value_type(std::this_thread::get_id(), ""));
_lastGslErrno.insert(ErrnoType::value_type(std::this_thread::get_id(), 0));
}
/** @brief store gsl error into the thread's error message
......@@ -67,14 +68,15 @@ void GslErrorMgr::_error_handler(const char *reason, const char *file, int line,
{
char aTmpBuffer[MAX_ERROR_SIZE];
snprintf(aTmpBuffer, MAX_ERROR_SIZE, "GSL call failed ! : %s %s %d %d", reason, file, line, gsl_errno);
PoolThreadMgr::Lock aLock(&_lock);
std::map<pthread_t, std::string>::iterator i = get()._errorMessage.find(pthread_self());
std::lock_guard<std::mutex> lock(_lock);
auto i = get()._errorMessage.find(std::this_thread::get_id());
if (i != get()._errorMessage.end())
{
i->second += '\n';
i->second += aTmpBuffer;
} else
get()._errorMessage.insert(ErrorMessageType::value_type(pthread_self(), aTmpBuffer));
get()._lastGslErrno.insert(ErrnoType::value_type(pthread_self(), gsl_errno));
get()._errorMessage.insert(ErrorMessageType::value_type(std::this_thread::get_id(), aTmpBuffer));
get()._lastGslErrno.insert(ErrnoType::value_type(std::this_thread::get_id(), gsl_errno));
}
#endif // PROCESSLIB_WITHOUT_GSL
......@@ -26,47 +26,34 @@
struct Data::HeaderContainer::HeaderHolder
{
HeaderHolder() : refcount(1)
{
pthread_mutexattr_init(&_lock_attr);
pthread_mutexattr_settype(&_lock_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&_lock, &_lock_attr);
}
~HeaderHolder()
{
pthread_mutex_destroy(&_lock);
pthread_mutexattr_destroy(&_lock_attr);
}
HeaderHolder() : refcount(1) {}
inline void ref()
void ref()
{
while (pthread_mutex_lock(&_lock))
;
std::lock_guard<std::recursive_mutex> aLock(_lock);
++refcount;
pthread_mutex_unlock(&_lock);
}
inline void unref()
void unref()
{
while (pthread_mutex_lock(&_lock))
;
_lock.lock();
if (!(--refcount))
{
pthread_mutex_unlock(&_lock);
_lock.unlock();
delete this;
} else
pthread_mutex_unlock(&_lock);
}
}
inline void lock()
{
while (pthread_mutex_lock(&_lock))
;
}
inline void unlock() { pthread_mutex_unlock(&_lock); }
// inline void lock()
//{
// while(pthread_mutex_lock(&_lock));
//}
// inline void unlock()
//{
// pthread_mutex_unlock(&_lock);
//}
int refcount;
pthread_mutex_t _lock;
pthread_mutexattr_t _lock_attr;
std::recursive_mutex _lock;
Data::HeaderContainer::Header header;
};
......@@ -94,16 +81,15 @@ Data::HeaderContainer::~HeaderContainer()