<commit_before>/*  $Id$

    Part of XPCE
    Designed and implemented by <NAME> and <NAME>
    E-mail: <EMAIL>

    Copyright (C) 1994 University of Amsterdam. All rights reserved.
*/

#include "include.h"

static HashTable TimerTable;

static UINT
getIdTimer(Timer tm)
{ return (UINT) tm->ws_ref;
}


static void
setIdTimer(Timer tm, UINT id)
{ DEBUG(NAME_timer, Cprintf("setIdTimer(%s, %d)\n", pp(tm), id));
  tm->ws_ref = (WsRef) id;
}


VOID CALLBACK
timer_proc(HWND hwnd, UINT msg, UINT id, DWORD now)
{ DEBUG(NAME_timer, Cprintf("Fireing timer %d\n", id));

  if ( TimerTable )
  { Timer tm;

    if ( (tm = getMemberHashTable(TimerTable, toInt(id))) )
    { executeTimer(tm);
      RedrawDisplayManager(TheDisplayManager());

      if ( tm->status != NAME_repeat )
      { KillTimer(NULL, id);
	deleteHashTable(TimerTable, toInt(id));
	assign(tm, status, NAME_idle);
      }

      return;
    }
  }

  KillTimer(NULL, id);			/* Unexpected timer.  Get rid of it */
}


void
ws_status_timer(Timer tm, Name status)
{ UINT id;

  if ( (id = getIdTimer(tm)) )
  { KillTimer(NULL, id);
    deleteHashTable(TimerTable, toInt(id));
    setIdTimer(tm, 0);
  }

  if ( status != NAME_idle )
  { long msec = (long) (valReal(tm->interval) * 1000.0);
    
    if ( (id = SetTimer(NULL, 0, (UINT)msec, (TIMERPROC) timer_proc)) )
    { if ( !TimerTable )
      { TimerTable = globalObject(CtoName("active_timers"),
				  ClassHashTable, 0);
	assign(TimerTable, refer, NAME_none);
      }<commit_msg>* Fixed scheduling of deletion<commit_after>/*  $Id$

    Part of XPCE
    Designed and implemented by <NAME> and <NAME>
    E-mail: <EMAIL>

    Copyright (C) 1994 University of Amsterdam. All rights reserved.
*/

#include "include.h"

static HashTable TimerTable;

static UINT
getIdTimer(Timer tm)
{ return (UINT) tm->ws_ref;
}


static void
setIdTimer(Timer tm, UINT id)
{ DEBUG(NAME_timer, Cprintf("setIdTimer(%s, %d)\n", pp(tm), id));
  tm->ws_ref = (WsRef) id;
}


VOID CALLBACK
timer_proc(HWND hwnd, UINT msg, UINT id, DWORD now)
{ DEBUG(NAME_timer, Cprintf("Fireing timer %d\n", id));

  if ( TimerTable )
  { Timer tm;

    if ( (tm = getMemberHashTable(TimerTable, toInt(id))) )
    { if ( tm->status != NAME_repeat )
      { KillTimer(NULL, id);
	deleteHashTable(TimerTable, toInt(id));
	assign(tm, status, NAME_idle);
      }

      executeTimer(tm);

      RedrawDisplayManager(TheDisplayManager());

      return;
    }
  }

  KillTimer(NULL, id);			/* Unexpected timer.  Get rid of it */
}


void
ws_status_timer(Timer tm, Name status)
{ UINT id;

  if ( (id = getIdTimer(tm)) )
  { KillTimer(NULL, id);
    deleteHashTable(TimerTable, toInt(id));
    setIdTimer(tm, 0);
  }

  if ( status != NAME_idle )
  { long msec = (long) (valReal(tm->interval) * 1000.0);
    
    if ( (id = SetTimer(NULL, 0, (UINT)msec, (TIMERPROC) timer_proc)) )
    { if ( !TimerTable )
      { TimerTable = globalObject(CtoName("active_timers"),
				  ClassHashTable, 0);
	assign(TimerTable, refer, NAME_none);
      }
{'fraction_non_alphanumeric': 0.14680426098535287, 'fraction_numerical': 0.007989347536617843, 'mean_word_length': 3.445266272189349, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2112786', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1089, 'n_words': 270}