static uint32_t index_from_float(float f);
static float float_from_index(uint32_t d);
static float *acos_table = NULL;
-static int acos_fd = -1;
#ifdef FAST_ACOSF_TESTING
acos_table_file = fopen(ACOS_TABLE_FILENAME, "w");
+ if (!acos_table_file) {
+ return -3;
+ }
+
for (i = 0; i < ACOS_TABLE_LENGTH; i++) {
f = acosf(float_from_index(i));
res = fwrite(&f, sizeof(f), 1, acos_table_file);
if (res != 0) {
return -2;
}
+
return 0;
fail:
fclose(acos_table_file);
+
return -1;
}
* or some other error occured */
errsv = errno;
strerror_r(errsv, err, 150);
- if (errsv != ENOENT) return -1;
- else {
+ if (errsv != ENOENT) {
+ return -1;
+ } else {
switch_log_printf(
SWITCH_CHANNEL_LOG,
SWITCH_LOG_NOTICE,
acos_fp = fopen(ACOS_TABLE_FILENAME, "r");
if (acos_fp == NULL) return -3;
/* can't fail */
- acos_fd = fileno(acos_fp);
acos_table = (float *) mmap(
NULL, /* kernel chooses the address at which to create the mapping */
- ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, acos_fd, 0);
+ ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, fileno(acos_fp), 0);
+ fclose(acos_fp);
if (acos_table == MAP_FAILED) return -4;
return 0;
extern int destroy_fast_acosf(void)
{
if (munmap(acos_table, ACOS_TABLE_LENGTH) == -1) return -1;
- if (acos_fd != -1) {
- if (close(acos_fd) == -1) return -2;
- }
+
/* disable use of fast arc cosine file */
acos_table = NULL;
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) {
size_t session_n;
-#ifndef WIN32
- int res;
-#endif
switch_mutex_lock(avmd_globals.mutex);
#ifndef WIN32
if (avmd_globals.settings.fast_math == 1) {
- res = destroy_fast_acosf();
- if (res != 0) {
- switch (res) {
- case -1:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n");
- break;
- case -2:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed closing arc cosine table\n");
- break;
- default:
- break;
- }
+ if (destroy_fast_acosf()) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n");
}
}
#endif
switch_mutex_unlock(avmd_globals.mutex);
switch_mutex_destroy(avmd_globals.mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection disabled\n");
+
return SWITCH_STATUS_SUCCESS;
}