useraction.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2008-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "libitm_i.h"
  20. namespace GTM HIDDEN {
  21. void
  22. gtm_thread::rollback_user_actions(size_t until_size)
  23. {
  24. for (size_t s = user_actions.size(); s > until_size; s--)
  25. {
  26. user_action *a = user_actions.pop();
  27. if (!a->on_commit)
  28. a->fn (a->arg);
  29. }
  30. }
  31. void
  32. gtm_thread::commit_user_actions()
  33. {
  34. for (vector<user_action>::iterator i = user_actions.begin(),
  35. ie = user_actions.end(); i != ie; i++)
  36. {
  37. if (i->on_commit)
  38. i->fn (i->arg);
  39. }
  40. user_actions.clear();
  41. }
  42. } // namespace GTM
  43. using namespace GTM;
  44. void ITM_REGPARM
  45. _ITM_addUserCommitAction(_ITM_userCommitFunction fn,
  46. _ITM_transactionId_t tid, void *arg)
  47. {
  48. gtm_thread *tx = gtm_thr();
  49. if (tid != _ITM_noTransactionId)
  50. GTM_fatal("resumingTransactionId in _ITM_addUserCommitAction must be "
  51. "_ITM_noTransactionId");
  52. gtm_thread::user_action *a = tx->user_actions.push();
  53. a->fn = fn;
  54. a->arg = arg;
  55. a->on_commit = true;
  56. a->resuming_id = tid;
  57. }
  58. void ITM_REGPARM
  59. _ITM_addUserUndoAction(_ITM_userUndoFunction fn, void * arg)
  60. {
  61. gtm_thread *tx = gtm_thr();
  62. gtm_thread::user_action *a = tx->user_actions.push();
  63. a->fn = fn;
  64. a->arg = arg;
  65. a->on_commit = false;
  66. }