uspace_rtapi_app: thread_lock should have been shared among all threads

.. but it never was.
This commit is contained in:
Jeff Epler 2020-08-03 16:30:57 -05:00
parent e060ed4418
commit c1fdb1a58f

View file

@ -615,8 +615,9 @@ struct Posix : RtapiApp
{
Posix(int policy = SCHED_FIFO) : RtapiApp(policy), do_thread_lock(policy != SCHED_FIFO) {
pthread_once(&key_once, init_key);
if(do_thread_lock)
pthread_mutex_init(&thread_lock, 0);
if(do_thread_lock) {
pthread_once(&lock_once, init_lock);
}
}
int task_delete(int id);
int task_start(int task_id, unsigned long period_nsec);
@ -634,7 +635,6 @@ struct Posix : RtapiApp
int run_threads(int fd, int (*callback)(int fd));
static void *wrapper(void *arg);
bool do_thread_lock;
pthread_mutex_t thread_lock;
static pthread_once_t key_once;
static pthread_key_t key;
@ -642,6 +642,13 @@ struct Posix : RtapiApp
pthread_key_create(&key, NULL);
}
static pthread_once_t lock_once;
static pthread_mutex_t thread_lock;
static void init_lock(void) {
pthread_mutexattr_t attr;
pthread_mutex_init(&thread_lock, &attr);
}
long long do_get_time(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -1039,7 +1046,9 @@ int Posix::task_start(int task_id, unsigned long int period_nsec)
#define RTAPI_CLOCK (CLOCK_MONOTONIC)
pthread_once_t Posix::key_once = PTHREAD_ONCE_INIT;
pthread_once_t Posix::lock_once = PTHREAD_ONCE_INIT;
pthread_key_t Posix::key;
pthread_mutex_t Posix::thread_lock;
void *Posix::wrapper(void *arg)
{