MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / start

Method start

libraries/AP_HAL_Linux/Thread.cpp:161–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161bool Thread::start(const char *name, int policy, int prio)
162{
163 if (_started) {
164 return false;
165 }
166
167 struct sched_param param = { .sched_priority = prio };
168 pthread_attr_t attr;
169 int r;
170
171 pthread_attr_init(&attr);
172
173 /*
174 we need to run as root to get realtime scheduling. Allow it to
175 run as non-root for debugging purposes, plus to allow the Replay
176 tool to run
177 */
178 if (geteuid() == 0) {
179 if ((r = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) != 0 ||
180 (r = pthread_attr_setschedpolicy(&attr, policy)) != 0 ||
181 (r = pthread_attr_setschedparam(&attr, &param)) != 0) {
182 AP_HAL::panic("Failed to set attributes for thread '%s': %s",
183 name, strerror(r));
184 }
185 }
186
187 if (_stack_size) {
188 if (pthread_attr_setstacksize(&attr, _stack_size) != 0) {
189 return false;
190 }
191 }
192
193 r = pthread_create(&_ctx, &attr, &Thread::_run_trampoline, this);
194 if (r != 0) {
195 AP_HAL::panic("Failed to create thread '%s': %s",
196 name, strerror(r));
197 }
198 pthread_attr_destroy(&attr);
199
200 if (name) {
201 pthread_setname_np(_ctx, name);
202 }
203
204 _started = true;
205
206 return true;
207}
208
209bool Thread::is_current_thread()
210{

Callers 5

initMethod · 0.45
thread_createMethod · 0.45
TESTFunction · 0.45

Calls 2

strerrorFunction · 0.85
panicFunction · 0.70

Tested by 1

TESTFunction · 0.36