acquire_cb.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011,2013,2014,2016 Université de Bordeaux
  4. * Copyright (C) 2011-2013 Inria
  5. * Copyright (C) 2011-2013,2017 CNRS
  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. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test that when using starpu_data_acquire_cb, the callback is properly called
  22. */
  23. unsigned token = 0;
  24. starpu_data_handle_t token_handle;
  25. static
  26. void callback(void *arg)
  27. {
  28. (void)arg;
  29. token = 42;
  30. starpu_data_release(token_handle);
  31. }
  32. int main(int argc, char **argv)
  33. {
  34. int ret;
  35. ret = starpu_initialize(NULL, &argc, &argv);
  36. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  37. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  38. starpu_variable_data_register(&token_handle, STARPU_MAIN_RAM, (uintptr_t)&token, sizeof(unsigned));
  39. starpu_data_acquire_cb(token_handle, STARPU_RW, callback, NULL);
  40. starpu_data_unregister(token_handle);
  41. FPRINTF(stderr, "Token: %u\n", token);
  42. starpu_shutdown();
  43. return (token == 42) ? EXIT_SUCCESS : EXIT_FAILURE;
  44. }