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

« back to all changes in this revision

Viewing changes to dclib/core/cmanager.cpp

  • 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
                           cmanager.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Thu Jan 23 2003
 
5
    copyright            : (C) 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
#ifdef HAVE_CONFIG_H
 
19
#include <config.h>
 
20
#endif
 
21
 
 
22
#ifndef WIN32
 
23
#include <sys/time.h>
 
24
#endif
 
25
#include <dclib/dcos.h>
 
26
#include <dclib/core/cdir.h>
 
27
#include <dclib/core/cplugin.h>
 
28
#include <dclib/core/platform.h>
 
29
 
 
30
#include "cmanager.h"
 
31
 
 
32
/** */
 
33
CManager::CManager()
 
34
{
 
35
        Start();
 
36
 
 
37
        SetInstance(this);
 
38
}
 
39
 
 
40
/** */
 
41
CManager::~CManager()
 
42
{
 
43
        Stop();
 
44
}
 
45
 
 
46
/** */
 
47
void CManager::Add( _CCallback * callback )
 
48
{
 
49
        if ( callback )
 
50
        {
 
51
                m_ThreadList.Lock();
 
52
                m_ThreadList.Add(callback);
 
53
                m_ThreadList.UnLock();
 
54
        }
 
55
}
 
56
 
 
57
/** */
 
58
void CManager::Remove( _CCallback * callback )
 
59
{
 
60
        if ( callback )
 
61
        {
 
62
                m_ThreadList.Lock();
 
63
                m_ThreadList.Remove(callback);
 
64
                m_ThreadList.UnLock();
 
65
        }
 
66
}
 
67
 
 
68
/** */
 
69
void CManager::Thread( CObject * )
 
70
{
 
71
        struct timeval tv_old, tv_new;
 
72
        _CCallback * callback = 0;
 
73
        ulonglong i;
 
74
 
 
75
        gettimeofday(&tv_old, NULL);
 
76
 
 
77
        while( TRUE )
 
78
        {
 
79
                m_ThreadList.Lock();
 
80
 
 
81
                callback = m_ThreadList.Next(callback);
 
82
 
 
83
                m_ThreadList.UnLock();
 
84
 
 
85
                if ( !callback )
 
86
                {
 
87
                        break;
 
88
                }
 
89
 
 
90
                callback->notify(0,0);
 
91
        }
 
92
 
 
93
        gettimeofday(&tv_new, NULL);
 
94
 
 
95
        if ( (tv_new.tv_sec - tv_old.tv_sec) > 0 )
 
96
        {
 
97
                i = 0;
 
98
        }
 
99
        else
 
100
        {
 
101
                i = (tv_new.tv_usec - tv_old.tv_usec);
 
102
 
 
103
                if ( i >= 5000 )
 
104
                {
 
105
                        i = 0;
 
106
                }
 
107
                else
 
108
                {
 
109
                        i = 10 - (i/1000);
 
110
                }
 
111
        }
 
112
 
 
113
        //malloc_stats();
 
114
 
 
115
        //printf("%d %d %d\n",i,tv_new.tv_sec - tv_old.tv_sec,(tv_new.tv_usec - tv_old.tv_usec)/1000);
 
116
 
 
117
        NanoSleep(i);
 
118
}