destroy_task_on_error.cocci 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * StarPU --- Runtime system for heterogeneous multicore architectures.
  3. *
  4. * Copyright (C) 2012 Inria
  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. /*
  18. * When the submission of a task fails, StarPU cannot destroy the task, even if
  19. * the destroy flag is set. So we have to destroy it ourselves while handling
  20. * the error.
  21. *
  22. * TODO: match if statments without braces.
  23. */
  24. virtual context
  25. virtual org
  26. virtual patch
  27. virtual report
  28. @initialize:python depends on org || report@
  29. msg = "Warning: in %s(): "
  30. msg+= "\"%s\" should probably be destroyed in the body of the if statement"
  31. from re import sub
  32. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  33. @r@
  34. local idexpression t;
  35. identifier err;
  36. identifier f;
  37. position p;
  38. @@
  39. f(...)
  40. {
  41. <+...
  42. (
  43. err = starpu_task_submit(t);
  44. |
  45. int err = starpu_task_submit(t);
  46. )
  47. if@p(
  48. (
  49. err == -ENODEV
  50. |
  51. err != 0
  52. |
  53. STARPU_UNLIKELY(err == -ENODEV)
  54. |
  55. STARPU_UNLIKELY(err != 0)
  56. )
  57. )
  58. {
  59. ... when != starpu_task_destroy(t);
  60. when != exit(...);
  61. when != STARPU_ASSERT(...);
  62. when != return 77;
  63. }
  64. ...+>
  65. }
  66. // Context mode.
  67. @depends on r && context@
  68. position r.p;
  69. @@
  70. *if@p(...) { ... }
  71. // Org mode.
  72. @script:python depends on r && org@
  73. p << r.p;
  74. t << r.t;
  75. f << r.f;
  76. @@
  77. coccilib.org.print_todo(p[0], orgmsg % (f,t))
  78. // Patch mode.
  79. // XXX: Instead of "..." we could use a statement list (statement list SS). But
  80. // it does not seem to work with if there is a "return" statement in the body
  81. // of the if condition.
  82. // Using "..." makes the patch ugly, but this may be fixed in a future version
  83. // of spatch.
  84. @depends on r && patch@
  85. local idexpression r.t;
  86. position r.p;
  87. identifier r.f;
  88. @@
  89. f(...)
  90. {
  91. <+...
  92. if@p (...)
  93. (
  94. {
  95. ...
  96. + t->destroy = 0;
  97. + starpu_task_destroy(t);
  98. return ...;
  99. }
  100. |
  101. {
  102. ...
  103. + t->destroy = 0;
  104. + starpu_task_destroy(t);
  105. }
  106. )
  107. ...+>
  108. }
  109. // Report mode.
  110. @script:python depends on r && report@
  111. p << r.p;
  112. t << r.t;
  113. f << r.f;
  114. @@
  115. coccilib.report.print_report(p[0], msg % (f,t))