some tweaks to mtx implementation to make it compilable on unsupported systems

This commit is contained in:
hyung-hwan 2022-06-16 11:36:00 +00:00
parent 7f870dbcd3
commit e276de96d7
3 changed files with 46 additions and 8 deletions

View File

@ -41,8 +41,8 @@ typedef struct hawk_mtx_t hawk_mtx_t;
typedef unsigned long hawk_mtx_hnd_t; typedef unsigned long hawk_mtx_hnd_t;
#elif defined(__DOS__) #elif defined(__DOS__)
/* not implemented */ /* not implemented. define it to a fake type */
# error not implemented typedef hawk_uintptr_t hawk_mtx_hnd_t;
#elif defined(__BEOS__) #elif defined(__BEOS__)
/* typedef int32 sem_id; /* typedef int32 sem_id;
@ -52,7 +52,8 @@ typedef struct hawk_mtx_t hawk_mtx_t;
#else #else
# if (HAWK_SIZEOF_PTHREAD_MUTEX_T == 0) # if (HAWK_SIZEOF_PTHREAD_MUTEX_T == 0)
# error unsupported /* no mutex support. just define it to an integer type to make the compiler happy */
typedef hawk_uintptr_t hawk_mtx_hnd_t;
# elif (HAWK_SIZEOF_PTHREAD_MUTEX_T == HAWK_SIZEOF_INT) # elif (HAWK_SIZEOF_PTHREAD_MUTEX_T == HAWK_SIZEOF_INT)
# if defined(HAWK_PTHREAD_MUTEX_T_IS_SIGNED) # if defined(HAWK_PTHREAD_MUTEX_T_IS_SIGNED)

View File

@ -144,7 +144,19 @@ typedef struct hawk_tree_t hawk_tree_t;
#else #else
# if !defined(HAVE___BUILTIN_MEMSET) || !defined(HAVE___BUILTIN_MEMCPY) || !defined(HAVE___BUILTIN_MEMMOVE) || !defined(HAVE___BUILTIN_MEMCMP) /* g++ 2.95 had a problem with __builtin_memxxx functions:
* implicit declaration of function `int HAWK::__builtin_memset(...)' */
# if defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ <= 2)
# undef HAVE___BUILTIN_MEMSET
# undef HAVE___BUILTIN_MEMCPY
# undef HAVE___BUILTIN_MEMMOVE
# undef HAVE___BUILTIN_MEMCMP
# endif
# if !defined(HAVE___BUILTIN_MEMSET) || \
!defined(HAVE___BUILTIN_MEMCPY) || \
!defined(HAVE___BUILTIN_MEMMOVE) || \
!defined(HAVE___BUILTIN_MEMCMP)
# include <string.h> # include <string.h>
# endif # endif

View File

@ -102,9 +102,13 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem)
} }
#elif defined(__DOS__) #elif defined(__DOS__)
# error not implemented /* nothing to implement */
#else #else
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
/* nothing to initialize as there is no actual mutex support */
#else
/* /*
hawk_ensure (pthread_mutexattr_init (&attr) == 0); hawk_ensure (pthread_mutexattr_init (&attr) == 0);
if (pthread_mutexattr_settype (&attr, type) != 0) if (pthread_mutexattr_settype (&attr, type) != 0)
@ -127,6 +131,8 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem)
return -1; return -1;
} }
} }
#endif
#endif #endif
return 0; return 0;
@ -141,10 +147,14 @@ void hawk_mtx_fini (hawk_mtx_t* mtx)
DosCloseMutexSem (mtx->hnd); DosCloseMutexSem (mtx->hnd);
#elif defined(__DOS__) #elif defined(__DOS__)
# error not implemented /* nothing to destroy as there is no mutex support */
#else #else
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
/* nothing to destroy as there is no actual mutex support */
#else
pthread_mutex_destroy ((pthread_mutex_t*)&mtx->hnd); pthread_mutex_destroy ((pthread_mutex_t*)&mtx->hnd);
#endif
#endif #endif
} }
@ -222,6 +232,9 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
/* nothing to do */ /* nothing to do */
#else #else
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
/* nothing to do as there is no actual mutex support */
#else
/* if pthread_mutex_timedlock() isn't available, don't honor the waiting time. */ /* if pthread_mutex_timedlock() isn't available, don't honor the waiting time. */
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) #if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
@ -256,6 +269,8 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) #if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
} }
#endif #endif
#endif
#endif #endif
return 0; return 0;
@ -284,6 +299,10 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx)
/* nothing to do */ /* nothing to do */
#else #else
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
/* nothing to do as there is no actual mutex support */
#else
int n; int n;
n = pthread_mutex_unlock((pthread_mutex_t*)&mtx->hnd); n = pthread_mutex_unlock((pthread_mutex_t*)&mtx->hnd);
if (n != 0) if (n != 0)
@ -291,6 +310,8 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx)
hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(n)); hawk_gem_seterrnum (mtx->gem, HAWK_NULL, hawk_syserr_to_errnum(n));
return -1; return -1;
} }
#endif
#endif #endif
return 0; return 0;
} }
@ -317,6 +338,9 @@ int hawk_mtx_trylock (hawk_mtx_t* mtx)
#else #else
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
/* nothing to do as there is no actual mutex support */
#else
/* -------------------------------------------------- */ /* -------------------------------------------------- */
int n; int n;
#if defined(HAVE_PTHREAD_MUTEX_TRYLOCK) #if defined(HAVE_PTHREAD_MUTEX_TRYLOCK)
@ -338,6 +362,7 @@ int hawk_mtx_trylock (hawk_mtx_t* mtx)
return -1; return -1;
} }
/* -------------------------------------------------- */ /* -------------------------------------------------- */
#endif
#endif #endif
return 0; return 0;