Skip to content

Commit 15a4a5e

Browse files
committed
✨ API Changes to match requested changes from WG14
1 parent dfb5299 commit 15a4a5e

12 files changed

Lines changed: 204 additions & 200 deletions

File tree

documentation/source/api.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,15 @@ These are standard structures, useful to dictate behavior across platforms. Cert
105105

106106
All attributes are processed on the thread that invoked one of the attribute-handling thread creation functions, except for :cpp:struct:`ztdc_thrd_attr_custom_on_new`, which is invoked on the new thread. :cpp:struct:`ztdc_thrd_attr_custom_on_new` and :cpp:struct:`ztdc_thrd_attr_custom_on_origin` are always invoked after all other attributes have been processed in `attrs` (and no errors have occurred). :cpp:struct:`ztdc_thrd_attr_custom_on_new` is processed before :cpp:struct:`ztdc_thrd_attr_custom_on_origin`, and none of their functions are ever invoked in parallel. The processing of all attributes synchronizes before the start of the actual passed-in thread function.
107107

108-
.. doxygenstruct:: ztdc_thrd_attr_name
109-
:members:
110-
111-
.. doxygenstruct:: ztdc_thrd_attr_name_sized
112-
:members:
113-
114108
.. doxygenstruct:: ztdc_thrd_attr_mcname
115109
:members:
116110

117-
.. doxygenstruct:: ztdc_thrd_attr_mcname_sized
118-
:members:
119-
120111
.. doxygenstruct:: ztdc_thrd_attr_mwcname
121112
:members:
122113

123-
.. doxygenstruct:: ztdc_thrd_attr_mwcname_sized
124-
:members:
125-
126114
.. doxygenstruct:: ztdc_thrd_attr_c8name
127115
:members:
128116

129-
.. doxygenstruct:: ztdc_thrd_attr_c8name_sized
130-
:members:
131-
132-
.. doxygenstruct:: ztdc_thrd_attr_c16name
133-
:members:
134-
135-
.. doxygenstruct:: ztdc_thrd_attr_c16name_sized
136-
:members:
137-
138-
.. doxygenstruct:: ztdc_thrd_attr_c32name
139-
:members:
140-
141-
.. doxygenstruct:: ztdc_thrd_attr_c32name_sized
142-
:members:
143-
144117
.. doxygenstruct:: ztdc_thrd_attr_stack_size
145118
:members:
146119

@@ -168,6 +141,33 @@ These structures are less portable and do not work across platforms.
168141
.. doxygenstruct:: ztdc_thrd_attr__stack_guard_size
169142
:members:
170143

144+
.. doxygenstruct:: ztdc_thrd_attr__mcname_sized
145+
:members:
146+
147+
.. doxygenstruct:: ztdc_thrd_attr__mwcname_sized
148+
:members:
149+
150+
.. doxygenstruct:: ztdc_thrd_attr__c8name_sized
151+
:members:
152+
153+
.. doxygenstruct:: ztdc_thrd_attr__c16name
154+
:members:
155+
156+
.. doxygenstruct:: ztdc_thrd_attr__c16name_sized
157+
:members:
158+
159+
.. doxygenstruct:: ztdc_thrd_attr__c32name
160+
:members:
161+
162+
.. doxygenstruct:: ztdc_thrd_attr__c32name_sized
163+
:members:
164+
165+
.. doxygenstruct:: ztdc_thrd_attr__name
166+
:members:
167+
168+
.. doxygenstruct:: ztdc_thrd_attr__name_sized
169+
:members:
170+
171171

172172

173173
``ztdc_thrd_set_name`` functions

documentation/source/design/alternatives.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ One of the issues with the current design is how type-unsafe it can be. When cre
4646
4747
int main () {
4848
ztdc_thrd_attr_c8name name = {
49-
.kind = ztdc_thrd_attr_kind_c32name, // MISTAKE
49+
.kind = ztdc_thrd_attr_kind__c32name, // MISTAKE
5050
.name = u8"meow"
5151
};
5252

documentation/source/design/core.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Core Design
3434
The design of this library is centered around 4 things:
3535

3636
- the :cpp:enum:`ztdc_thrd_attr_kind` enumeration having appropriate values that map to a specific structure;
37-
- the :cpp:struct:`ztdc_thrd_attr_* <ztdc_thrd_attr_name>` structures (and the :cpp:struct:`ztdc_thrd_attr__* implementation-defined structures <ztdc_thrd_attr__stack_storage>`) for each enumerator in the :cpp:enum:`ztdc_thrd_attr_kind` enumeration;
37+
- the :cpp:struct:`ztdc_thrd_attr_* <ztdc_thrd_attr__name>` structures (and the :cpp:struct:`ztdc_thrd_attr__* implementation-defined structures <ztdc_thrd_attr__stack_storage>`) for each enumerator in the :cpp:enum:`ztdc_thrd_attr_kind` enumeration;
3838
- the :cpp:func:`ztdc_thrd_create_attrs` and :cpp:func:`ztdc_thrd_create_attrs_err` functions allowing an implementation to set data before or immediately after thread creation;
3939
- and, the :cpp:type:`ztdc_thrd_attr_err_func` error function type used in :cpp:func:`ztdc_thrd_create_attrs_err` to allow for checking and either passing over or denying an attribute.
4040

examples/source/basic_name_and_stack_size.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ int main(void) {
4747
thrd_t t0 = { 0 };
4848
thrd_t t1 = { 0 };
4949

50-
ztdc_thrd_attr_c32name name_attr = { // format
51-
.kind = ztdc_thrd_attr_kind_c32name,
50+
ztdc_thrd_attr__c32name name_attr = { // format
51+
.kind = ztdc_thrd_attr_kind__c32name,
5252
.name = U"meow?!"
5353
};
5454
ztdc_thrd_attr_stack_size stack_size_attr = {

examples/source/handle_unknown_attribute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ int thread_handle_attribute_errors(const ztdc_thrd_attr_kind* attr_kind, int err
5656
int main(void) {
5757
thrd_t t0 = { 0 };
5858

59-
ztdc_thrd_attr_c32name name_attr = { // format
60-
.kind = ztdc_thrd_attr_kind_c32name,
59+
ztdc_thrd_attr__c32name name_attr = { // format
60+
.kind = ztdc_thrd_attr_kind__c32name,
6161
.name = U"meow?!"
6262
};
6363
ztdc_thrd_attr_stack_size stack_size_attr = {

include/ztd/thread/threads.attr.h

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -72,45 +72,18 @@ typedef int(ztdc_thrd_attr_func_t)(
7272
/// for the thread to use.
7373
typedef enum ztdc_thrd_attr_kind
7474
#if ZTD_IS_ON(ZTD_CXX) || (ZTD_IS_ON(ZTD_C) && __STDC_VERSION__ >= 202300L)
75-
: int_least32_t
75+
: int_least32_t
7676
#endif
7777
{
78-
/// @brief A raw, direct name copied unmodified into the thread name descriptor. Corresponds to the structure
79-
/// ztdc_thrd_attr_name_sized.
80-
ztdc_thrd_attr_kind_name = 0,
81-
/// @brief A raw, direct name copied unmodified into the thread name descriptor. Includes the size. Corresponds to
82-
/// the structure ztdc_thrd_attr_name_sized.
83-
ztdc_thrd_attr_kind_name_sized = 1,
8478
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Corresponds
8579
/// to the structure ztdc_thrd_attr_mcname.
8680
ztdc_thrd_attr_kind_mcname = 2,
87-
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
88-
/// size. Corresponds to the structure ztdc_thrd_attr_mcname_sized.
89-
ztdc_thrd_attr_kind_mcname_sized = 3,
9081
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Corresponds
9182
/// to the structure ztdc_thrd_attr_mwcname.
9283
ztdc_thrd_attr_kind_mwcname = 4,
93-
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
94-
/// size. Corresponds to the structure ztdc_thrd_attr_mwcname_sized.
95-
ztdc_thrd_attr_kind_mwcname_sized = 5,
9684
/// @brief A name provided in the UTF-8 encoding to be transformed and stored as the thread name. Corresponds
9785
/// to the structure ztdc_thrd_attr_c8name.
9886
ztdc_thrd_attr_kind_c8name = 6,
99-
/// @brief A name provided in the UTF-8 encoding to be transformed and stored as the thread name. Includes the
100-
/// size. Corresponds to the structure ztdc_thrd_attr_c8name_sized.
101-
ztdc_thrd_attr_kind_c8name_sized = 7,
102-
/// @brief A name provided in the UTF-16 encoding to be transformed and stored as the thread name. Corresponds
103-
/// to the structure ztdc_thrd_attr_c16name.
104-
ztdc_thrd_attr_kind_c16name = 8,
105-
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
106-
/// size. Corresponds to the structure ztdc_thrd_attr_c16name_sized.
107-
ztdc_thrd_attr_kind_c16name_sized = 9,
108-
/// @brief A name provided in the UTF-32 encoding to be transformed and stored as the thread name. Corresponds to
109-
/// the structure ztdc_thrd_attr_c32name.
110-
ztdc_thrd_attr_kind_c32name = 10,
111-
/// @brief A name provided in the UTF-32 encoding to be transformed and stored as the thread name. Includes the
112-
/// size. Corresponds to the structure ztdc_thrd_attr_c32name_sized.
113-
ztdc_thrd_attr_kind_c32name_sized = 11,
11487
/// @brief The expected stack size for the implementation. Corresponds to the structure ztdc_thrd_attr_stack_size.
11588
ztdc_thrd_attr_kind_stack_size = 32,
11689
/// @brief Whether or not this thread should be started detached. Corresponds to the structure
@@ -124,6 +97,7 @@ typedef enum ztdc_thrd_attr_kind
12497
/// Gives the newly created thread, the native thread handle, and the native thread ID alongside a user data. Is
12598
/// invoked after all other thread attributes are applied.
12699
ztdc_thrd_attr_kind_custom_on_new = 513,
100+
127101
/// @brief The last standard-defined attribute that marks the beginning of the implementation-defined attributes.
128102
/// Corresponds to nothing and is just for informational purposes.
129103
ztdc_thrd_attr_kind_implementation_defined = 0xFFFF,
@@ -133,10 +107,37 @@ typedef enum ztdc_thrd_attr_kind
133107
/// @brief A size dictating how big the guard area on one or both sides of the stack might be.
134108
/// Implementation-defined and not cross-platform. Corresponds to the structure ztdc_thread_attr__stack_guard_size.
135109
ztdc_thrd_attr_kind__stack_guard_size = 0x10021,
110+
/// @brief A raw, direct name copied unmodified into the thread name descriptor. Corresponds to the structure
111+
/// ztdc_thrd_attr__name_sized.
112+
ztdc_thrd_attr_kind_name = 0x10000,
113+
/// @brief A raw, direct name copied unmodified into the thread name descriptor. Includes the size. Corresponds to
114+
/// the structure ztdc_thrd_attr__name_sized.
115+
ztdc_thrd_attr__kind_name_sized = 0x10001,
116+
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
117+
/// size. Corresponds to the structure ztdc_thrd_attr__mcname_sized.
118+
ztdc_thrd_attr__kind_mcname_sized = 0x10003,
119+
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
120+
/// size. Corresponds to the structure ztdc_thrd_attr__mwcname_sized.
121+
ztdc_thrd_attr__kind_mwcname_sized = 0x10005,
122+
/// @brief A name provided in the UTF-8 encoding to be transformed and stored as the thread name. Includes the
123+
/// size. Corresponds to the structure ztdc_thrd_attr__c8name_sized.
124+
ztdc_thrd_attr__kind_c8name_sized = 0x10007,
125+
/// @brief A name provided in the UTF-16 encoding to be transformed and stored as the thread name. Corresponds
126+
/// to the structure ztdc_thrd_attr__c16name.
127+
ztdc_thrd_attr_kind__c16name = 0x10008,
128+
/// @brief A name provided in the execution encoding to be transformed and stored as the thread name. Includes the
129+
/// size. Corresponds to the structure ztdc_thrd_attr__c16name_sized.
130+
ztdc_thrd_attr__kind_c16name_sized = 0x10009,
131+
/// @brief A name provided in the UTF-32 encoding to be transformed and stored as the thread name. Corresponds to
132+
/// the structure ztdc_thrd_attr__c32name.
133+
ztdc_thrd_attr_kind__c32name = 0x1000A,
134+
/// @brief A name provided in the UTF-32 encoding to be transformed and stored as the thread name. Includes the
135+
/// size. Corresponds to the structure ztdc_thrd_attr__c32name_sized.
136+
ztdc_thrd_attr__kind_c32name_sized = 0x1000B,
136137
} ztdc_thrd_attr_kind;
137138

138139
/// @brief Describes a direct, raw name for the implementation to use without modification.
139-
typedef struct ztdc_thrd_attr_name {
140+
typedef struct ztdc_thrd_attr__name {
140141
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_name.
141142
ztdc_thrd_attr_kind kind;
142143
/// @brief A pointer to the data that represents the name. It is null-terminated with an implementation-defined
@@ -146,11 +147,11 @@ typedef struct ztdc_thrd_attr_name {
146147
/// @remarks For Windows, this is typically 2 bytes (16 bits). For POSIX-derivative implementations, this is
147148
/// usually one byte (8 bits). On some exotic implementations, it can be four bytes (32 bits).
148149
const void* name;
149-
} ztdc_thrd_attr_name;
150+
} ztdc_thrd_attr__name;
150151

151152
/// @brief Describes a direct, raw name for the implementation to use without modification. Includes the size.
152-
typedef struct ztdc_thrd_attr_name_sized {
153-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_name_sized.
153+
typedef struct ztdc_thrd_attr__name_sized {
154+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_name_sized.
154155
ztdc_thrd_attr_kind kind;
155156
/// @brief The size of the data pointer. For the range denoted by the pointer `name` and this `size` parameter, it
156157
/// must not contain one of the implementation-defined null terminators for the data within.
@@ -161,7 +162,7 @@ typedef struct ztdc_thrd_attr_name_sized {
161162
/// @remarks For Windows, this is typically 2 bytes (16 bits). For POSIX-derivative implementations, this is
162163
/// usually one byte (8 bits). On some exotic implementations, it can be four bytes (32 bits).
163164
const void* name;
164-
} ztdc_thrd_attr_name_sized;
165+
} ztdc_thrd_attr__name_sized;
165166

166167
/// @brief Describes a name encoded in the execution encoding for the implementation to transcode to the a suitable
167168
/// internally-named string, if applicable.
@@ -174,14 +175,14 @@ typedef struct ztdc_thrd_attr_mcname {
174175

175176
/// @brief Describes a name encoded in the execution encoding for the implementation to transcode to the a suitable
176177
/// internally-named string, if applicable. Includes the size.
177-
typedef struct ztdc_thrd_attr_mcname_sized {
178-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_mcname_sized.
178+
typedef struct ztdc_thrd_attr__mcname_sized {
179+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_mcname_sized.
179180
ztdc_thrd_attr_kind kind;
180181
/// @brief The size of the name. Must not include a null terminator in its range.
181182
size_t size;
182183
/// @brief The execution encoding name.
183184
const char* name;
184-
} ztdc_thrd_attr_mcname_sized;
185+
} ztdc_thrd_attr__mcname_sized;
185186

186187
/// @brief Describes a name encoded in the wide execution encoding for the implementation to transcode to the a suitable
187188
/// internally-named string, if applicable.
@@ -194,14 +195,14 @@ typedef struct ztdc_thrd_attr_mwcname {
194195

195196
/// @brief Describes a name encoded in the wide execution encoding for the implementation to transcode to the a suitable
196197
/// internally-named string, if applicable. Includes the size.
197-
typedef struct ztdc_thrd_attr_mwcname_sized {
198-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_mwcname_sized.
198+
typedef struct ztdc_thrd_attr__mwcname_sized {
199+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_mwcname_sized.
199200
ztdc_thrd_attr_kind kind;
200201
/// @brief The size of the name. Must not include a null terminator in its range.
201202
size_t size;
202203
/// @brief The wide execution encoding name.
203204
const ztd_wchar_t* name;
204-
} ztdc_thrd_attr_mwcname_sized;
205+
} ztdc_thrd_attr__mwcname_sized;
205206

206207
/// @brief Describes a name encoded in the UTF-8 encoding for the implementation to transcode to the a suitable
207208
/// internally-named string, if applicable.
@@ -214,54 +215,54 @@ typedef struct ztdc_thrd_attr_c8name {
214215

215216
/// @brief Describes a name encoded in the UTF-8 encoding for the implementation to transcode to the a suitable
216217
/// internally-named string, if applicable. Includes the size.
217-
typedef struct ztdc_thrd_attr_c8name_sized {
218-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_c8name_sized.
218+
typedef struct ztdc_thrd_attr__c8name_sized {
219+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_c8name_sized.
219220
ztdc_thrd_attr_kind kind;
220221
/// @brief The size of the name. Must not include a null terminator in its range.
221222
size_t size;
222223
/// @brief The UTF-8 encoding name.
223224
const ztd_char8_t* name;
224-
} ztdc_thrd_attr_c8name_sized;
225+
} ztdc_thrd_attr__c8name_sized;
225226

226227
/// @brief Describes a name encoded in the UTF-16 encoding for the implementation to transcode to the a suitable
227228
/// internally-named string, if applicable.
228-
typedef struct ztdc_thrd_attr_c16name {
229-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_c16name.
229+
typedef struct ztdc_thrd_attr__c16name {
230+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind__c16name.
230231
ztdc_thrd_attr_kind kind;
231232
/// @brief The UTF-8 encoding name.
232233
const ztd_char16_t* name;
233-
} ztdc_thrd_attr_c16name;
234+
} ztdc_thrd_attr__c16name;
234235

235236
/// @brief Describes a name encoded in the UTF-16 encoding for the implementation to transcode to the a suitable
236237
/// internally-named string, if applicable. Includes the size.
237-
typedef struct ztdc_thrd_attr_c16name_sized {
238-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_c16name_sized.
238+
typedef struct ztdc_thrd_attr__c16name_sized {
239+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_c16name_sized.
239240
ztdc_thrd_attr_kind kind;
240241
/// @brief The size of the name. Must not include a null terminator in its range.
241242
size_t size;
242243
/// @brief The UTF-8 encoding name.
243244
const ztd_char16_t* name;
244-
} ztdc_thrd_attr_c16name_sized;
245+
} ztdc_thrd_attr__c16name_sized;
245246

246247
/// @brief Describes a name encoded in the UTF-32 encoding for the implementation to transcode to the a suitable
247248
/// internally-named string, if applicable.
248-
typedef struct ztdc_thrd_attr_c32name {
249-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_c32name.
249+
typedef struct ztdc_thrd_attr__c32name {
250+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind__c32name.
250251
ztdc_thrd_attr_kind kind;
251252
/// @brief The UTF-32 encoding name. Null terminated.
252253
const ztd_char32_t* name;
253-
} ztdc_thrd_attr_c32name;
254+
} ztdc_thrd_attr__c32name;
254255

255256
/// @brief Describes a name encoded in the UTF-32 encoding for the implementation to transcode to the a suitable
256257
/// internally-named string, if applicable. Includes the size.
257-
typedef struct ztdc_thrd_attr_c32name_sized {
258-
/// @brief The kind of the attribute. Must be ztdc_thrd_attr_kind_c32name_sized.
258+
typedef struct ztdc_thrd_attr__c32name_sized {
259+
/// @brief The kind of the attribute. Must be ztdc_thrd_attr__kind_c32name_sized.
259260
ztdc_thrd_attr_kind kind;
260261
/// @brief The size of the name. Must not include a null terminator in its range.
261262
size_t size;
262263
/// @brief The UTF-32 encoding name.
263264
const ztd_char32_t* name;
264-
} ztdc_thrd_attr_c32name_sized;
265+
} ztdc_thrd_attr__c32name_sized;
265266

266267
/// @brief Describes a request for a specific stack size.
267268
typedef struct ztdc_thrd_attr_stack_size {

0 commit comments

Comments
 (0)