some tweaks to mtx implementation to make it compilable on unsupported systems
This commit is contained in:
parent
7f870dbcd3
commit
e276de96d7
@ -41,8 +41,8 @@ typedef struct hawk_mtx_t hawk_mtx_t;
|
||||
typedef unsigned long hawk_mtx_hnd_t;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
/* not implemented */
|
||||
# error not implemented
|
||||
/* not implemented. define it to a fake type */
|
||||
typedef hawk_uintptr_t hawk_mtx_hnd_t;
|
||||
|
||||
#elif defined(__BEOS__)
|
||||
/* typedef int32 sem_id;
|
||||
@ -52,7 +52,8 @@ typedef struct hawk_mtx_t hawk_mtx_t;
|
||||
#else
|
||||
|
||||
# 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)
|
||||
# if defined(HAWK_PTHREAD_MUTEX_T_IS_SIGNED)
|
||||
|
@ -144,7 +144,19 @@ typedef struct hawk_tree_t hawk_tree_t;
|
||||
|
||||
#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>
|
||||
# endif
|
||||
|
||||
|
@ -102,9 +102,13 @@ int hawk_mtx_init (hawk_mtx_t* mtx, hawk_gem_t* gem)
|
||||
}
|
||||
|
||||
#elif defined(__DOS__)
|
||||
# error not implemented
|
||||
|
||||
/* nothing to implement */
|
||||
#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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
@ -141,10 +147,14 @@ void hawk_mtx_fini (hawk_mtx_t* mtx)
|
||||
DosCloseMutexSem (mtx->hnd);
|
||||
|
||||
#elif defined(__DOS__)
|
||||
# error not implemented
|
||||
/* nothing to destroy as there is no mutex support */
|
||||
|
||||
#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);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -222,6 +232,9 @@ int hawk_mtx_lock (hawk_mtx_t* mtx, const hawk_ntime_t* waiting_time)
|
||||
/* nothing to do */
|
||||
|
||||
#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 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)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
@ -284,6 +299,10 @@ int hawk_mtx_unlock (hawk_mtx_t* mtx)
|
||||
/* nothing to do */
|
||||
|
||||
#else
|
||||
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
|
||||
/* nothing to do as there is no actual mutex support */
|
||||
#else
|
||||
|
||||
int n;
|
||||
n = pthread_mutex_unlock((pthread_mutex_t*)&mtx->hnd);
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -317,6 +338,9 @@ int hawk_mtx_trylock (hawk_mtx_t* mtx)
|
||||
|
||||
#else
|
||||
|
||||
#if (HAWK_SIZEOF_PTHREAD_MUTEX_T <= 0)
|
||||
/* nothing to do as there is no actual mutex support */
|
||||
#else
|
||||
/* -------------------------------------------------- */
|
||||
int n;
|
||||
#if defined(HAVE_PTHREAD_MUTEX_TRYLOCK)
|
||||
@ -338,6 +362,7 @@ int hawk_mtx_trylock (hawk_mtx_t* mtx)
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user