-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlocksRuntimeExtra.c
More file actions
94 lines (75 loc) · 2.01 KB
/
BlocksRuntimeExtra.c
File metadata and controls
94 lines (75 loc) · 2.01 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2025-2026 Paul Olteanu
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdatomic.h>
#include "Block_private.h"
/*
* Supporting routines for libobjc2.
*/
bool
_Block_has_signature(void const *b)
{
return atomic_load(&((BlockLiteral const *)b)->flags) &
BLOCK_HAS_SIGNATURE;
}
char const *
_Block_signature(void const *b)
{
BlockLiteral const *aBlock;
int f;
aBlock = (BlockLiteral const *)b;
f = atomic_load(&aBlock->flags);
if ((f & BLOCK_HAS_SIGNATURE) == 0)
return nullptr;
return f & BLOCK_HAS_COPY_DISPOSE ?
aBlock->copyDisposeDescriptor->typeEncoding :
aBlock->descriptor->typeEncoding;
}
bool
_Block_tryRetain(void *b)
{
BlockLiteral *aBlock;
int f;
aBlock = (BlockLiteral *)b;
f = atomic_load(&aBlock->flags);
while (true) {
if (f & BLOCK_DEALLOCATING)
return false;
if ((f & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK ||
atomic_compare_exchange_strong(&aBlock->flags, &f, f + 2))
return true;
}
}
bool
_Block_isDeallocating(void const *b)
{
return atomic_load(&((BlockLiteral const *)b)->flags) &
BLOCK_DEALLOCATING;
}
/*
* Extra compatibility routines.
*/
unsigned long
_Block_size(void const *b)
{
return ((BlockLiteral const *)b)->descriptor->blockSize;
}
bool
_Block_use_stret(void const *b)
{
int f;
f = atomic_load(&((BlockLiteral const *)b)->flags);
return (f & (BLOCK_HAS_SIGNATURE | BLOCK_USE_STRET)) ==
(BLOCK_HAS_SIGNATURE | BLOCK_USE_STRET);
}