aboutsummaryrefslogtreecommitdiff
path: root/src/threading.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2018-11-27 15:39:30 +0100
committerBenoit Germain <bnt.germain@gmail.com>2018-11-27 15:39:30 +0100
commit3aed735e5523af04ff24fd73c4b38944d3ab283d (patch)
treec0827580f2885f1ce49f9d20ec96406e53f83976 /src/threading.c
parenteae02827ca659a25949c212d8e53dd4334df32d0 (diff)
parent0709c08e07e4c5b1696200cd5ee5da0b371e481f (diff)
downloadlanes-3aed735e5523af04ff24fd73c4b38944d3ab283d.tar.gz
lanes-3aed735e5523af04ff24fd73c4b38944d3ab283d.tar.bz2
lanes-3aed735e5523af04ff24fd73c4b38944d3ab283d.zip
Merge branch 'master' of https://github.com/LuaLanes/lanes
Diffstat (limited to 'src/threading.c')
-rw-r--r--src/threading.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/threading.c b/src/threading.c
index c0e6a55..1eab52f 100644
--- a/src/threading.c
+++ b/src/threading.c
@@ -34,6 +34,14 @@ THE SOFTWARE.
34 34
35=============================================================================== 35===============================================================================
36*/ 36*/
37#if defined(__linux__)
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
43#endif
44
37#include <stdio.h> 45#include <stdio.h>
38#include <stdlib.h> 46#include <stdlib.h>
39#include <assert.h> 47#include <assert.h>
@@ -58,6 +66,10 @@ THE SOFTWARE.
58 volatile bool_t sudo; 66 volatile bool_t sudo;
59#endif 67#endif
60 68
69#ifdef PLATFORM_OSX
70# include "threading_osx.h"
71#endif
72
61/* Linux with older glibc (such as Debian) don't have pthread_setname_np, but have prctl 73/* Linux with older glibc (such as Debian) don't have pthread_setname_np, but have prctl
62*/ 74*/
63#if defined PLATFORM_LINUX 75#if defined PLATFORM_LINUX
@@ -789,7 +801,9 @@ void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data,
789 // "The specified scheduling parameters are only used if the scheduling 801 // "The specified scheduling parameters are only used if the scheduling
790 // parameter inheritance attribute is PTHREAD_EXPLICIT_SCHED." 802 // parameter inheritance attribute is PTHREAD_EXPLICIT_SCHED."
791 // 803 //
804#if !defined __ANDROID__ || ( defined __ANDROID__ && __ANDROID_API__ >= 28 )
792 PT_CALL( pthread_attr_setinheritsched( &a, PTHREAD_EXPLICIT_SCHED)); 805 PT_CALL( pthread_attr_setinheritsched( &a, PTHREAD_EXPLICIT_SCHED));
806#endif
793 807
794#ifdef _PRIO_SCOPE 808#ifdef _PRIO_SCOPE
795 PT_CALL( pthread_attr_setscope( &a, _PRIO_SCOPE)); 809 PT_CALL( pthread_attr_setscope( &a, _PRIO_SCOPE));
@@ -884,7 +898,11 @@ void THREAD_SET_AFFINITY( unsigned int aff)
884 ++ bit; 898 ++ bit;
885 aff >>= 1; 899 aff >>= 1;
886 } 900 }
901#ifdef __ANDROID__
902 PT_CALL( sched_setaffinity( pthread_self(), sizeof(cpu_set_t), &cpuset));
903#else
887 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
888} 906}
889 907
890 /* 908 /*
@@ -955,15 +973,23 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *
955 } 973 }
956 // 974 //
957 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
958 pthread_cancel( *ref ); 979 pthread_cancel( *ref );
980#endif
959 } 981 }
960 982
961 void THREAD_MAKE_ASYNCH_CANCELLABLE() 983 void THREAD_MAKE_ASYNCH_CANCELLABLE()
962 { 984 {
985#ifdef __ANDROID__
986 __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!");
987#else
963 // that's the default, but just in case... 988 // that's the default, but just in case...
964 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); 989 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
965 // 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)
966 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 991 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
992#endif
967 } 993 }
968 994
969 void THREAD_SETNAME( char const* _name) 995 void THREAD_SETNAME( char const* _name)