test_condwait.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_CONDWAIT_H_
  23. #define _TEST_CONDWAIT_H_
  24. void *threadfunc_timed(void *parm)
  25. {
  26. tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm;
  27. int ret = 0;
  28. ret = tsk_condwait_timedwait(condwait, 10);
  29. printf("threadfunc_timed/// %d\n", ret);
  30. return 0;
  31. }
  32. void *threadfunc_infinite(void *parm)
  33. {
  34. tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm;
  35. int ret = 0;
  36. ret = tsk_condwait_wait(condwait);
  37. printf("threadfunc_infinite/// %d\n", ret);
  38. return 0;
  39. }
  40. void *threadfunc_onemore(void *parm)
  41. {
  42. tsk_condwait_handle_t *condwait = (tsk_condwait_handle_t *)parm;
  43. int ret = 0;
  44. ret = tsk_condwait_wait(condwait);
  45. printf("threadfunc_onemore/// %d\n", ret);
  46. return 0;
  47. }
  48. /* Pthread condwait */
  49. void test_condwait()
  50. {
  51. tsk_condwait_handle_t *condwait = tsk_condwait_create();
  52. int ret;
  53. void* tid[3] = {0,0,0};
  54. printf("test_condwait//\n");
  55. tsk_thread_create(&tid[0], threadfunc_timed, condwait);
  56. tsk_thread_create(&tid[1], threadfunc_infinite, condwait);
  57. tsk_thread_create(&tid[2], threadfunc_onemore, condwait);
  58. tsk_condwait_timedwait(condwait, 100); /* give the threads the time to start and 'threadfunc_timed' function to timeout */
  59. ret = tsk_condwait_signal(condwait); /* Release one */
  60. ret = tsk_condwait_broadcast(condwait); /* Release all */
  61. tsk_thread_join(&tid[0]);
  62. tsk_thread_join(&tid[1]);
  63. tsk_thread_join(&tid[2]);
  64. tsk_condwait_destroy(&condwait);
  65. }
  66. #endif /* _TEST_CONDWAIT_H_ */