void queue_wait_for(Queue *queue, int size, pthread_mutex_t * mutex, pthread_cond_t *cond) { assert(queue->size >= size); pthread_mutex_lock(mutex); while (1) { int next = queue->next_to_read; int i; int all_ok = TRUE; for (i = 0; i < size; ++i) { if (next == queue->next_to_write || !queue->ready[queue->next_to_read]) { all_ok = FALSE; break; } next = queue_get_next(queue, next); } if (all_ok) break; pthread_cond_wait(cond, mutex); } pthread_mutex_unlock(mutex); }
void *queue_push_start_already_locked(Queue *queue, pthread_mutex_t * mutex, pthread_cond_t *cond, int *to_write, QueueCheckFunc func, void *check_data, void *check_ret_data) { int next_next_to_write; while (1) { if (func == NULL) goto test; QueueCheckFuncRet check = func(queue, check_data, check_ret_data); if (check == QUEUE_CHECK_FUNC_RET_SKIP) return NULL; else if (check == QUEUE_CHECK_FUNC_RET_WAIT) goto wait; else if (check == QUEUE_CHECK_FUNC_RET_TEST) goto test; else assert(FALSE); test: next_next_to_write = queue_get_next(queue, queue->next_to_write); if (next_next_to_write != queue->next_to_read) { break; } wait: pthread_cond_wait(cond, mutex); } *to_write = queue->next_to_write; queue->ready[*to_write] = FALSE; queue->next_to_write = next_next_to_write; pthread_cond_broadcast(cond); end: return queue->tab[*to_write]; }
static void queue_free_list (queue_t *queue) { sp_track *track; while ((track = queue_get_next (queue))) sp_track_release (track); }
void queue_pop_finish_already_locked(Queue *queue, pthread_mutex_t * mutex, pthread_cond_t *cond) { assert(queue->in_read); queue->in_read = FALSE; queue->next_to_read = queue_get_next(queue, queue->next_to_read); pthread_cond_broadcast(cond); }
/************************************************ * Description: * * Arguments: * Return: * * Date: 2010-05-18 ************************************************/ static void load_queue_data() { struct data_entry * queue_data; if (queue_is_empty(&mac_send_queue)) return; // Get next data to send. queue_data = queue_get_next(&mac_send_queue); // Fill the MAC header. mac_fill_mhr(queue_data); // Ok, data available, try to send. // Change to tx mode mac_FSM_tx_mode(); }
void command_play(sp_session *session, const struct command * const command) { if(command->track < queue_get_len()) { queue_set_current(command->track); /* * If the track fails to play, we try to play the next song. * If no track is found within the maximum length of the queue, * give up. */ int cntr = 0; int track = command->track; while(!play(session, queue_get(track), 1)) { queue_del_track(track); ++cntr; if(cntr == PLAY_QUEUE_LEN) { sock_send_str(command->sockfd, "There doesn't seem to be any playable track in the queue.\n"); return; } track = queue_get_next(); } queue_set_current(track); char buf[API_MESSAGE_LEN]; track_to_str(buf, API_MESSAGE_LEN, queue_get(track)); sock_send_str(command->sockfd, "Playing: "); sock_send_str(command->sockfd, buf); sock_send_str(command->sockfd, "\n"); } else { sock_send_str(command->sockfd, "Track not in queue!\n"); } }
void command_next(sp_session *session, struct command * const command) { command->type = PLAY; command->track = queue_get_next(); command_play(session, command); }