use_starpu_pthread_macros.cocci 4.6 KB

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