2013-01-08 06:10:33 -08:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2013 ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-02-04 05:44:58 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
|
2013-01-08 06:10:33 -08:00
|
|
|
#include "eina_suite.h"
|
|
|
|
|
|
|
|
static Eina_Thread wk1, wk2, wk3, wk4, wk5;
|
|
|
|
static Eina_Barrier barrier;
|
|
|
|
|
|
|
|
static void *
|
|
|
|
wk_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
|
|
|
|
{
|
|
|
|
eina_barrier_wait(&barrier);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
wk1_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
|
|
|
|
{
|
|
|
|
eina_barrier_wait(&barrier);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
wk2_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
|
|
|
|
{
|
|
|
|
eina_barrier_wait(&barrier);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
wk3_func(void *data EINA_UNUSED, Eina_Thread thread EINA_UNUSED)
|
|
|
|
{
|
|
|
|
eina_barrier_wait(&barrier);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_barrier_test_simple)
|
2013-01-08 06:10:33 -08:00
|
|
|
{
|
2013-01-17 11:13:24 -08:00
|
|
|
Eina_Bool r;
|
|
|
|
int i;
|
2013-01-08 06:10:33 -08:00
|
|
|
|
2013-01-17 11:13:24 -08:00
|
|
|
i = eina_threads_init();
|
2013-01-18 06:32:08 -08:00
|
|
|
_ck_assert_int(i, >=, 1);
|
2013-01-17 11:13:24 -08:00
|
|
|
|
|
|
|
r = eina_barrier_new(&barrier, 6);
|
|
|
|
fail_unless(r);
|
|
|
|
|
2017-03-02 03:37:32 -08:00
|
|
|
r = eina_thread_create(&wk1, EINA_THREAD_NORMAL, -1, wk_func, NULL);
|
2013-01-17 11:13:24 -08:00
|
|
|
fail_unless(r);
|
|
|
|
|
2017-03-02 03:37:32 -08:00
|
|
|
r = eina_thread_create(&wk2, EINA_THREAD_NORMAL, -1, wk_func, NULL);
|
2013-01-17 11:13:24 -08:00
|
|
|
fail_unless(r);
|
|
|
|
|
2017-03-02 03:37:32 -08:00
|
|
|
r = eina_thread_create(&wk3, EINA_THREAD_NORMAL, -1, wk1_func, NULL);
|
2013-01-17 11:13:24 -08:00
|
|
|
fail_unless(r);
|
|
|
|
|
2017-03-02 03:37:32 -08:00
|
|
|
r = eina_thread_create(&wk4, EINA_THREAD_NORMAL, -1, wk2_func, NULL);
|
2013-01-17 11:13:24 -08:00
|
|
|
fail_unless(r);
|
|
|
|
|
2017-03-02 03:37:32 -08:00
|
|
|
r = eina_thread_create(&wk5, EINA_THREAD_NORMAL, -1, wk3_func, NULL);
|
2013-01-17 11:13:24 -08:00
|
|
|
fail_unless(r);
|
2013-01-08 06:10:33 -08:00
|
|
|
|
|
|
|
eina_barrier_wait(&barrier);
|
|
|
|
|
|
|
|
eina_thread_join(wk1);
|
2013-01-17 11:13:24 -08:00
|
|
|
|
2013-01-08 06:10:33 -08:00
|
|
|
eina_thread_join(wk2);
|
2013-01-17 11:13:24 -08:00
|
|
|
|
2013-01-08 06:10:33 -08:00
|
|
|
eina_thread_join(wk3);
|
2013-01-17 11:13:24 -08:00
|
|
|
|
2013-01-08 06:10:33 -08:00
|
|
|
eina_thread_join(wk4);
|
2013-01-17 11:13:24 -08:00
|
|
|
|
2013-01-08 06:10:33 -08:00
|
|
|
eina_thread_join(wk5);
|
|
|
|
|
|
|
|
eina_barrier_free(&barrier);
|
|
|
|
|
|
|
|
eina_threads_shutdown();
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2013-01-08 06:10:33 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
eina_test_barrier(TCase *tc)
|
|
|
|
{
|
2015-01-30 01:49:57 -08:00
|
|
|
#ifndef _WIN32
|
2018-03-29 14:02:04 -07:00
|
|
|
tcase_set_timeout(tc, 1);
|
2015-01-30 01:49:57 -08:00
|
|
|
#endif
|
2013-01-08 06:10:33 -08:00
|
|
|
tcase_add_test(tc, eina_barrier_test_simple);
|
|
|
|
}
|