1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #include <common.h>
26 #include "atomic.h"
27
28 #if defined(MI_DEFAULT_ATOMIC_REQUIRED)
29 #include <pthread.h>
30
31 static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER;
32
33 // Atomically increment x.
34 EXTERNC void AtomicInc(AtomicInt* x)
35 {
36 pthread_mutex_lock(&s_mutex);
37 (*x) ++;
38 pthread_mutex_unlock(&s_mutex);
39 }
40
41 // AtomicType decrement x and return true if it becomes zero.
42 EXTERNC unsigned char AtomicDec(AtomicInt* x)
43 mike 1.1 {
44 MI_Boolean res;
45
46 pthread_mutex_lock(&s_mutex);
47 (*x) --;
48 res = (*x) == 0;
49 pthread_mutex_unlock(&s_mutex);
50
51 return res;
52 }
53
54 #endif
55
|