~ubuntu-branches/debian/sid/libdc0/sid

« back to all changes in this revision

Viewing changes to dclib/core/cthread.h

  • Committer: Bazaar Package Importer
  • Author(s): Pasi Savilaakso
  • Date: 2004-06-05 23:01:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040605230137-2ty5g6rcfyguk4et
Tags: upstream-0.3.2
Import upstream version 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          cthread.h  -  description
 
3
                             -------------------
 
4
    begin                : Sun Sep 30 2001
 
5
    copyright            : (C) 2001-2003 by Mathias K�ster
 
6
    email                : mathen@users.berlios.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#ifndef CTHREAD_H
 
19
#define CTHREAD_H
 
20
 
 
21
/**
 
22
  *@author Mathias K�ster
 
23
  */
 
24
 
 
25
#include <pthread.h>
 
26
 
 
27
#include <dclib/dcos.h>
 
28
#include <dclib/core/cobject.h>
 
29
 
 
30
class _CCallback;
 
31
 
 
32
class DLL_EXPORT CMutex {
 
33
public:
 
34
        /** */
 
35
        CMutex();
 
36
        /** */
 
37
        virtual ~CMutex();
 
38
 
 
39
        /** */
 
40
        int Lock();
 
41
        /** */
 
42
        bool TryLock();
 
43
        /** */
 
44
        int UnLock();
 
45
 
 
46
private:
 
47
        /** */
 
48
        pthread_mutex_t mutex;
 
49
};
 
50
 
 
51
class DLL_EXPORT CThread : public CMutex {
 
52
public:
 
53
        /** */
 
54
        CThread();
 
55
        /** */
 
56
        virtual ~CThread();
 
57
 
 
58
        /** */
 
59
        int Start();
 
60
        /** */
 
61
        int Stop( bool bHard = TRUE );
 
62
        /** */
 
63
        bool Stopped() const;
 
64
 
 
65
        /** */
 
66
        void NanoSleep( unsigned int );
 
67
        /** */
 
68
        void SetThreadCallBackFunction( _CCallback * callback );
 
69
 
 
70
        /** */
 
71
        virtual void Thread(CObject *) {};
 
72
 
 
73
 
 
74
protected:
 
75
        /** */
 
76
        int iRun;
 
77
 
 
78
private:
 
79
        /** callback function */
 
80
        _CCallback * _thread_callback_function;
 
81
        /** */
 
82
        pthread_t thread;
 
83
        /** */
 
84
        int iStop;
 
85
        /** */
 
86
        static void * MainThread(void *object);
 
87
};
 
88
 
 
89
/** */
 
90
inline bool CThread::Stopped() const
 
91
{ return (iStop==1); }
 
92
 
 
93
#endif