[asterisk-dev] sleeping in a module

Thomas Andrews tandrews at grok.co.za
Fri Aug 11 07:15:36 MST 2006


On Fri, Aug 11, 2006 at 08:54:08AM -0500, Kevin P. Fleming wrote:

> ----- Thomas Andrews <tandrews at grok.co.za> wrote:
> > I'm writing res_config_sqlite.c based on res_config_odbc.c and I
> > need to know what the correct call would be to sleep if my db is
> > busy for some reason. Should I call ast_safe_sleep() or what?
> 
> That would be the obvious answer, except that ast_safe_sleep()
> requires a channel pointer, and a res_config module isn't going to
> have one to pass in.

I realised that just after I'd sent the mail. I'm currently using
sched_yield()
 
> I think you need to find a different solution that doesn't require the
> res_config module to sleep at all... users of ast_realtime APIs are
> going to expect to get an immediate result, and if they don't then
> there could be really bizarre side effects.

Do you really think so? I would have thought that the socket on the odbc
interface would block if there was a lock on the db, so why can't I
block too?

The thing is, if the db is locked, you have no choice but to sleep or
give up. I'd have thought that giving up would be worse. Calling
sched_yield() as I am should allow other threads to run enough to unlock
the db..



More information about the asterisk-dev mailing list