llvm.org GIT mirror llvm / 9a3df67
Add an atomic increment and decrement implementation, which will be used for thread-safe reference counting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73587 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
5 changed file(s) with 35 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
934934 volatile unsigned long val = 1;
935935 __sync_synchronize();
936936 __sync_val_compare_and_swap(&val, 1, 0);
937 __sync_add_and_fetch(&val, 1);
938 __sync_sub_and_fetch(&val, 1);
937939 return 0;
938940 }
939941 ]]),
3375933759 volatile unsigned long val = 1;
3376033760 __sync_synchronize();
3376133761 __sync_val_compare_and_swap(&val, 1, 0);
33762 __sync_add_and_fetch(&val, 1);
33763 __sync_sub_and_fetch(&val, 1);
3376233764 return 0;
3376333765 }
3376433766
2323 cas_flag CompareAndSwap(volatile cas_flag* ptr,
2424 cas_flag new_value,
2525 cas_flag old_value);
26 cas_flag AtomicPostIncrement(volatile cas_flag* ptr);
27 cas_flag AtomicPostDecrement(volatile cas_flag* ptr);
2628 }
2729 }
2830
352352 /// addAbstractTypeUser - Notify an abstract type that there is a new user of
353353 /// it. This function is called primarily by the PATypeHandle class.
354354 ///
355 void addAbstractTypeUser(AbstractTypeUser *U) const {
356 assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
357 AbstractTypeUsers.push_back(U);
358 }
355 void addAbstractTypeUser(AbstractTypeUser *U) const;
359356
360357 /// removeAbstractTypeUser - Notify an abstract type that a user of the class
361358 /// no longer has a handle to the type. This function is called primarily by
5050 # error No compare-and-swap implementation for your platform!
5151 #endif
5252 }
53
54 sys::cas_flag sys::AtomicPostIncrement(volatile sys::cas_flag* ptr) {
55 #if LLVM_MULTITHREADED==0
56 ++(*ptr);
57 return *ptr;
58 #elif defined(__GNUC__)
59 return __sync_add_and_fetch(ptr, 1);
60 #elif defined(_MSC_VER)
61 return InterlockedCompareExchange(ptr, new_value, old_value);
62 #else
63 # error No atomic increment implementation for your platform!
64 #endif
65 }
66
67 sys::cas_flag sys::AtomicPostDecrement(volatile sys::cas_flag* ptr) {
68 #if LLVM_MULTITHREADED==0
69 --(*ptr);
70 return *ptr;
71 #elif defined(__GNUC__)
72 return __sync_sub_and_fetch(ptr, 1);
73 #elif defined(_MSC_VER)
74 return InterlockedIncrement(ptr);
75 #else
76 # error No atomic decrement implementation for your platform!
77 #endif
78 }
79
80