Remove non-jackdbus man pages
[jackdbus.git] / tools / zalsa / pxthread.cc
blob522827d4eabde5f4d7afcb4122905b9dfd5b72d0
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
4 //
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.
9 //
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 // ----------------------------------------------------------------------------
21 #include "pxthread.h"
24 Pxthread::Pxthread (void) : _thrid (0)
29 Pxthread::~Pxthread (void)
34 extern "C" void *Pxthread_entry_point (void *arg)
36 Pxthread *T = (Pxthread *) arg;
37 T->thr_main ();
38 return NULL;
42 int Pxthread::thr_start (int policy, int priority, size_t stacksize)
44 int min, max, rc;
45 pthread_attr_t attr;
46 struct sched_param parm;
48 min = sched_get_priority_min (policy);
49 max = sched_get_priority_max (policy);
50 priority += max;
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);
63 _thrid = 0;
64 rc = pthread_create (&_thrid,
65 &attr,
66 Pxthread_entry_point,
67 this);
69 pthread_attr_destroy (&attr);
71 return rc;
75 void Pxthread::thr_main (void)
80 void Pxthread::thr_wait (void)
82 if (_thrid == 0)
83 return;
84 pthread_join (_thrid, NULL);
85 _thrid = 0;