All pastes #46568 Raw Edit

Stuff

public text v1 · immutable
#46568 ·published 2006-03-22 06:35 UTC
rendered paste body
JSBool chan_await(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
                  jsval * rval)
{
                struct jchan *jc = JS_GetPrivate(cx, obj);
                *rval = BOOLEAN_TO_JSVAL(JS_FALSE);

                int rc;
                int wait = 0;
                if ( jc->chanevents ) {
                        //pthread_mutex_lock(&jc->chanevents->mutex);
                        if ( argc > 0 ) {
                                if (  (JS_ValueToInt32(cx, argv[0], &wait) ) && wait && wait > 0) {
                                struct timespec abstime = { 0, 0 };
                                struct timeval curtime;

                                gettimeofday(&curtime, NULL);
                                abstime.tv_sec = curtime.tv_sec + wait; 

                                rc = ast_cond_timedwait(&jc->chanevents->cond, &jc->chanevents->mutex, &abstime);
                                if ( rc == 0 ) 
                                        *rval = BOOLEAN_TO_JSVAL(JS_TRUE);

                                } else {
                                        rc = ast_cond_wait(&jc->chanevents->cond, &jc->chanevents->mutex);
                                        if (rc == 0) {
                                                *rval = BOOLEAN_TO_JSVAL(JS_TRUE);
                                        }       else { 
                                                ast_verbose("ast_cond_wait return %d\n", rc);
                        return JS_FALSE;
                  }
                                }
                        }
                }
                return JS_TRUE;
}

void *pbx_aexec_helper(void *arg)
{
        struct fast_aexec *exec_data = arg;
//      struct ast_channel *chan = NULL;

//      pthread_mutex_lock(&exec_data->chanevents->mutex);

        pbx_exec(exec_data->chan, exec_data->appS, exec_data->data, 1);

        if (ast_cond_broadcast(&exec_data->chanevents->cond) != 0) {
                ast_verbose("Main failed to broadcast the condition\n");
        }

        ast_mutex_destroy(&exec_data->chanevents->mutex);
        ast_cond_destroy(&exec_data->chanevents->cond);

        if ( ast_check_hangup(exec_data->chan) == TRUE )
            ast_softhangup(exec_data->chan, AST_SOFTHANGUP_EXPLICIT);

//      ast_softhangup(exec_data->chan, AST_SOFTHANGUP_EXPLICIT);
//      ast_hangup(exec_data->chan);
        return NULL;
}