Commit 4b922ed6 authored by Laurent Claustre's avatar Laurent Claustre

Merge branch 'rm-posix-thread' into 'master'

Remove dependency to pthread, use std thread library support instead

Closes #2

See merge request !19
parents 401899bd 0813ef4c
Pipeline #8606 passed with stages
in 6 minutes and 11 seconds
......@@ -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")
......
//###########################################################################
// 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. */