use_starpu_pthread_macros.cocci 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. virtual context
  17. virtual org
  18. virtual patch
  19. virtual report
  20. @initialize:python depends on report || org@
  21. d = {
  22. 'pthread_create' : '_STARPU_PTHREAD_CREATE',
  23. 'pthread_mutex_init' : '_STARPU_PTHREAD_MUTEX_INIT',
  24. 'pthread_mutex_lock' : '_STARPU_PTHREAD_MUTEX_LOCK',
  25. 'pthread_mutex_unlock' : '_STARPU_PTHREAD_MUTEX_UNLOCK',
  26. 'pthread_mutex_destroy' : '_STARPU_PTHREAD_MUTEX_DESTROY',
  27. 'pthread_rwlock_init' : '_STARPU_PTHREAD_RWLOCK_INIT',
  28. 'pthread_rwlock_rdlock' : '_STARPU_PTHREAD_RWLOCK_RDLOCK',
  29. 'pthread_rwlock_wrlock' : '_STARPU_PTHREAD_RWLOCK_WRLOCK',
  30. 'pthread_rwlock_unlock' : '_STARPU_PTHREAD_RWLOCK_UNLOCK',
  31. 'pthread_rwlock_destroy' : '_STARPU_PTHREAD_RWLOCK_DESTROY',
  32. 'pthread_cond_init' : '_STARPU_PTHREAD_COND_INIT',
  33. 'pthread_cond_signal' : '_STARPU_PTHREAD_COND_SIGNAL',
  34. 'pthread_cond_broadcast' : '_STARPU_PTHREAD_COND_BROADCAST',
  35. 'pthread_cond_wait' : '_STARPU_PTHREAD_COND_WAIT',
  36. 'pthread_cond_destroy' : '_STARPU_PTHREAD_COND_DESTROY',
  37. 'pthread_barrier_init' : '_STARPU_PTHREAD_BARRIER_INIT',
  38. 'pthread_barrier_wait' : '_STARPU_PTHREAD_BARRIER_WAIT',
  39. 'pthread_barrier_destroy' : '_STARPU_PTHREAD_BARRIER_DESTROY',
  40. 'pthread_spin_destroy' : '_STARPU_PTHREAD_SPIN_DESTROY',
  41. 'pthread_spin_lock' : '_STARPU_PTHREAD_SPIN_LOCK',
  42. 'pthread_spin_unlock' : '_STARPU_PTHREAD_SPIN_UNLOCK'
  43. }
  44. msg = "Use %s instead of %s."
  45. from re import sub
  46. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  47. @r@
  48. identifier f =~ "^pthread_";
  49. position p;
  50. @@
  51. f@p(...)
  52. //
  53. // Context mode.
  54. //
  55. @depends on context@
  56. identifier f =~ "^pthread_";
  57. @@
  58. * f(...)
  59. //
  60. // Org mode.
  61. //
  62. @script:python depends on r && org@
  63. p << r.p;
  64. f << r.f;
  65. @@
  66. if str(f) in d.keys():
  67. coccilib.org.print_todo(p[0], orgmsg % (d[str(f)], f))
  68. else:
  69. coccilib.org.print_todo(p[0], "Shouldn't =%s= be wrapped in a macro ?" % str(f))
  70. //
  71. // Patch mode.
  72. //
  73. @pthread_ depends on patch@
  74. expression E1, E2, E3, E4;
  75. @@
  76. - pthread_create(E1, E2, E3, E4);
  77. + _STARPU_PTHREAD_CREATE(E1, E2, E3, E4);
  78. @pthread_mutex_ depends on patch@
  79. expression E1, E2;
  80. @@
  81. (
  82. - pthread_mutex_init(E1, E2);
  83. + _STARPU_PTHREAD_MUTEX_INIT(E1, E2);
  84. |
  85. - pthread_mutex_lock(E1);
  86. + _STARPU_PTHREAD_MUTEX_LOCK(E1);
  87. |
  88. - pthread_mutex_unlock(E1);
  89. + _STARPU_PTHREAD_MUTEX_UNLOCK(E1);
  90. |
  91. - pthread_mutex_destroy(E1);
  92. + _STARPU_PTHREAD_MUTEX_DESTROY(E1);
  93. )
  94. @pthread_rwlock_ depends on patch@
  95. expression E;
  96. @@
  97. (
  98. - pthread_rwlock_init(E);
  99. + _STARPU_PTHREAD_RWLOCK_INIT(E);
  100. |
  101. - pthread_rwlock_rdlock(E);
  102. + _STARPU_PTHREAD_RWLOCK_RDLOCK(E);
  103. |
  104. - pthread_rwlock_wrlock(E);
  105. + _STARPU_PTHREAD_RWLOCK_WRLOCK(E);
  106. |
  107. - pthread_rwlock_unlock(E);
  108. + _STARPU_PTHREAD_RWLOCK_UNLOCK(E);
  109. |
  110. - pthread_rwlock_destroy(E);
  111. + _STARPU_PTHREAD_RWLOCK_DESTROY(E);
  112. )
  113. @pthread_cond_ depends on patch@
  114. expression E1, E2;
  115. @@
  116. (
  117. - pthread_cond_init(E1, E2);
  118. + _STARPU_PTHREAD_COND_INIT(E1, E2);
  119. |
  120. - pthread_cond_signal(E1);
  121. + _STARPU_PTHREAD_COND_SIGNAL(E1);
  122. |
  123. - pthread_cond_broadcast(E1);
  124. + _STARPU_PTHREAD_COND_BROADCAST(E1);
  125. |
  126. - pthread_cond_wait(E1, E2);
  127. + _STARPU_PTHREAD_COND_WAIT(E1, E2);
  128. |
  129. - pthread_cond_destroy(E1);
  130. + _STARPU_PTHREAD_COND_DESTROY(E1);
  131. )
  132. @pthread_barrier_ depends on patch@
  133. expression E1, E2, E3;
  134. @@
  135. (
  136. - pthread_barrier_init(E1, E2, E3);
  137. + _STARPU_PTHREAD_BARRIER_INIT(E1, E2, E3);
  138. |
  139. - pthread_barrier_wait(E1);
  140. + _STARPU_PTHREAD_BARRIER_WAIT(E1);
  141. |
  142. - pthread_barrier_destroy(E1);
  143. + _STARPU_PTHREAD_BARRIER_DESTROY(E1);
  144. )
  145. @pthread_spin_ depends on patch@
  146. expression E1;
  147. @@
  148. (
  149. - pthread_spin_destroy(E1);
  150. + _STARPU_PTHREAD_SPIN_DESTROY(E1);
  151. |
  152. - pthread_spin_lock(E1);
  153. + _STARPU_PTHREAD_SPIN_LOCK(E1);
  154. |
  155. - pthread_spin_unlock(E1);
  156. + _STARPU_PTHREAD_SPIN_UNLOCK(E1);
  157. )
  158. //
  159. // Report mode.
  160. //
  161. @script:python depends on r && report@
  162. p << r.p;
  163. f << r.f;
  164. @@
  165. if str(f) in d.keys():
  166. coccilib.report.print_report(p[0], msg % (d[str(f)], f))
  167. else:
  168. coccilib.report.print_report(p[0], "Shouldn't %s be wrapped in a macro ?" % str(f))