work2d.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2013-2014 Luke Dashjr
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #include "config.h"
  10. #include <stdbool.h>
  11. #include <stdint.h>
  12. #include "miner.h"
  13. #define MAX_DIVISIONS 255
  14. static bool work2d_reserved[MAX_DIVISIONS + 1] = { true };
  15. int work2d_xnonce1sz;
  16. int work2d_xnonce2sz;
  17. void work2d_init()
  18. {
  19. RUNONCE();
  20. for (uint64_t n = MAX_DIVISIONS; n; n >>= 8)
  21. ++work2d_xnonce1sz;
  22. work2d_xnonce2sz = 2;
  23. }
  24. bool reserve_work2d_(uint32_t * const xnonce1_p)
  25. {
  26. uint32_t xnonce1;
  27. for (xnonce1 = MAX_DIVISIONS; work2d_reserved[xnonce1]; --xnonce1)
  28. if (!xnonce1)
  29. return false;
  30. work2d_reserved[xnonce1] = true;
  31. *xnonce1_p = htole32(xnonce1);
  32. return true;
  33. }
  34. void release_work2d_(uint32_t xnonce1)
  35. {
  36. xnonce1 = le32toh(xnonce1);
  37. work2d_reserved[xnonce1] = false;
  38. }