Skip to content

Commit bb1a51f

Browse files
committed
Cleanup: Get rid of instance, we can lock before we start thread
1 parent 1c3a33c commit bb1a51f

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

src/rtapi/uspace_posix.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@ struct PosixTask : rtapi_task
2222
struct PosixApp : RtapiApp
2323
{
2424
PosixApp(int policy = SCHED_FIFO) : RtapiApp(policy), do_thread_lock(policy != SCHED_FIFO) {
25-
if(instance != nullptr){
26-
throw std::invalid_argument("Only one instance allowed!");
27-
}
2825
pthread_once(&key_once, init_key);
2926
if(do_thread_lock) {
3027
pthread_once(&lock_once, init_lock);
3128
}
32-
instance = this;
3329
}
3430

3531
struct rtapi_task *do_task_new() {
@@ -90,6 +86,8 @@ struct PosixApp : RtapiApp
9086
return -ret;
9187
}
9288
}
89+
if(do_thread_lock)
90+
pthread_mutex_lock(&thread_lock);
9391
if((ret = pthread_create(&task->thr, &attr, &wrapper, reinterpret_cast<void*>(task))) != 0)
9492
return -ret;
9593

@@ -102,9 +100,6 @@ struct PosixApp : RtapiApp
102100
pthread_setspecific(key, arg);
103101
set_namef("rtapi_app:T#%d", task->id);
104102

105-
if(instance->do_thread_lock)
106-
pthread_mutex_lock(&instance->thread_lock);
107-
108103
struct timespec now;
109104
clock_gettime(CLOCK_MONOTONIC, &now);
110105
rtapi_timespec_advance(task->nextstart, now, task->period + task->pll_correction);
@@ -216,12 +211,8 @@ struct PosixApp : RtapiApp
216211
struct timespec ts = {0, ns};
217212
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, nullptr);
218213
}
219-
220-
static PosixApp* instance;
221214
};
222215

223-
PosixApp* PosixApp::instance=nullptr;
224-
225216
pthread_once_t PosixApp::key_once = PTHREAD_ONCE_INIT;
226217
pthread_once_t PosixApp::lock_once = PTHREAD_ONCE_INIT;
227218
pthread_key_t PosixApp::key;

0 commit comments

Comments
 (0)