Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

vector-nolock.c 618B

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "mythreads.h"
  6. #include "main-header.h"
  7. #include "vector-header.h"
  8. // taken from https://en.wikipedia.org/wiki/Fetch-and-add
  9. int fetch_and_add(int * variable, int value) {
  10. asm volatile("lock; xaddl %%eax, %2;"
  11. :"=a" (value)
  12. :"a" (value), "m" (*variable)
  13. :"memory");
  14. return value;
  15. }
  16. void vector_add(vector_t *v_dst, vector_t *v_src) {
  17. int i;
  18. for (i = 0; i < VECTOR_SIZE; i++) {
  19. fetch_and_add(&v_dst->values[i], v_src->values[i]);
  20. }
  21. }
  22. void fini() {}
  23. #include "main-common.c"