xref: /netbsd-src/external/gpl3/binutils/dist/gprofng/src/DbeThread.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1*cb63e24eSchristos /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
24f645668Schristos    Contributed by Oracle.
34f645668Schristos 
44f645668Schristos    This file is part of GNU Binutils.
54f645668Schristos 
64f645668Schristos    This program is free software; you can redistribute it and/or modify
74f645668Schristos    it under the terms of the GNU General Public License as published by
84f645668Schristos    the Free Software Foundation; either version 3, or (at your option)
94f645668Schristos    any later version.
104f645668Schristos 
114f645668Schristos    This program is distributed in the hope that it will be useful,
124f645668Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
134f645668Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
144f645668Schristos    GNU General Public License for more details.
154f645668Schristos 
164f645668Schristos    You should have received a copy of the GNU General Public License
174f645668Schristos    along with this program; if not, write to the Free Software
184f645668Schristos    Foundation, 51 Franklin Street - Fifth Floor, Boston,
194f645668Schristos    MA 02110-1301, USA.  */
204f645668Schristos 
214f645668Schristos #ifndef _DBETHREAD_H
224f645668Schristos #define _DBETHREAD_H
234f645668Schristos #include <pthread.h>
244f645668Schristos #include "DbeLinkList.h"
254f645668Schristos 
264f645668Schristos template <class ITEM> class Vector;
274f645668Schristos 
284f645668Schristos class DbeQueue
294f645668Schristos {
304f645668Schristos public:
314f645668Schristos   DbeQueue (int (*_func)(void *arg), void *_arg);
324f645668Schristos   ~DbeQueue ();
334f645668Schristos 
344f645668Schristos   int (*func) (void *arg);
354f645668Schristos   void *arg;
364f645668Schristos   int id;
374f645668Schristos   DbeQueue *next;
384f645668Schristos };
394f645668Schristos 
404f645668Schristos class DbeThreadPool
414f645668Schristos {
424f645668Schristos public:
434f645668Schristos   DbeThreadPool (int _max_threads);
444f645668Schristos   ~DbeThreadPool ();
454f645668Schristos   DbeQueue *get_queue ();
464f645668Schristos   void put_queue (DbeQueue *q);
474f645668Schristos   void wait_queues ();
484f645668Schristos 
494f645668Schristos   pthread_mutex_t p_mutex;
504f645668Schristos   pthread_cond_t p_cond_var;
514f645668Schristos   volatile bool no_new_queues;
524f645668Schristos private:
534f645668Schristos   Vector<pthread_t> *threads;
544f645668Schristos   int max_threads;
554f645668Schristos   DbeQueue *volatile queue;
564f645668Schristos   DbeQueue *volatile last_queue;
574f645668Schristos   volatile int queues_cnt;
584f645668Schristos   volatile int total_queues;
594f645668Schristos };
604f645668Schristos 
614f645668Schristos #endif
62