The pthread.h has PTHREAD_MUTEX_RECURSIVE as an enum value, so that wouldn't work in an ifdef. Not sure if older versions had it as a define.
Good catch; this appears to be platform specific.
On OSX it's a macro, on linux it's an enum.
Might want to open an issue regarding this.
/* Mutex types. */
enum
{
PTHREAD_MUTEX_TIMED_NP,
PTHREAD_MUTEX_RECURSIVE_NP,
PTHREAD_MUTEX_ERRORCHECK_NP,
[..]
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/e044460a-00b8-bd38-9b37-71a7cbac3e71%40seriss.com.
It does look like recursive lock emulation is done if it does not think this is defined.I think it may have to add if's for various systems to know they have recursive locks, I think this is very common.
This gets into the weird "sys driver" stuff where compile-time decisions are implemented as function pointers. I really think that needs to be fixed. You can still put the implementations in different files, just put #if xxx around the include statements.
The current api is certainly wasting a lot of time and is very hard to read or debug and you cannot put break points on the functions you think you are putting them on.
On Wed, Jun 30, 2021 at 12:26 PM Greg Ercolano <er...@seriss.com> wrote:
The pthread.h has PTHREAD_MUTEX_RECURSIVE as an enum value, so that wouldn't work in an ifdef. Not sure if older versions had it as a define.
I looked at the pthread.h provided by mingw and it also has PTHREAD_MUTEX_RECURSIVE as a define. So the only (apparent) outlier seems to be Linux!
Maybe using something like
#if defined(PTHREAD_MUTEX_RECURSIVE) || defined(__USE_UNIX98)
Would cover all bases?
Example test source code:
/*FLTK feature test: do we have PTHREAD_MUTEX_RECURSIVE ?Compile: gcc -c pthread_mutex_recursive.c*/#include <pthread.h>int main() {pthread_mutexattr_t attrib;pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);return 0;}
If this compiles, then both <pthread.h> and PTHREAD_MUTEX_RECURSIVE are available.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/0625f1d1-283b-4a75-ae40-dc8e04268587n%40googlegroups.com.
I've found these situations- PTHREAD_MUTEX_RECURSIVE is #define'd :macOS, NetBSD, pthreads-mingw64
- PTHREAD_MUTEX_RECURSIVE is an enum value :Linux, FreeBSD, pthreads-mingw32
But PTHREAD_MUTEX_RECURSIVE is always usable as a C constant value.
We definitely have to remove the present usage of#ifdef PTHREAD_MUTEX_RECURSIVE
I see two ways out :
1) Only use recursive mutexes and remove all the code devoted to the support of non-recursive mutexes.That would be fine on all systems mentionned above. It would fail on systems where pthread.h exists butPTHREAD_MUTEX_RECURSIVE is neither an enum nor a preprocessor variable. Do such systems exist?
2) define an FLTK-specific preprocessor variable that would be used instead of#ifdef PTHREAD_MUTEX_RECURSIVEand that would be always set in config.h to 1, but that could be commented out to allow bulding of FLTKon a hypothetical system lacking recursive mutexes.Alternatively, the configure-time test Albrecht showed could put config.h in the adequate state.
Albrecht previously suggested to name such prepro variable USE_MUTEX_RECURSIVE
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/60431152-20BB-4480-9AF8-A9734056C07A%40gmail.com.
You may be right that it is the C++ mutexes that are fairly efficient on Windows, not the pthreads.h ones.The old school Window locks were all calls to functions in the Windows runtime library, and I think a lot of them instantly do a system trap.
All modern systems compile into at least a few inline assembly instructions that make the most common route (an uncontested mutex, for instance) much faster, as they avoid the overhead of a function call.