PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/rt/sync/sync.h

http://github.com/jruderman/rust
C Header | 44 lines | 35 code | 8 blank | 1 comment | 0 complexity | 6da6e4ba3b2d83ea1bf3218743b76b8e MD5 | raw file
 1// -*- c++ -*-
 2#ifndef SYNC_H
 3#define SYNC_H
 4
 5class sync {
 6public:
 7    template <class T>
 8    static bool compare_and_swap(T *address,
 9        T oldValue, T newValue) {
10        return __sync_bool_compare_and_swap(address, oldValue, newValue);
11    }
12
13    template <class T>
14    static T increment(T *address) {
15        return __sync_add_and_fetch(address, 1);
16    }
17
18    template <class T>
19    static T decrement(T *address) {
20        return __sync_sub_and_fetch(address, 1);
21    }
22
23    template <class T>
24    static T increment(T &address) {
25        return __sync_add_and_fetch(&address, 1);
26    }
27
28    template <class T>
29    static T decrement(T &address) {
30        return __sync_sub_and_fetch(&address, 1);
31    }
32
33    template <class T>
34    static T read(T *address) {
35        return __sync_add_and_fetch(address, 0);
36    }
37
38    template <class T>
39    static T read(T &address) {
40        return __sync_add_and_fetch(&address, 0);
41    }
42};
43
44#endif /* SYNC_H */