int pthread_mutex_lock(pthread_mutex_t *mutex) { static void *handle = NULL; if (!handle) { fout = fopen("report", "w"); //fprintf(fout, "No DeadLock detected!\n"); handle = dlopen("libc.so.6", RTLD_LAZY); old_mutex_lock = (MUTEX_LOCK)dlsym(handle, "pthread_mutex_lock"); old_mutex_unlock = (MUTEX_LOCK)dlsym(handle, "pthread_mutex_unlock"); detector_init(); } old_mutex_lock(&hook_mutex); if (!detector_mutex_free(mutex)) { detector_wait(pthread_self(), mutex); DEBUG("wait"); old_mutex_unlock(&hook_mutex); return old_mutex_lock(mutex); } else { detector_hold(pthread_self(), mutex); DEBUG("get lock\n"); old_mutex_unlock(&hook_mutex); return old_mutex_lock(mutex); } }
/******************************************************************************* * @brief initialize detector * @author zhanggaoxin * @date 2013-03-20 * @param [in]mode: * @return T_BOOL * @retval success or fail *******************************************************************************/ T_BOOL Fwl_DetectorInit(T_U8 mode) { T_BOOL ret = AK_FALSE; detector_init(); if ((DEVICE_USB & mode) || (DEVICE_CHG & mode)) { detector_register_gpio(DEVICE_USB, GPIO_USB_DET, LEVEL_HIGH, AK_TRUE, 0); detector_set_callback(DEVICE_USB, AK_NULL); ret = AK_TRUE; } #ifdef OS_ANYKA #ifdef SUPPORT_SDCARD if (DEVICE_SD & mode) { detector_register_gpio(DEVICE_SD, GPIO_SD_DET, LEVEL_LOW, AK_TRUE, 0); detector_set_callback(DEVICE_SD, AK_NULL); gpio_set_pullup_pulldown(GPIO_SD_DET, 1); ret = AK_TRUE; } #endif #endif if (DEVICE_HP & mode) { detector_register_gpio(DEVICE_HP, GPIO_HP_DET, LEVEL_LOW, AK_TRUE, 0); detector_set_callback(DEVICE_HP, AK_NULL); gpio_set_pullup_pulldown(GPIO_HP_DET, AK_TRUE); ret = AK_TRUE; } #if SUPPORT_LINEIN_SPK if (DEVICE_LINEIN & mode) { detector_register_gpio(DEVICE_LINEIN, GPIO_LINEIN_DET, LEVEL_LOW, AK_TRUE, 0); detector_set_callback(DEVICE_LINEIN, AK_NULL); Fwl_DetectorEnable(DEVICE_LINEIN, AK_TRUE); gpio_set_pullup_pulldown(GPIO_LINEIN_DET, AK_TRUE); ret = AK_TRUE; } #endif #ifdef SUPPORT_USBHOST if (DEVICE_UHOST & mode) { Fwl_UsbHostDetectEnable(AK_TRUE); ret = AK_TRUE; } #endif return ret; }
static void *dialer_create(struct modem *m) { struct dialer_struct *s; unsigned int wait_before_dial; s = malloc(sizeof(*s)); if (!s) return NULL; memset(s, 0, sizeof(*s)); s->d_ptr = m->dial_string; s->state = STATE_WAIT; wait_before_dial = m->sregs[6] > 0 ? m->sregs[6] : 2; detector_init(&s->detector, samples_in_sec(wait_before_dial)); dtmfgen_init(&s->dtmfgen, m->dial_string); return s; }
static int dialer_process(struct modem *m, int16_t * in, int16_t * out, unsigned int count) { struct dialer_struct *s = (struct dialer_struct *)m->datapump.dp; enum dialer_states new_state; const char *p; int ret = 0; switch (s->state) { case STATE_WAIT: ret = detector_process(&s->detector, in, count); memset(out, 0, ret * sizeof(int16_t)); break; case STATE_DIAL: ret = dtmfgen_process(&s->dtmfgen, out, count); break; default: return -1; } if (ret == count) return count; if (ret < 0) return ret; memset(out + ret, 0, (count - ret) * sizeof(int16_t)); if (s->state == STATE_DIAL) p = s->d_ptr = s->dtmfgen.p; else p = s->d_ptr++; if (*p == '\0') { dbg("dialer finished\n"); m->next_dp_id = DP_DETECTOR; new_state = STATE_FINISHED; } else if (tolower(*p) == 'w' || *p == ',') { unsigned int pause_time = m->sregs[8] > 0 ? m->sregs[8] : 2; new_state = STATE_WAIT; detector_init(&s->detector, samples_in_sec(pause_time)); } else { new_state = STATE_DIAL; dtmfgen_init(&s->dtmfgen, p); } dbg("dialer state: %s -> %s\n", STATE_NAME(s->state), STATE_NAME(new_state)); s->state = new_state; return count; }