use_starpu_pthread_macros.cocci 4.5 KB

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