[SMF] Prevent concurrent access to ogs_pool allocating smf_event (#1546)
This commit is contained in:
parent
aba1867902
commit
43a7259781
|
@ -21,22 +21,27 @@
|
|||
#include "context.h"
|
||||
|
||||
static OGS_POOL(pool, smf_event_t);
|
||||
static ogs_thread_mutex_t smf_event_alloc_mutex;
|
||||
|
||||
void smf_event_init(void)
|
||||
{
|
||||
ogs_pool_init(&pool, ogs_app()->pool.event);
|
||||
ogs_thread_mutex_init(&smf_event_alloc_mutex);
|
||||
}
|
||||
|
||||
void smf_event_final(void)
|
||||
{
|
||||
ogs_pool_final(&pool);
|
||||
ogs_thread_mutex_destroy(&smf_event_alloc_mutex);
|
||||
}
|
||||
|
||||
smf_event_t *smf_event_new(smf_event_e id)
|
||||
{
|
||||
smf_event_t *e = NULL;
|
||||
|
||||
ogs_thread_mutex_lock(&smf_event_alloc_mutex);
|
||||
ogs_pool_alloc(&pool, &e);
|
||||
ogs_thread_mutex_unlock(&smf_event_alloc_mutex);
|
||||
ogs_assert(e);
|
||||
memset(e, 0, sizeof(*e));
|
||||
|
||||
|
@ -48,7 +53,9 @@ smf_event_t *smf_event_new(smf_event_e id)
|
|||
void smf_event_free(smf_event_t *e)
|
||||
{
|
||||
ogs_assert(e);
|
||||
ogs_thread_mutex_lock(&smf_event_alloc_mutex);
|
||||
ogs_pool_free(&pool, e);
|
||||
ogs_thread_mutex_unlock(&smf_event_alloc_mutex);
|
||||
}
|
||||
|
||||
const char *smf_event_get_name(smf_event_t *e)
|
||||
|
|
Loading…
Reference in New Issue