From da2a4c3f2160b2a3103609f8c593b4f7af2752d2 Mon Sep 17 00:00:00 2001 From: valid-ptr Date: Tue, 27 Nov 2018 13:39:03 +0300 Subject: Threads compilation for Android fixed; Thread can't be killed to date (warning in logcat). --- src/threading.c | 18 ++++++++++++++++++ src/threading.h | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/threading.c b/src/threading.c index ffd063f..1eab52f 100644 --- a/src/threading.c +++ b/src/threading.c @@ -36,6 +36,10 @@ THE SOFTWARE. */ #if defined(__linux__) # define _GNU_SOURCE /* must be defined before any include */ +# ifdef __ANDROID__ +# include +# define LOG_TAG "LuaLanes" +# endif #endif #include @@ -797,7 +801,9 @@ void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, // "The specified scheduling parameters are only used if the scheduling // parameter inheritance attribute is PTHREAD_EXPLICIT_SCHED." // +#if !defined __ANDROID__ || ( defined __ANDROID__ && __ANDROID_API__ >= 28 ) PT_CALL( pthread_attr_setinheritsched( &a, PTHREAD_EXPLICIT_SCHED)); +#endif #ifdef _PRIO_SCOPE PT_CALL( pthread_attr_setscope( &a, _PRIO_SCOPE)); @@ -892,7 +898,11 @@ void THREAD_SET_AFFINITY( unsigned int aff) ++ bit; aff >>= 1; } +#ifdef __ANDROID__ + PT_CALL( sched_setaffinity( pthread_self(), sizeof(cpu_set_t), &cpuset)); +#else PT_CALL( pthread_setaffinity_np( pthread_self(), sizeof(cpu_set_t), &cpuset)); +#endif } /* @@ -963,15 +973,23 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T * } // void THREAD_KILL( THREAD_T *ref ) { +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot kill thread!"); +#else pthread_cancel( *ref ); +#endif } void THREAD_MAKE_ASYNCH_CANCELLABLE() { +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); +#else // that's the default, but just in case... pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); +#endif } void THREAD_SETNAME( char const* _name) diff --git a/src/threading.h b/src/threading.h index 8ebe805..063cc82 100644 --- a/src/threading.h +++ b/src/threading.h @@ -143,7 +143,7 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; // #if defined( PLATFORM_OSX) #define YIELD() pthread_yield_np() - #elif defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) // no PTHREAD for PLATFORM_XBOX +#elif defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) || defined(__ANDROID__) // no PTHREAD for PLATFORM_XBOX // for some reason win32-pthread doesn't have pthread_yield(), but sched_yield() #define YIELD() sched_yield() #else -- cgit v1.2.3-55-g6feb