mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
instructions.c: threadsafe static var
* libguile/instructions.c (fetch_instruction_table): Lock access to the static, lazily-generated table.
This commit is contained in:
parent
05e7481311
commit
4b69f6ad26
1 changed files with 9 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
|
/* Copyright (C) 2001, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -23,8 +23,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "_scm.h"
|
#include "_scm.h"
|
||||||
|
#include "threads.h"
|
||||||
#include "instructions.h"
|
#include "instructions.h"
|
||||||
|
|
||||||
|
|
||||||
struct scm_instruction {
|
struct scm_instruction {
|
||||||
enum scm_opcode opcode; /* opcode */
|
enum scm_opcode opcode; /* opcode */
|
||||||
const char *name; /* instruction name */
|
const char *name; /* instruction name */
|
||||||
|
@ -45,11 +47,15 @@ struct scm_instruction {
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
static scm_i_pthread_mutex_t itable_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|
||||||
static struct scm_instruction*
|
static struct scm_instruction*
|
||||||
fetch_instruction_table ()
|
fetch_instruction_table ()
|
||||||
{
|
{
|
||||||
static struct scm_instruction *table = NULL;
|
static struct scm_instruction *table = NULL;
|
||||||
|
|
||||||
|
scm_i_pthread_mutex_lock (&itable_lock);
|
||||||
if (SCM_UNLIKELY (!table))
|
if (SCM_UNLIKELY (!table))
|
||||||
{
|
{
|
||||||
size_t bytes = SCM_VM_NUM_INSTRUCTIONS * sizeof(struct scm_instruction);
|
size_t bytes = SCM_VM_NUM_INSTRUCTIONS * sizeof(struct scm_instruction);
|
||||||
|
@ -71,6 +77,8 @@ fetch_instruction_table ()
|
||||||
table[i].symname = SCM_BOOL_F;
|
table[i].symname = SCM_BOOL_F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scm_i_pthread_mutex_unlock (&itable_lock);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue