tzwrapper.cc: fixed use of iterator after erase
[barry.git] / src / threadwrap.h
blob838e37d4eccad63087b7fd39f0b912e5feac76df
1 ///
2 /// \file threadwrap.h
3 /// RAII Wrapper for a single thread.
4 ///
6 /*
7 Copyright (C) 2009, Nicolas VIVIEN
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_THREADWRAP_H__
23 #define __BARRY_THREADWRAP_H__
25 #include "dll.h"
26 #include <pthread.h>
28 namespace Barry {
30 class BXEXPORT Thread
32 public:
33 struct CallbackData
35 void *(*callback)(Barry::Thread::CallbackData *data);
37 // user-accessible data
38 volatile bool stopflag;
39 void *userdata;
41 explicit CallbackData(void *userdata);
44 private:
45 pthread_t thread;
46 int m_socket;
47 CallbackData *m_data;
49 public:
50 // Note: the data pointer passed into callback is not the same
51 // as userdata. The data pointer is a pointer to CallbackData
52 // which will contain the userdata pointer.
53 Thread(int socket,
54 void *(*callback)(Barry::Thread::CallbackData *data),
55 void *userdata);
56 ~Thread();
58 /// Sets stopflag in the callback data to true
59 void StopFlag();
62 } // namespace Barry
64 #endif