1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

return value wasn't a good idea after all - added Irssi::timeout_add_once()

instead.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2758 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2002-05-07 23:40:21 +00:00 committed by cras
parent 0d76b65381
commit c1384d919b
2 changed files with 25 additions and 10 deletions

View File

@ -193,7 +193,22 @@ CODE:
croak("Irssi::timeout() : msecs must be >= 10"); croak("Irssi::timeout() : msecs must be >= 10");
RETVAL = -1; RETVAL = -1;
} else { } else {
RETVAL = perl_timeout_add(msecs, func, data); RETVAL = perl_timeout_add(msecs, func, data, FALSE);
}
OUTPUT:
RETVAL
int
timeout_add_once(msecs, func, data)
int msecs
SV *func
SV *data
CODE:
if (msecs < 10) {
croak("Irssi::timeout_once() : msecs must be >= 10");
RETVAL = -1;
} else {
RETVAL = perl_timeout_add(msecs, func, data, TRUE);
} }
OUTPUT: OUTPUT:
RETVAL RETVAL

View File

@ -29,6 +29,7 @@ typedef struct {
PERL_SCRIPT_REC *script; PERL_SCRIPT_REC *script;
int tag; int tag;
int refcount; int refcount;
int once; /* run only once */
SV *func; SV *func;
SV *data; SV *data;
@ -41,14 +42,15 @@ static void perl_source_ref(PERL_SOURCE_REC *rec)
rec->refcount++; rec->refcount++;
} }
static void perl_source_unref(PERL_SOURCE_REC *rec) static int perl_source_unref(PERL_SOURCE_REC *rec)
{ {
if (--rec->refcount != 0) if (--rec->refcount != 0)
return; return TRUE;
SvREFCNT_dec(rec->data); SvREFCNT_dec(rec->data);
SvREFCNT_dec(rec->func); SvREFCNT_dec(rec->func);
g_free(rec); g_free(rec);
return FALSE;
} }
static void perl_source_destroy(PERL_SOURCE_REC *rec) static void perl_source_destroy(PERL_SOURCE_REC *rec)
@ -81,12 +83,10 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
char *error = g_strdup(SvPV(ERRSV, PL_na)); char *error = g_strdup(SvPV(ERRSV, PL_na));
signal_emit("script error", 2, rec->script, error); signal_emit("script error", 2, rec->script, error);
g_free(error); g_free(error);
} else if (retcount > 0 && POPi != 0) {
/* stopped */
perl_source_destroy(rec);
} }
perl_source_unref(rec); if (perl_source_unref(rec) && rec->once)
perl_source_destroy(rec);
PUTBACK; PUTBACK;
FREETMPS; FREETMPS;
@ -95,7 +95,7 @@ static int perl_source_event(PERL_SOURCE_REC *rec)
return 1; return 1;
} }
int perl_timeout_add(int msecs, SV *func, SV *data) int perl_timeout_add(int msecs, SV *func, SV *data, int once)
{ {
PERL_SCRIPT_REC *script; PERL_SCRIPT_REC *script;
PERL_SOURCE_REC *rec; PERL_SOURCE_REC *rec;
@ -117,7 +117,7 @@ int perl_timeout_add(int msecs, SV *func, SV *data)
return rec->tag; return rec->tag;
} }
int perl_input_add(int source, int condition, SV *func, SV *data) int perl_input_add(int source, int condition, SV *func, SV *data, int once)
{ {
PERL_SCRIPT_REC *script; PERL_SCRIPT_REC *script;
PERL_SOURCE_REC *rec; PERL_SOURCE_REC *rec;