[sane-devel] pthread include ?

Olaf Meeuwissen paddy-hack at member.fsf.org
Sat Feb 13 08:40:41 UTC 2016


Hi Alessandro,

Alessandro Zummo writes:

>  Shouldn't include/sane/sanei_thread.h
>  have an
>
>  #include <pthread.h>
>
>  just before 
>
>  typedef pthread_t SANE_Pid;
>
>  ?

If there is a practice of requiring that sanei_* API users include extra
system headers in their *.c files, then, no.

Personally, I believe that header files should take care of dependencies
themselves rather than putting the onus on the user.  If sanei_thread.h
(conditionally) depends on the pthread_t type, then it had better make
sure to (conditionally) include a file that provides this type.

So, I'd say yes.  By the way, you should also check on HAVE_PTHREAD_H,
like so

  #ifdef USE_PTHREAD
  #ifdef HAVE_PTHREAD_H
  #include <pthread.h>
  typedef pthread_t SANE_Pid;
  #endif
  #else
  typedef int SANE_Pid;
  #endif

Of course, the above makes no sense but it's what the implementation of
SANE_CHECK_PTHREAD in acinclude.m4 requires.  I fixed SANE_CHECK_PTHREAD
and moved the include statement from sanei_thread.c to its header file.

Actually, the Single Unix Specification, version 2, puts the definition
of pthread_t in <sys/types.h>.  I've checked the backends that use the
sanei_thread API and all typically include a bunch of system headers
*before* the SANE project's headers.  Most list <sys/types.h> and, on my
system, that provides pthread_t as well.

# The definition is in /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
# which is included by both <pthread.h> and <sys/types.h>.

FWIW, the LSB puts the definition in pthread.h ... which seems more
sensible to me as just about all pthread API needs it anyway.

Hope this helps,
-- 
Olaf Meeuwissen, LPIC-2            FSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Software                        https://my.fsf.org/donate
 Join the Free Software Foundation              https://my.fsf.org/join





More information about the sane-devel mailing list