Browse Source

code cleanup: fix code-in-asserts for NDEBUG

master
Yury Popov 2 years ago
parent
commit
7b46c81b2f
2 changed files with 40 additions and 17 deletions
  1. 12
    4
      src/libespeak-ng/event.c
  2. 28
    13
      src/libespeak-ng/fifo.c

+ 12
- 4
src/libespeak-ng/event.c View File

pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL); pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL);
init(); init();


assert(-1 != pthread_cond_init(&my_cond_start_is_required, NULL));
assert(-1 != pthread_cond_init(&my_cond_stop_is_required, NULL));
assert(-1 != pthread_cond_init(&my_cond_stop_is_acknowledged, NULL));
int a_status;

a_status = pthread_cond_init(&my_cond_start_is_required, NULL);
assert(-1 != a_status);
a_status = pthread_cond_init(&my_cond_stop_is_required, NULL);
assert(-1 != a_status);
a_status = pthread_cond_init(&my_cond_stop_is_acknowledged, NULL);
assert(-1 != a_status);
(void)a_status;


pthread_attr_t a_attrib; pthread_attr_t a_attrib;


if (!ts) if (!ts)
return; return;


assert(gettimeofday(&tv, NULL) != -1);
int a_status = gettimeofday(&tv, NULL);
assert(a_status != -1);
(void)a_status;
ts->tv_sec = tv.tv_sec; ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec*1000; ts->tv_nsec = tv.tv_usec*1000;
} }

+ 28
- 13
src/libespeak-ng/fifo.c View File

pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL); pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL);
init(0); init(0);


assert(-1 != pthread_cond_init(&my_cond_command_is_running, NULL));
assert(-1 != pthread_cond_init(&my_cond_start_is_required, NULL));
assert(-1 != pthread_cond_init(&my_cond_stop_is_acknowledged, NULL));
int a_status;
a_status = pthread_cond_init(&my_cond_command_is_running, NULL);
assert(-1 != a_status);
a_status = pthread_cond_init(&my_cond_start_is_required, NULL);
assert(-1 != a_status);
a_status = pthread_cond_init(&my_cond_stop_is_acknowledged, NULL);
assert(-1 != a_status);


pthread_attr_t a_attrib; pthread_attr_t a_attrib;
if (pthread_attr_init(&a_attrib) if (pthread_attr_init(&a_attrib)
pthread_attr_destroy(&a_attrib); pthread_attr_destroy(&a_attrib);


// leave once the thread is actually started // leave once the thread is actually started
assert(-1 != pthread_mutex_lock(&my_mutex));
a_status = pthread_mutex_lock(&my_mutex);
assert(-1 != a_status);
(void)a_status;
while (my_stop_is_acknowledged == false) { while (my_stop_is_acknowledged == false) {
while ((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR) while ((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR)
; ;
{ {
(void)p; // unused (void)p; // unused


int a_status;

// announce that thread is started // announce that thread is started
assert(-1 != pthread_mutex_lock(&my_mutex));
a_status = pthread_mutex_lock(&my_mutex);
assert(-1 != a_status);
my_stop_is_acknowledged = true; my_stop_is_acknowledged = true;
assert(-1 != pthread_cond_signal(&my_cond_stop_is_acknowledged));
assert(-1 != pthread_mutex_unlock(&my_mutex));
a_status = pthread_cond_signal(&my_cond_stop_is_acknowledged);
assert(-1 != a_status);
a_status = pthread_mutex_unlock(&my_mutex);
assert(-1 != a_status);


bool look_for_inactivity = false; bool look_for_inactivity = false;


} }
look_for_inactivity = true; look_for_inactivity = true;


int a_status = pthread_mutex_lock(&my_mutex);
a_status = pthread_mutex_lock(&my_mutex);
assert(!a_status); assert(!a_status);


if (!a_start_is_required) { if (!a_start_is_required) {


my_command_is_running = true; my_command_is_running = true;


assert(-1 != pthread_cond_broadcast(&my_cond_command_is_running));
assert(-1 != pthread_mutex_unlock(&my_mutex));
a_status = pthread_cond_broadcast(&my_cond_command_is_running);
assert(-1 != a_status);
a_status = pthread_mutex_unlock(&my_mutex);
assert(-1 != a_status);


while (my_command_is_running && !my_terminate_is_required) { while (my_command_is_running && !my_terminate_is_required) {
int a_status = pthread_mutex_lock(&my_mutex);
a_status = pthread_mutex_lock(&my_mutex);
assert(!a_status); assert(!a_status);
t_espeak_command *a_command = (t_espeak_command *)pop(); t_espeak_command *a_command = (t_espeak_command *)pop();


// and waiting for my_cond_stop_is_acknowledged // and waiting for my_cond_stop_is_acknowledged
init(1); init(1);


assert(-1 != pthread_mutex_lock(&my_mutex));
a_status = pthread_mutex_lock(&my_mutex);
assert(-1 != a_status);
my_start_is_required = false; my_start_is_required = false;


// acknowledge the stop request // acknowledge the stop request
my_stop_is_acknowledged = true; my_stop_is_acknowledged = true;
int a_status = pthread_cond_signal(&my_cond_stop_is_acknowledged);
a_status = pthread_cond_signal(&my_cond_stop_is_acknowledged);
assert(a_status != -1); assert(a_status != -1);
pthread_mutex_unlock(&my_mutex); pthread_mutex_unlock(&my_mutex);


} }
// and wait for the next start // and wait for the next start
} }
(void)a_status;


return NULL; return NULL;
} }

Loading…
Cancel
Save