bool PulseHandler::Init(void) { if (m_initialised) return m_valid; m_initialised = true; // Initialse our connection to the server m_loop = pa_mainloop_new(); if (!m_loop) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get PulseAudio mainloop"); return m_valid; } pa_mainloop_api *api = pa_mainloop_get_api(m_loop); if (!api) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get PulseAudio api"); return m_valid; } if (pa_signal_init(api) != 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to initialise signaling"); return m_valid; } const char *client = "mythtv"; m_ctx = pa_context_new(api, client); if (!m_ctx) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create context"); return m_valid; } // remember which thread created this object for later sanity debugging m_thread = QThread::currentThread(); // we set the callback, connect and then run the main loop 'by hand' // until we've successfully connected (or not) pa_context_set_state_callback(m_ctx, StatusCallback, this); pa_context_connect(m_ctx, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL); int ret = 0; int tries = 0; while ((tries++ < 100) && !IS_READY(m_ctx_state)) { pa_mainloop_iterate(m_loop, 0, &ret); usleep(10000); } if (PA_CONTEXT_READY != m_ctx_state) { LOG(VB_GENERAL, LOG_ERR, LOC + "Context not ready after 1000ms"); return m_valid; } LOG(VB_AUDIO, LOG_INFO, LOC + "Initialised handler"); m_valid = true; return m_valid; }
/* * EV send async trigger for new commands to send * (External to the event loop) */ static inline void _eredis_ev_send_trigger (eredis_t *e) { if (IS_READY(e) && !IS_SHUTDOWN(e) && !e->send_async_pending) { e->send_async_pending = 1; ev_async_send( e->loop, &e->send_async ); } }
void entry(void) { char *p = "Hello, world!\n"; volatile long *data_reg = (long *)(IOBASE+DISPLAY_1_DATA); volatile long *control_reg = (long *)(IOBASE+DISPLAY_1_CONTROL); while (*p != '\0') { do { 0; } while (! IS_READY(control_reg)); *data_reg = (long) *p++; } }
int fc_dl_sl_find(void *s){ fc_dl_skiplist_t *p = (fc_dl_skiplist_t *)s; pub_record *rec; __u64 candidate_dline = 0; __u64 data_struct_dline = 0; int candidate_cpu = -1; int data_struct_cpu = -1; /* previsione migliore cpu dalla scansione lista */ rec = p->p_list->head; /* lettura atomica (vedi old_dl_sl_find) */ while(rec){ /* il combiner thread potrebbe, nel frattempo, apportare le modifiche */ if(!IS_READY(rec)) switch(rec->req){ case PREEMPT: if(candidate_cpu == -1 || p->cmp_dl(rec->par.preempt_p.dline, candidate_dline)){ candidate_cpu = rec->par.preempt_p.cpu; candidate_dline = rec->par.preempt_p.dline; } break; } rec = rec->next; } /* lettura migliore cpu dalla struttura dati */ data_struct_cpu = old_fc_dl_sl_find(s); if(data_struct_cpu >= 0) data_struct_dline = p->list->rq_to_node[data_struct_cpu]->dline; /* confronto */ if(candidate_dline > 0 && data_struct_dline > 0) return p->cmp_dl(candidate_dline, data_struct_dline) ? candidate_cpu : data_struct_cpu; if(candidate_dline > 0) return candidate_cpu; else return data_struct_cpu; }
void console_tick(void) { int ch = 0; if(read_char(&ch) == 0) { int n; char help[] = "help:\r\n" " 0-F : select block to read disk data from\r\n" " i : insert disk\r\n" " r : remove disk\r\n" " f : flip disk to next side/disk\r\n" " p : print disks stored in flash\r\n" " d : disk read mode\r\n" " t : transfer mode\r\n" "\r\n"; switch((char)ch) { case '?': printf("%s",help); printf("currently selected disk in block is %d.\r\n\r\n",diskblock); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if(ch >= 'A' && ch <= 'F') { diskblock = 10 + (ch - 'A'); } else { diskblock = ch - '0'; } printf("selected disk in block %X.\r\n",diskblock); break; case 'i': fds_insert_disk(diskblock); break; case 'r': fds_remove_disk(); break; case 'p': for(n=0;n<0x10;n++) { print_block_info(n); } break; case 's': flash_init(); sram_init(); break; case 'd': fds_setup_diskread(); break; case 't': fds_setup_transfer(); if(IS_READY()) printf("drive is ready\n"); else printf("drive is not ready\n"); if(IS_MEDIASET()) printf("media is set\n"); else printf("media is not set\n"); if(IS_WRITABLE()) printf("media is writable\n"); else printf("media is not writable\n"); if(IS_MOTORON()) printf("motor is on\n"); else printf("motor is not on\n"); break; case 'c': sram_read(3537,crap,256); hexdump("crap",crap,256); break; case 'v': printf("stopping read\n"); CLEAR_WRITE(); CLEAR_SCANMEDIA(); SET_STOPMOTOR(); break; case 'I': printf("ident: '%s'\n",ident.ident); break; } } }
/* * EV connect callback * * EV_TIMER connect_timer */ static void _eredis_ev_connect_cb (struct ev_loop *loop, ev_timer *w, int revents) { int i; eredis_t *e; (void) revents; (void) loop; e = (eredis_t*) w->data; if (IS_SHUTDOWN(e)) { if (e->hosts_connected) { for (i=0; i<e->hosts_nb; i++) { host_t *h = &e->hosts[i]; if (H_IS_CONNECTED(h) && h->async_ctx) redisAsyncDisconnect( h->async_ctx ); } } else { /* Connect timer */ ev_timer_stop( e->loop, &e->connect_timer ); /* Async send */ ev_async_stop( e->loop, &e->send_async ); /* Event break */ ev_break( e->loop, EVBREAK_ALL ); } return; } for (i=0; i<e->hosts_nb; i++) { host_t *h = &e->hosts[i]; switch (H_CONN_STATE( h )) { case HOST_F_CONNECTED: break; case HOST_F_FAILED: if ((h->failures < HOST_FAILED_RETRY_AFTER) || ( ! _host_connect( h, 0 ))) { h->failures %= HOST_FAILED_RETRY_AFTER; h->failures ++; } break; case HOST_F_DISCONNECTED: if (! _host_connect( h, 0 )) { if ((++ h->failures) > HOST_DISCONNECTED_RETRIES) { h->failures = 0; H_SET_FAILED( h ); } } break; default: break; } } if (! IS_READY(e)) { /* Ready flag - need a connected host or a connection failure */ int nb = 0; /* build ready flag */ for (i=0; i<e->hosts_nb; i++) { host_t *h = &e->hosts[i]; if (H_IS_INIT( h )) nb ++; } if (nb == e->hosts_nb) { SET_READY(e); e->send_async_pending = 1; ev_async_send( e->loop, &e->send_async ); } } }