mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f11db2a605
A doubly-linked list for tracking living threads guarantees constant-time insert/delete performance with no corner cases of a hash table. I chose this ccan implementation of doubly-linked lists over the BSD sys/queue.h implementation since: 1) insertion and removal are both branchless 2) locality is improved if a struct may be a member of multiple lists (0002 patch in Feature 9632 will introduce a secondary list for waiting FDs) This also increases cache locality during iteration: improving performance in a new IO#close benchmark with many sleeping threads while still scanning the same number of threads. vm_thread_close 1.762 * vm_core.h (rb_vm_t): list_head and counter for living_threads (rb_thread_t): vmlt_node for living_threads linkage (rb_vm_living_threads_init): new function wrapper (rb_vm_living_threads_insert): ditto (rb_vm_living_threads_remove): ditto * vm.c (rb_vm_living_threads_foreach): new function wrapper * thread.c (terminate_i, thread_start_func_2, thread_create_core, thread_fd_close_i, thread_fd_close): update to use new APIs * vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct, vm_memsize, vm_init2, Init_VM): ditto * vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto * benchmark/bm_vm_thread_close.rb: added to show improvement * ccan/build_assert/build_assert.h: added as a dependency of list.h * ccan/check_type/check_type.h: ditto * ccan/container_of/container_of.h: ditto * ccan/licenses/BSD-MIT: ditto * ccan/licenses/CC0: ditto * ccan/str/str.h: ditto (stripped of unused macros) * ccan/list/list.h: ditto * common.mk: add CCAN_LIST_INCLUDES [ruby-core:61871][Feature 9632 (part 1)] Apologies for the size of this commit, but I think a good doubly-linked list will be useful for future features, too. This may be used to add ordering to a container_of-based hash table to preserve compatibility if required (e.g. feature 9614). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
40 lines
1.2 KiB
C
40 lines
1.2 KiB
C
/* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
|
|
#ifndef CCAN_BUILD_ASSERT_H
|
|
#define CCAN_BUILD_ASSERT_H
|
|
|
|
/**
|
|
* BUILD_ASSERT - assert a build-time dependency.
|
|
* @cond: the compile-time condition which must be true.
|
|
*
|
|
* Your compile will fail if the condition isn't true, or can't be evaluated
|
|
* by the compiler. This can only be used within a function.
|
|
*
|
|
* Example:
|
|
* #include <stddef.h>
|
|
* ...
|
|
* static char *foo_to_char(struct foo *foo)
|
|
* {
|
|
* // This code needs string to be at start of foo.
|
|
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
|
|
* return (char *)foo;
|
|
* }
|
|
*/
|
|
#define BUILD_ASSERT(cond) \
|
|
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
|
|
|
|
/**
|
|
* BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
|
|
* @cond: the compile-time condition which must be true.
|
|
*
|
|
* Your compile will fail if the condition isn't true, or can't be evaluated
|
|
* by the compiler. This can be used in an expression: its value is "0".
|
|
*
|
|
* Example:
|
|
* #define foo_to_char(foo) \
|
|
* ((char *)(foo) \
|
|
* + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
|
|
*/
|
|
#define BUILD_ASSERT_OR_ZERO(cond) \
|
|
(sizeof(char [1 - 2*!(cond)]) - 1)
|
|
|
|
#endif /* CCAN_BUILD_ASSERT_H */
|