1 /* 2 * HT Editor 3 * htidle.cc 4 * 5 * Copyright (C) 1999-2002 Stefan Weyergraf 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #include "data.h" 22 #include "htdebug.h" 23 #include "htidle.h" 24 #include "keyb.h" 25 #include "sys.h" 26 27 static List *idle_objs; 28 register_idle_object(Object * o)29void register_idle_object(Object *o) 30 { 31 idle_objs->insert(o); 32 } 33 unregister_idle_object(Object * o)34void unregister_idle_object(Object *o) 35 { 36 int c = idle_objs->count(); 37 for (int i=0; i < c; i++) if ((*idle_objs)[i] == o) { 38 idle_objs->remove(idle_objs->findByIdx(i)); 39 } 40 } 41 do_idle()42void do_idle() 43 { 44 static int cur_idle = 0; 45 static bool any_idles = 0; 46 int c = idle_objs->count(); 47 if (c) { 48 if (cur_idle >= c) { 49 cur_idle = 0; 50 if (!any_idles) sys_suspend(); 51 any_idles = 0; 52 } 53 Object *i = (*idle_objs)[cur_idle]; 54 assert(i); 55 any_idles |= i->idle(); 56 cur_idle++; 57 } else { 58 sys_suspend(); 59 } 60 } 61 62 /* 63 * INIT 64 */ 65 init_idle()66bool init_idle() 67 { 68 idle_objs = new Array(false); 69 return true; 70 } 71 72 /* 73 * DONE 74 */ 75 done_idle()76void done_idle() 77 { 78 delete idle_objs; 79 } 80