1 // ----------------------------------------------------------------------------
3 // Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // ----------------------------------------------------------------------------
24 Pxthread::Pxthread (void) : _thrid (0)
29 Pxthread::~Pxthread (void)
34 extern "C" void *Pxthread_entry_point (void *arg
)
36 Pxthread
*T
= (Pxthread
*) arg
;
42 int Pxthread::thr_start (int policy
, int priority
, size_t stacksize
)
46 struct sched_param parm
;
48 min
= sched_get_priority_min (policy
);
49 max
= sched_get_priority_max (policy
);
51 if (priority
> max
) priority
= max
;
52 if (priority
< min
) priority
= min
;
53 parm
.sched_priority
= priority
;
55 pthread_attr_init (&attr
);
56 pthread_attr_setdetachstate (&attr
, PTHREAD_CREATE_DETACHED
);
57 pthread_attr_setschedpolicy (&attr
, policy
);
58 pthread_attr_setschedparam (&attr
, &parm
);
59 pthread_attr_setscope (&attr
, PTHREAD_SCOPE_SYSTEM
);
60 pthread_attr_setinheritsched (&attr
, PTHREAD_EXPLICIT_SCHED
);
61 pthread_attr_setstacksize (&attr
, stacksize
);
64 rc
= pthread_create (&_thrid
,
69 pthread_attr_destroy (&attr
);
75 void Pxthread::thr_main (void)
80 void Pxthread::thr_wait (void)
84 pthread_join (_thrid
, NULL
);