aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvalid-ptr <konstantin.matveyev@eligovision.ru>2018-11-27 13:39:03 +0300
committerKonstantin S. Matveyev <root@zorro.ev>2018-11-27 13:41:35 +0300
commitda2a4c3f2160b2a3103609f8c593b4f7af2752d2 (patch)
treec4a55308fb2e5ea18dda8eb56afb4653b98f19cb
parentb47776a0e7dc3c784bbd4fb037de34444b72a68d (diff)
downloadlanes-da2a4c3f2160b2a3103609f8c593b4f7af2752d2.tar.gz
lanes-da2a4c3f2160b2a3103609f8c593b4f7af2752d2.tar.bz2
lanes-da2a4c3f2160b2a3103609f8c593b4f7af2752d2.zip
Threads compilation for Android fixed; Thread can't be killed to date (warning in logcat).
-rw-r--r--src/threading.c18
-rw-r--r--src/threading.h2
2 files changed, 19 insertions, 1 deletions
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.
36*/ 36*/
37#if defined(__linux__) 37#if defined(__linux__)
38# define _GNU_SOURCE /* must be defined before any include */ 38# define _GNU_SOURCE /* must be defined before any include */
39# ifdef __ANDROID__
40# include <android/log.h>
41# define LOG_TAG "LuaLanes"
42# endif
39#endif 43#endif
40 44
41#include <stdio.h> 45#include <stdio.h>
@@ -797,7 +801,9 @@ void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data,
797 // "The specified scheduling parameters are only used if the scheduling 801 // "The specified scheduling parameters are only used if the scheduling
798 // parameter inheritance attribute is PTHREAD_EXPLICIT_SCHED." 802 // parameter inheritance attribute is PTHREAD_EXPLICIT_SCHED."
799 // 803 //
804#if !defined __ANDROID__ || ( defined __ANDROID__ && __ANDROID_API__ >= 28 )
800 PT_CALL( pthread_attr_setinheritsched( &a, PTHREAD_EXPLICIT_SCHED)); 805 PT_CALL( pthread_attr_setinheritsched( &a, PTHREAD_EXPLICIT_SCHED));
806#endif
801 807
802#ifdef _PRIO_SCOPE 808#ifdef _PRIO_SCOPE
803 PT_CALL( pthread_attr_setscope( &a, _PRIO_SCOPE)); 809 PT_CALL( pthread_attr_setscope( &a, _PRIO_SCOPE));
@@ -892,7 +898,11 @@ void THREAD_SET_AFFINITY( unsigned int aff)
892 ++ bit; 898 ++ bit;
893 aff >>= 1; 899 aff >>= 1;
894 } 900 }
901#ifdef __ANDROID__
902 PT_CALL( sched_setaffinity( pthread_self(), sizeof(cpu_set_t), &cpuset));
903#else
895 PT_CALL( pthread_setaffinity_np( pthread_self(), sizeof(cpu_set_t), &cpuset)); 904 PT_CALL( pthread_setaffinity_np( pthread_self(), sizeof(cpu_set_t), &cpuset));
905#endif
896} 906}
897 907
898 /* 908 /*
@@ -963,15 +973,23 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *
963 } 973 }
964 // 974 //
965 void THREAD_KILL( THREAD_T *ref ) { 975 void THREAD_KILL( THREAD_T *ref ) {
976#ifdef __ANDROID__
977 __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot kill thread!");
978#else
966 pthread_cancel( *ref ); 979 pthread_cancel( *ref );
980#endif
967 } 981 }
968 982
969 void THREAD_MAKE_ASYNCH_CANCELLABLE() 983 void THREAD_MAKE_ASYNCH_CANCELLABLE()
970 { 984 {
985#ifdef __ANDROID__
986 __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!");
987#else
971 // that's the default, but just in case... 988 // that's the default, but just in case...
972 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); 989 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
973 // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) 990 // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default)
974 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 991 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
992#endif
975 } 993 }
976 994
977 void THREAD_SETNAME( char const* _name) 995 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 };
143 // 143 //
144 #if defined( PLATFORM_OSX) 144 #if defined( PLATFORM_OSX)
145 #define YIELD() pthread_yield_np() 145 #define YIELD() pthread_yield_np()
146 #elif defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) // no PTHREAD for PLATFORM_XBOX 146#elif defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) || defined(__ANDROID__) // no PTHREAD for PLATFORM_XBOX
147 // for some reason win32-pthread doesn't have pthread_yield(), but sched_yield() 147 // for some reason win32-pthread doesn't have pthread_yield(), but sched_yield()
148 #define YIELD() sched_yield() 148 #define YIELD() sched_yield()
149 #else 149 #else