static void timeout_toggled(DBusTimeout *timeout, void *data) { if (dbus_timeout_get_enabled(timeout)) add_timeout(timeout, data); else remove_timeout(timeout, data); }
/*! * \brief Insert a new entry on the hashtable * \param callid Call-ID string */ static void insert(str callid) { unsigned int index = hash(callid.s, callid.len) & HASHTABLEMASK; struct ring_record_t* rr; remove_timeout(index); rr = shm_malloc(sizeof(struct ring_record_t)); assert(rr); rr->next = NULL; rr->time = get_ticks(); strncpy(rr->callid, callid.s, MIN(callid.len, MAXCALLIDLEN)); rr->callid[MIN(callid.len, MAXCALLIDLEN)] = 0; if ((*hashtable)[index].tail) { (*hashtable)[index].tail->next = rr; (*hashtable)[index].tail = rr; } else { (*hashtable)[index].head = rr; (*hashtable)[index].tail = rr; } LM_DBG("inserting at %d %.*s ticks=%d\n", index, callid.len, callid.s, rr->time); }
/*! \brief Mailbox flush function * * Flush a mailbox and unblock all pending tasks that were waiting for free message containers. \e SYS_ERROR * is passed to the task. * \param ph handle to mailbox */ void MBX_Flush(HANDLE *ph) { tcb_t *ptcb; mcb_t *pmcb; msg_t *pmsg_entry; size_t flags; pmcb = (mcb_t*) ph; flags = INT_Disable(); /* Empty all containers in the FullList. If there is a task waiting for an empty container give the dequeued * container to it. If not put the container in the free list. */ while( (pmsg_entry = (msg_t*) dequeue_top_object( (queue_t*) &pmcb->full_list)) ) { if( (ptcb = (tcb_t*) dequeue_top_object( (queue_t*) &pmcb->fullq)) ) { ptcb->flags = TSK_READY; ptcb->event = SYS_ERROR; ptcb->pmsg_entry = pmsg_entry; remove_timeout( &ptcb->tic ); priority_enqueue_tsk( ptcb ); } else enqueue_bottom_object( (queue_t*) &pmcb->free_list, (dll_t*) pmsg_entry ); } INT_Restore( flags ); }
/*! \brief Mailbox post function * * A mailbox can be post from an interrupt ISR or from a task. When posted from a task a timeout value can be * specified. \n * If a mailbox has a empty message container the message is stored in the mailbox and the system call returns * with SYS_OK. When there is no empty message containers the task is pending and SYS_ERROR is returned. If the caller * specifed a timeout value a timer is started and the task is delayed from execution. After the timeout expires * (no task freed a message container) the task is unblocked and \e SYS_MBX_TOUT is passed to the task's entry * parameter. If a task freed a message container the \e SYS_MBX value is passed to the task. * \param ph handle to mailbox * \param pmsg pointer caller to message * \param tout timeout value * \retval SYS_OK if there was a free message container * \retval SYS_ERR if all message containers are full */ STATUS MBX_Post(HANDLE *ph, void *pmsg, uint16 tout) { tcb_t *ptcb; mcb_t *pmcb; msg_t *pmsg_entry; size_t flags; ptcb = get_curr_tsk(); pmcb = (mcb_t*) ph; flags = INT_Disable(); /* Check if the task was given an entry by the MBX_Pend function. If it was take this entry and not the one * in the free_list. This is needed beacause a MBX_Pend caused a free container in the free_list. As soon this container * become avaible we must give it to the first waiting task. Otherwise we could dequeue a task, make it runable, but an other task * could take its container. So this would be an invalid situation. */ if( !ptcb->pmsg_entry ) { /* Wait for a message entry to become free*/ if( !(pmsg_entry = (msg_t*) dequeue_top_object( (queue_t*) &pmcb->free_list)) ) { if( tout == NO_WAIT ) { INT_Restore( flags ); return SYS_ERROR; } ptcb->pqueue = (queue_t*) &pmcb->fullq; ptcb->flags = TSK_MBX_PEND; enqueue_top_object(&pmcb->fullq, (dll_t*) ptcb); append_timeout(ptcb, &mbx_tout_clb, tout); INT_Restore( flags ); return SYS_ERROR; } } else { /* If the task was given an msg entry operate on that entry. */ pmsg_entry = ptcb->pmsg_entry; ptcb->pmsg_entry = 0; } /* Copy the message data into the container */ memcpy( pmsg_entry->pdata, pmsg, pmcb->len); /* Move the message container to the full list. */ enqueue_bottom_object( &pmcb->full_list, (dll_t*) pmsg_entry ); /* Check if there was a task waiting for a message. If it was remove its timeout timer.*/ if( (ptcb = (tcb_t*) dequeue_top_object( (queue_t*) &pmcb->emptyq)) ) { ptcb->flags = TSK_READY; ptcb->event = SYS_MBX; priority_enqueue_tsk( ptcb ); remove_timeout( &ptcb->tic ); } INT_Restore( flags ); return SYS_OK; }
static void timeout_toggled (DBusTimeout *timeout, void *data) { /* Because we just exit on OOM, enable/disable is * no different from add/remove */ if (dbus_timeout_get_enabled (timeout)) add_timeout (timeout, data); else remove_timeout (timeout, data); }
/*! * \brief Helper functions that checks if the hash table contains the callid * \param callid Call-ID that is searched * \return 1 when callid could be found, 0 when not found */ static int contains(str callid) { unsigned int index = hash(callid.s, callid.len) & HASHTABLEMASK; struct ring_record_t* rr; remove_timeout(index); rr = (*hashtable)[index].head; while (rr) { if (strncmp(rr->callid, callid.s, callid.len) == 0) return 1; rr = rr->next; } return 0; }
static void remove_timeout(DBusTimeout *t, void *data) { printf(" TIMEOUT: remove timeout %p\n", t); watched_timeout = NULL; struct timeval tv = { .tv_sec = 0, .tv_usec = 0, }; watched_timeout_start_tv = tv; watched_timeout_setv = 0; watched_timeout_lastv = 0; } static void toggle_timeout(DBusTimeout *t, void *data) { printf(" TIMEOUT: toggle timeout %p\n", t); if (dbus_timeout_get_enabled(t)) add_timeout(t, data); else remove_timeout(t, data); }
/*! \brief Mailbox pend function * * Only tasks can pend on mailboxes. If a mailbox is not empty the message is returned to the caller and the system call * returns with SYS_OK. When there is no message the task is pending and SYS_ERROR is returned. If the caller * specifed a timeout value a timer is started and the task is delayed from execution. After the timeout expires * (no task or interrupt posted a message) the task is unblocked and \e SYS_MBX_TOUT is passed to the task's entry * parameter. If somebody posted a message the timer is removed and the \e SYS_MBX values is passed to the task. * \param ph handle to mailbox * \param pmsg pointer caller where the message will be copied * \param tout timeout value * \retval SYS_OK if there was a message in mailbox * \retval SYS_ERR if there was no messages in mailbox * \attention MBX_pend can not be called from an ISR. */ STATUS MBX_Pend(HANDLE *ph, void *pmsg, uint16 tout) { tcb_t *ptcb; mcb_t *pmcb; msg_t *pmsg_entry; size_t flags; ptcb = get_curr_tsk(); pmcb = (mcb_t*) ph; flags = INT_Disable(); /* Check if there is a message already in the mailbox */ if( !(pmsg_entry = (msg_t*) dequeue_top_object( (queue_t*) &pmcb->full_list)) ) { if( tout == NO_WAIT ) { INT_Restore( flags ); return SYS_ERROR; } ptcb->pqueue = (queue_t*) &pmcb->emptyq; ptcb->flags = TSK_MBX_PEND; enqueue_top_object(&pmcb->emptyq, (dll_t*) ptcb); append_timeout(ptcb, &mbx_tout_clb, tout); INT_Restore( flags ); return SYS_ERROR; } /* Copy message to task */ memcpy( pmsg, pmsg_entry->pdata, pmcb->len ); /* Check if there was a task waiting for an empty entry in the mailbox */ if( (ptcb = (tcb_t*) dequeue_top_object( (queue_t*) &pmcb->fullq)) ) { ptcb->flags = TSK_READY; ptcb->event = SYS_MBX; ptcb->pmsg_entry = pmsg_entry; priority_enqueue_tsk( ptcb ); remove_timeout( &ptcb->tic ); } else { enqueue_bottom_object( (queue_t*) &pmcb->free_list, (dll_t*) pmsg_entry ); } INT_Restore( flags ); return SYS_OK; }
void stop (void) { MafwRenderer *renderer; MafwPlayState state; renderer = get_selected_renderer(); if (renderer == NULL) return; state = get_selected_renderer_state (); if (state != Stopped) { remove_timeout(); mafw_renderer_stop(renderer, play_error_cb, NULL); } else { g_warning ("Tried to Stop when renderer state " "is already Stopped. Skipped."); } }
void prepare_controls_for_state (MafwPlayState state) { gboolean play_possible; gboolean pause_possible; gboolean stop_possible; switch (state) { case Stopped: /* Disable the seekbar when the state is stopped */ gtk_widget_set_sensitive(position_hscale, FALSE); play_possible = TRUE; pause_possible = FALSE; stop_possible = TRUE; in_state_stopped = TRUE; remove_timeout (); g_signal_handlers_block_by_func (G_OBJECT(position_hscale), on_position_hscale_value_changed, NULL); gtk_range_set_value (GTK_RANGE (position_hscale), 0.0); gtk_label_set_text(GTK_LABEL(position_label), "00:00"); g_signal_handlers_unblock_by_func(G_OBJECT(position_hscale), on_position_hscale_value_changed, NULL); break; case Paused: play_possible = TRUE; pause_possible = FALSE; stop_possible = TRUE; in_state_stopped = FALSE; remove_timeout (); update_position (NULL); break; case Playing: play_possible = FALSE; pause_possible = TRUE; stop_possible = TRUE; in_state_stopped = FALSE; /* Start tracking media position in playing state */ add_timeout (); break; case Transitioning: play_possible = FALSE; pause_possible = FALSE; stop_possible = TRUE; in_state_stopped = FALSE; remove_timeout (); break; default: play_possible = TRUE; pause_possible = FALSE; stop_possible = TRUE; in_state_stopped = FALSE; remove_timeout (); break; } if (!stop_possible) { g_signal_handlers_block_by_func (position_hscale, on_position_hscale_value_changed, NULL); gtk_range_set_value (GTK_RANGE (position_hscale), 0.0); gtk_label_set_text(GTK_LABEL(position_label), "00:00"); g_signal_handlers_unblock_by_func (position_hscale, on_position_hscale_value_changed, NULL); } if (play_possible == TRUE) { GtkWidget *image; image = gtk_image_new_from_icon_name("camera_playback", HILDON_ICON_SIZE_SMALL); gtk_button_set_image(GTK_BUTTON(play_button), image); } if (pause_possible == TRUE) { GtkWidget *image; image = gtk_image_new_from_icon_name("camera_video_pause", HILDON_ICON_SIZE_SMALL); gtk_button_set_image(GTK_BUTTON(play_button), image); } if (play_possible == FALSE && pause_possible == FALSE) { gtk_widget_set_sensitive (play_button, FALSE); } else { gtk_widget_set_sensitive (play_button, TRUE); } gtk_widget_set_sensitive (stop_button, stop_possible); }