File: htidle.cc

package info (click to toggle)
ht 2.1.0%2Brepack1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,852 kB
  • sloc: cpp: 88,922; ansic: 12,693; sh: 4,083; lex: 226; makefile: 185; yacc: 128
file content (79 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 *	HT Editor
 *	htidle.cc
 *
 *	Copyright (C) 1999-2002 Stefan Weyergraf
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "data.h"
#include "htdebug.h"
#include "htidle.h"
#include "keyb.h"
#include "sys.h"

static List *idle_objs;

void register_idle_object(Object *o)
{
	idle_objs->insert(o);
}

void unregister_idle_object(Object *o)
{
	int c = idle_objs->count();
	for (int i=0; i < c; i++) if ((*idle_objs)[i] == o) {
		idle_objs->remove(idle_objs->findByIdx(i));
	}
}

void do_idle()
{
	static int cur_idle = 0;
	static bool any_idles = 0;
	int c = idle_objs->count();
	if (c) {
		if (cur_idle >= c) {
			cur_idle = 0;
			if (!any_idles) sys_suspend();
			any_idles = 0;
		}
		Object *i = (*idle_objs)[cur_idle];
		assert(i);
		any_idles |= i->idle();
		cur_idle++;
	} else {
		sys_suspend();
	}
}

/*
 *	INIT
 */

bool init_idle()
{
	idle_objs = new Array(false);
	return true;
}

/*
 *	DONE
 */

void done_idle()
{
	delete idle_objs;
}