This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathopennurbs_atomic_op.h
78 lines (63 loc) · 2.09 KB
/
opennurbs_atomic_op.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2018 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_ATOMIC_OP_INC_)
#define OPENNURBS_ATOMIC_OP_INC_
/*
Description:
Expert user tool to decrement the value of the parameter as an atomic operation.
Parameters:
ptr_int32 - [in]
A non-null pointer to a signed 32-bit integer.
Returns:
Decremented value.
Example:
int i = 3;
// j will be 2
int j = ON_AtomicDecrementInt32(&i);
Remarks:
Caller is responsible for insuring ptr_int32 is not nullptr.
*/
// ON_AtomicDecrementInt32(int* ptr_int32)
/*
Description:
Expert user tool to increment the value of the parameter as an atomic operation.
Parameters:
ptr_int32 - [in]
A non-null pointer to a signed 32-bit integer.
Returns:
Incremented value.
Example:
int i = 3;
// j will be 4
int j = ON_AtomicIncrementInt32(&i);
Remarks:
Caller is responsible for insuring ptr_int32 points to
a signed 32-bit integer.
*/
// ON_AtomicIncrementInt32(int* ptr_int32)
#if defined(ON_RUNTIME_WIN)
#define ON_AtomicDecrementInt32(ptr_int32) InterlockedDecrement((long*)(ptr_int32))
#define ON_AtomicIncrementInt32(ptr_int32) InterlockedIncrement((long*)(ptr_int32))
#elif defined(ON_RUNTIME_APPLE_MACOS)
#include <libkern/OSAtomic.h>
#define ON_AtomicDecrementInt32(ptr_int32) OSAtomicDecrement32((int*)(ptr_int32))
#define ON_AtomicIncrementInt32(ptr_int32) OSAtomicIncrement32((int*)(ptr_int32))
#else
// NOT thread safe
#define ON_AtomicDecrementInt32(ptr_int32) (--(*ptr_int32))
#define ON_AtomicIncrementInt32(ptr_int32) (++(*ptr_int32))
#endif
#endif