Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ucs/debug/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void ucs_log_init()
&ucs_log_file_close, &next_token);
}

get_thread_num();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 52 is done not under lock
maybe it is better to split this function into actual init_thread() and get_thread_id() parts?
if get_thread_id function the var "threads_count" can be accessed w/o lock indeed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a double-checked lock paradigm so no need to take lock every time.
if current thread is not found, it is searched for again with lock held.
it assigns the threads according to the order they are calling this function
calling it on the first time from log_init forces thread 0 to be the main.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

ucs_debug("%s loaded at 0x%lx", ucs_debug_get_lib_path(),
ucs_debug_get_lib_base_addr());
}
Expand Down
33 changes: 22 additions & 11 deletions src/ucs/type/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ struct ucs_class {
* Class initialization/cleanup function prototypes.
*/
#define UCS_CLASS_INIT_FUNC(_type, ...) \
ucs_status_t _UCS_CLASS_INIT_NAME(_type)(_type *self, ## __VA_ARGS__, \
ucs_class_t *_myclass, int *_init_count)
ucs_status_t _UCS_CLASS_INIT_NAME(_type)(_type *self, ucs_class_t *_myclass, \
int *_init_count, ## __VA_ARGS__)
#define UCS_CLASS_CLEANUP_FUNC(_type) \
void _UCS_CLASS_CLEANUP_NAME(_type)(_type *self)

Expand Down Expand Up @@ -89,10 +89,11 @@ struct ucs_class {
({ \
UCS_CLASS_DECLARE(_type) \
ucs_class_t *cls = &_UCS_CLASS_DECL_NAME(_type); \
int init_count = 0; \
int init_count = 1; \
ucs_status_t status; \
\
status = _UCS_CLASS_INIT_NAME(_type)((_type*)(_obj), ## __VA_ARGS__, cls, &init_count); \
status = _UCS_CLASS_INIT_NAME(_type)((_type*)(_obj), cls, &init_count, \
## __VA_ARGS__); \
if (status != UCS_OK) { \
_ucs_class_call_cleanup_chain(&_UCS_CLASS_DECL_NAME(_type), \
(_obj), init_count); \
Expand Down Expand Up @@ -171,12 +172,14 @@ struct ucs_class {
#define UCS_CLASS_CALL_SUPER_INIT(...) \
{ \
ucs_status_t status = \
_myclass->superclass->init(self, ## __VA_ARGS__, \
_myclass->superclass, _init_count); \
_myclass->superclass->init(self, _myclass->superclass, _init_count, \
## __VA_ARGS__); \
if (status != UCS_OK) { \
return status; \
} \
++(*_init_count); \
if (_myclass->superclass != &_UCS_CLASS_DECL_NAME(void)) { \
++(*_init_count); \
} \
}


Expand All @@ -194,12 +197,13 @@ struct ucs_class {
* status = _type##_new(arg1, arg2, arg3, &obj);
* }
*/
#define UCS_CLASS_DEFINE_NEW_FUNC(_type, _argtype, ...) \
#define UCS_CLASS_DECLARE_NEW_FUNC(_type, _argtype, ...) \
ucs_status_t UCS_CLASS_NEW_FUNC_NAME(_type)( \
UCS_PP_FOREACH(_UCS_CLASS_INIT_ARG_DEFINE, _, \
UCS_PP_ZIP((UCS_PP_SEQ(UCS_PP_NUM_ARGS(__VA_ARGS__))), (__VA_ARGS__))) \
_argtype **obj_p) \
{ \
_argtype **obj_p)
#define UCS_CLASS_DEFINE_NEW_FUNC(_type, _argtype, ...) \
UCS_CLASS_DECLARE_NEW_FUNC(_type, _argtype, ## __VA_ARGS__) { \
return UCS_CLASS_NEW(_type, obj_p \
UCS_PP_FOREACH(_UCS_CLASS_INIT_ARG_PASS, _, \
UCS_PP_SEQ(UCS_PP_NUM_ARGS(__VA_ARGS__)))); \
Expand Down Expand Up @@ -233,8 +237,10 @@ struct ucs_class {
* _type *obj = ...;
* _type##_delete(obj);
*/
#define UCS_CLASS_DECLARE_DELETE_FUNC(_type, _argtype) \
void UCS_CLASS_DELETE_FUNC_NAME(_type)(_argtype *self)
#define UCS_CLASS_DEFINE_DELETE_FUNC(_type, _argtype) \
void UCS_CLASS_DELETE_FUNC_NAME(_type)(_argtype *self) \
UCS_CLASS_DECLARE_DELETE_FUNC(_type, _argtype) \
{ \
UCS_CLASS_DELETE(_type, self); \
}
Expand All @@ -257,4 +263,9 @@ struct ucs_class {
void _ucs_class_call_cleanup_chain(ucs_class_t *cls, void *obj, int limit);


/**
* The empty class.
*/
UCS_CLASS_DECLARE(void);

#endif