use_starpu_pthread_macros.cocci 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // StarPU --- Runtime system for heterogeneous multicore architectures.
  2. //
  3. // Copyright (C) 2011-2012 inria
  4. // Copyright (C) 2011 Centre National de la Recherche Scientifique
  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. virtual context
  17. virtual org
  18. virtual patch
  19. virtual report
  20. @initialize:python depends on report || org@
  21. d = {
  22. 'pthread_mutex_init' : '_STARPU_PTHREAD_MUTEX_INIT',
  23. 'pthread_mutex_lock' : '_STARPU_PTHREAD_MUTEX_LOCK',
  24. 'pthread_mutex_unlock' : '_STARPU_PTHREAD_MUTEX_UNLOCK',
  25. 'pthread_mutex_destroy' : '_STARPU_PTHREAD_MUTEX_DESTROY',
  26. 'pthread_rwlock_init' : '_STARPU_PTHREAD_RWLOCK_INIT',
  27. 'pthread_rwlock_rdlock' : '_STARPU_PTHREAD_RWLOCK_RDLOCK',
  28. 'pthread_rwlock_wrlock' : '_STARPU_PTHREAD_RWLOCK_WRLOCK',
  29. 'pthread_rwlock_unlock' : '_STARPU_PTHREAD_RWLOCK_UNLOCK',
  30. 'pthread_rwlock_destroy' : '_STARPU_PTHREAD_RWLOCK_DESTROY',
  31. 'pthread_cond_init' : '_STARPU_PTHREAD_COND_INIT',
  32. 'pthread_cond_signal' : '_STARPU_PTHREAD_COND_SIGNAL',
  33. 'pthread_cond_broadcast' : '_STARPU_PTHREAD_COND_BROADCAST',
  34. 'pthread_cond_wait' : '_STARPU_PTHREAD_COND_WAIT',
  35. 'pthread_cond_destroy' : '_STARPU_PTHREAD_COND_DESTROY',
  36. 'pthread_barrier_init' : '_STARPU_PTHREAD_BARRIER_INIT',
  37. 'pthread_barrier_wait' : '_STARPU_PTHREAD_BARRIER_WAIT',
  38. 'pthread_barrier_destroy' : '_STARPU_PTHREAD_BARRIER_DESTROY',
  39. 'pthread_spin_destroy' : '_STARPU_PTHREAD_SPIN_DESTROY',
  40. 'pthread_spin_lock' : '_STARPU_PTHREAD_SPIN_LOCK',
  41. 'pthread_spin_unlock' : '_STARPU_PTHREAD_SPIN_UNLOCK'
  42. }
  43. msg = "Use %s instead of %s."
  44. from re import sub
  45. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  46. @r@
  47. identifier f =~ "^pthread_";
  48. position p;
  49. @@
  50. f@p(...)
  51. //
  52. // Context mode.
  53. //
  54. @depends on context@
  55. identifier f =~ "^pthread_";
  56. @@
  57. * f(...)
  58. //
  59. // Org mode.
  60. //
  61. @script:python depends on r && org@
  62. p << r.p;
  63. f << r.f;
  64. @@
  65. if str(f) in d.keys():
  66. coccilib.org.print_todo(p[0], orgmsg % (d[str(f)], f))
  67. else:
  68. coccilib.org.print_todo(p[0], "Shouldn't =%s= be wrapped in a macro ?" % str(f))
  69. //
  70. // Patch mode.
  71. //
  72. @pthread_mutex_ depends on patch@
  73. expression E1, E2;
  74. @@
  75. (
  76. - pthread_mutex_init(E1, E2);
  77. + _STARPU_PTHREAD_MUTEX_INIT(E1, E2);
  78. |
  79. - pthread_mutex_lock(E1);
  80. + _STARPU_PTHREAD_MUTEX_LOCK(E1);
  81. |
  82. - pthread_mutex_unlock(E1);
  83. + _STARPU_PTHREAD_MUTEX_UNLOCK(E1);
  84. |
  85. - pthread_mutex_destroy(E1);
  86. + _STARPU_PTHREAD_MUTEX_DESTROY(E1);
  87. )
  88. @pthread_rwlock_ depends on patch@
  89. expression E;
  90. @@
  91. (
  92. - pthread_rwlock_init(E);
  93. + _STARPU_PTHREAD_RWLOCK_INIT(E);
  94. |
  95. - pthread_rwlock_rdlock(E);
  96. + _STARPU_PTHREAD_RWLOCK_RDLOCK(E);
  97. |
  98. - pthread_rwlock_wrlock(E);
  99. + _STARPU_PTHREAD_RWLOCK_WRLOCK(E);
  100. |
  101. - pthread_rwlock_unlock(E);
  102. + _STARPU_PTHREAD_RWLOCK_UNLOCK(E);
  103. |
  104. - pthread_rwlock_destroy(E);
  105. + _STARPU_PTHREAD_RWLOCK_DESTROY(E);
  106. )
  107. @pthread_cond_ depends on patch@
  108. expression E1, E2;
  109. @@
  110. (
  111. - pthread_cond_init(E1, E2);
  112. + _STARPU_PTHREAD_COND_INIT(E1, E2);
  113. |
  114. - pthread_cond_signal(E1);
  115. + _STARPU_PTHREAD_COND_SIGNAL(E1);
  116. |
  117. - pthread_cond_broadcast(E1);
  118. + _STARPU_PTHREAD_COND_BROADCAST(E1);
  119. |
  120. - pthread_cond_wait(E1, E2);
  121. + _STARPU_PTHREAD_COND_WAIT(E1, E2);
  122. |
  123. - pthread_cond_destroy(E1);
  124. + _STARPU_PTHREAD_COND_DESTROY(E1);
  125. )
  126. @pthread_barrier_ depends on patch@
  127. expression E1, E2, E3;
  128. @@
  129. (
  130. - pthread_barrier_init(E1, E2, E3);
  131. + _STARPU_PTHREAD_BARRIER_INIT(E1, E2, E3);
  132. |
  133. - pthread_barrier_wait(E1);
  134. + _STARPU_PTHREAD_BARRIER_WAIT(E1);
  135. |
  136. - pthread_barrier_destroy(E1);
  137. + _STARPU_PTHREAD_BARRIER_DESTROY(E1);
  138. )
  139. @pthread_spin_ depends on patch@
  140. expression E1;
  141. @@
  142. (
  143. - pthread_spin_destroy(E1);
  144. + _STARPU_PTHREAD_SPIN_DESTROY(E1);
  145. |
  146. - pthread_spin_lock(E1);
  147. + _STARPU_PTHREAD_SPIN_LOCK(E1);
  148. |
  149. - pthread_spin_unlock(E1);
  150. + _STARPU_PTHREAD_SPIN_UNLOCK(E1);
  151. )
  152. //
  153. // Report mode.
  154. //
  155. @script:python depends on r && report@
  156. p << r.p;
  157. f << r.f;
  158. @@
  159. if str(f) in d.keys():
  160. coccilib.report.print_report(p[0], msg % (d[str(f)], f))
  161. else:
  162. coccilib.report.print_report(p[0], "Shouldn't %s be wrapped in a macro ?" % str(f))