1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use opaque struct pointer than void

This commit is contained in:
Nobuyoshi Nakada 2020-11-27 21:36:12 +09:00
parent 5d8fe1267d
commit 039ba387aa
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
4 changed files with 11 additions and 8 deletions

View file

@ -14,9 +14,10 @@
RBIMPL_SYMBOL_EXPORT_BEGIN()
typedef struct {
struct rb_random_struct {
VALUE seed;
} rb_random_t;
};
typedef struct rb_random_struct rb_random_t;
typedef void rb_random_init_func(rb_random_t *, const uint32_t *, size_t);
typedef unsigned int rb_random_get_int32_func(rb_random_t *);

View file

@ -1773,11 +1773,11 @@ rb_ractor_stderr_set(VALUE err)
}
}
void *
rb_ractor_default_rand(void *ptr)
struct rb_random_struct *
rb_ractor_default_rand(struct rb_random_struct *ptr)
{
if (rb_ractor_main_p()) {
static void *default_rnd;
static struct rb_random_struct *default_rnd;
if (UNLIKELY(ptr != NULL)) {
rb_ractor_t *cr = GET_RACTOR();
cr->default_rand = default_rnd = ptr;

View file

@ -36,6 +36,8 @@ struct rb_ractor_waiting_list {
rb_ractor_t **ractors;
};
struct rb_random_struct; // c.f. ruby/random.h
struct rb_ractor_struct {
// ractor lock
rb_nativethread_lock_t lock;
@ -127,7 +129,7 @@ struct rb_ractor_struct {
VALUE verbose;
VALUE debug;
void *default_rand; // used in random.c
struct rb_random_struct *default_rand; // used in random.c
// gc.c rb_objspace_reachable_objects_from
struct gc_mark_func_data_struct {

View file

@ -149,11 +149,11 @@ rand_start(rb_random_mt_t *r)
static rb_random_mt_t *
default_rand(void)
{
void *rb_ractor_default_rand(void *); // ractor.c
rb_random_t *rb_ractor_default_rand(rb_random_t *); // ractor.c
rb_random_mt_t *rnd = (rb_random_mt_t *)rb_ractor_default_rand(NULL);
if (rnd == NULL) {
rnd = ZALLOC(rb_random_mt_t);
rb_ractor_default_rand(rnd);
rb_ractor_default_rand(&rnd->base);
}
return rnd;
}