use_starpu_pthread_macros.cocci 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. @r@
  45. identifier f =~ "^pthread_";
  46. position p;
  47. @@
  48. f@p(...)
  49. //
  50. // Context mode.
  51. //
  52. @depends on context@
  53. identifier f =~ "^pthread_";
  54. @@
  55. * f(...)
  56. //
  57. // Org mode.
  58. //
  59. @script:python depends on r && org@
  60. p << r.p;
  61. f << r.f;
  62. @@
  63. if str(f) in d.keys():
  64. coccilib.org.print_todo(p[0], msg % (d[str(f)], f))
  65. else:
  66. coccilib.org.print_todo(p[0], "Shouldn't %s be wrapped in a macro ?" % str(f))
  67. //
  68. // Patch mode.
  69. //
  70. @pthread_mutex_ depends on patch@
  71. expression E1, E2;
  72. @@
  73. (
  74. - pthread_mutex_init(E1, E2);
  75. + _STARPU_PTHREAD_MUTEX_INIT(E1, E2);
  76. |
  77. - pthread_mutex_lock(E1);
  78. + _STARPU_PTHREAD_MUTEX_LOCK(E1);
  79. |
  80. - pthread_mutex_unlock(E1);
  81. + _STARPU_PTHREAD_MUTEX_UNLOCK(E1);
  82. |
  83. - pthread_mutex_destroy(E1);
  84. + _STARPU_PTHREAD_MUTEX_DESTROY(E1);
  85. )
  86. @pthread_rwlock_ depends on patch@
  87. expression E;
  88. @@
  89. (
  90. - pthread_rwlock_init(E);
  91. + _STARPU_PTHREAD_RWLOCK_INIT(E);
  92. |
  93. - pthread_rwlock_rdlock(E);
  94. + _STARPU_PTHREAD_RWLOCK_RDLOCK(E);
  95. |
  96. - pthread_rwlock_wrlock(E);
  97. + _STARPU_PTHREAD_RWLOCK_WRLOCK(E);
  98. |
  99. - pthread_rwlock_unlock(E);
  100. + _STARPU_PTHREAD_RWLOCK_UNLOCK(E);
  101. |
  102. - pthread_rwlock_destroy(E);
  103. + _STARPU_PTHREAD_RWLOCK_DESTROY(E);
  104. )
  105. @pthread_cond_ depends on patch@
  106. expression E1, E2;
  107. @@
  108. (
  109. - pthread_cond_init(E1, E2);
  110. + _STARPU_PTHREAD_COND_INIT(E1, E2);
  111. |
  112. - pthread_cond_signal(E1);
  113. + _STARPU_PTHREAD_COND_SIGNAL(E1);
  114. |
  115. - pthread_cond_broadcast(E1);
  116. + _STARPU_PTHREAD_COND_BROADCAST(E1);
  117. |
  118. - pthread_cond_wait(E1, E2);
  119. + _STARPU_PTHREAD_COND_WAIT(E1, E2);
  120. |
  121. - pthread_cond_destroy(E1);
  122. + _STARPU_PTHREAD_COND_DESTROY(E1);
  123. )
  124. @pthread_barrier_ depends on patch@
  125. expression E1, E2, E3;
  126. @@
  127. (
  128. - pthread_barrier_init(E1, E2, E3);
  129. + _STARPU_PTHREAD_BARRIER_INIT(E1, E2, E3);
  130. |
  131. - pthread_barrier_wait(E1);
  132. + _STARPU_PTHREAD_BARRIER_WAIT(E1);
  133. |
  134. - pthread_barrier_destroy(E1);
  135. + _STARPU_PTHREAD_BARRIER_DESTROY(E1);
  136. )
  137. @pthread_spin_ depends on patch@
  138. expression E1;
  139. @@
  140. (
  141. - pthread_spin_destroy(E1);
  142. + _STARPU_PTHREAD_SPIN_DESTROY(E1);
  143. |
  144. - pthread_spin_lock(E1);
  145. + _STARPU_PTHREAD_SPIN_LOCK(E1);
  146. |
  147. - pthread_spin_unlock(E1);
  148. + _STARPU_PTHREAD_SPIN_UNLOCK(E1);
  149. )
  150. //
  151. // Report mode.
  152. //
  153. @script:python depends on r && report@
  154. p << r.p;
  155. f << r.f;
  156. @@
  157. if str(f) in d.keys():
  158. coccilib.report.print_report(p[0], msg % (d[str(f)], f))
  159. else:
  160. coccilib.report.print_report(p[0], "Shouldn't %s be wrapped in a macro ?" % str(f))