aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-04-12 11:34:58 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-04-12 17:20:24 -0300
commitba10e311bddab18e38b1b706e232f804c2da9174 (patch)
treea4b66f731ff0c1a37a241b740a8e5465320d3a7a /src/nvim/os
parent27b5ef3975e22c7d62e8dbe780dc75607e36eb43 (diff)
downloadrneovim-ba10e311bddab18e38b1b706e232f804c2da9174.tar.gz
rneovim-ba10e311bddab18e38b1b706e232f804c2da9174.tar.bz2
rneovim-ba10e311bddab18e38b1b706e232f804c2da9174.zip
memory: Replace klib memory pools by malloc/free
Klib pools were used to improve allocation efficiency for some small objects, but it is not a thread-safe approach. Thread safety in allocations will be required for implementing #2371).
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/event.c1
-rw-r--r--src/nvim/os/signal.c16
-rw-r--r--src/nvim/os/wstream.c26
3 files changed, 9 insertions, 34 deletions
diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c
index dbb9d337cf..0560da1e2e 100644
--- a/src/nvim/os/event.c
+++ b/src/nvim/os/event.c
@@ -46,7 +46,6 @@ void event_init(void)
// early msgpack-rpc initialization
msgpack_rpc_init_method_table();
msgpack_rpc_helpers_init();
- wstream_init();
// Initialize input events
input_init();
// Timer to wake the event loop if a timeout argument is passed to
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index a332ad2314..f824543003 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -1,9 +1,8 @@
+#include <assert.h>
#include <stdbool.h>
#include <uv.h>
-#include "nvim/lib/klist.h"
-
#include "nvim/ascii.h"
#include "nvim/vim.h"
#include "nvim/globals.h"
@@ -15,10 +14,6 @@
#include "nvim/os/signal.h"
#include "nvim/os/event.h"
-#define SignalEventFreer(x)
-KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer)
-kmempool_t(SignalEventPool) *signal_event_pool = NULL;
-
static uv_signal_t spipe, shup, squit, sterm;
#ifdef SIGPWR
static uv_signal_t spwr;
@@ -32,7 +27,6 @@ static bool rejecting_deadly;
void signal_init(void)
{
- signal_event_pool = kmp_init(SignalEventPool);
uv_signal_init(uv_default_loop(), &spipe);
uv_signal_init(uv_default_loop(), &shup);
uv_signal_init(uv_default_loop(), &squit);
@@ -119,18 +113,16 @@ static void deadly_signal(int signum)
static void signal_cb(uv_signal_t *handle, int signum)
{
- int *n = kmp_alloc(SignalEventPool, signal_event_pool);
- *n = signum;
+ assert(signum >= 0);
event_push((Event) {
.handler = on_signal_event,
- .data = n
+ .data = (void *)(uintptr_t)signum
}, false);
}
static void on_signal_event(Event event)
{
- int signum = *((int *)event.data);
- kmp_free(SignalEventPool, signal_event_pool, event.data);
+ int signum = (int)(uintptr_t)event.data;
switch (signum) {
#ifdef SIGPWR
diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c
index 13c6c0429f..ad9d936625 100644
--- a/src/nvim/os/wstream.c
+++ b/src/nvim/os/wstream.c
@@ -5,8 +5,6 @@
#include <uv.h>
-#include "nvim/lib/klist.h"
-
#include "nvim/os/uv_helpers.h"
#include "nvim/os/wstream.h"
#include "nvim/os/wstream_defs.h"
@@ -41,24 +39,10 @@ typedef struct {
uv_write_t uv_req;
} WRequest;
-#define WRequestFreer(x)
-KMEMPOOL_INIT(WRequestPool, WRequest, WRequestFreer)
-kmempool_t(WRequestPool) *wrequest_pool = NULL;
-#define WBufferFreer(x)
-KMEMPOOL_INIT(WBufferPool, WBuffer, WBufferFreer)
-kmempool_t(WBufferPool) *wbuffer_pool = NULL;
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/wstream.c.generated.h"
#endif
-/// Initialize pools for reusing commonly created objects
-void wstream_init(void)
-{
- wrequest_pool = kmp_init(WRequestPool);
- wbuffer_pool = kmp_init(WBufferPool);
-}
-
/// Creates a new WStream instance. A WStream encapsulates all the boilerplate
/// necessary for writing to a libuv stream.
///
@@ -163,7 +147,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)
wstream->curmem += buffer->size;
- WRequest *data = kmp_alloc(WRequestPool, wrequest_pool);
+ WRequest *data = xmalloc(sizeof(WRequest));
data->wstream = wstream;
data->buffer = buffer;
data->uv_req.data = data;
@@ -173,7 +157,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)
uvbuf.len = buffer->size;
if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) {
- kmp_free(WRequestPool, wrequest_pool, data);
+ free(data);
goto err;
}
@@ -202,7 +186,7 @@ WBuffer *wstream_new_buffer(char *data,
size_t refcount,
wbuffer_data_finalizer cb)
{
- WBuffer *rv = kmp_alloc(WBufferPool, wbuffer_pool);
+ WBuffer *rv = xmalloc(sizeof(WBuffer));
rv->size = size;
rv->refcount = refcount;
rv->cb = cb;
@@ -236,7 +220,7 @@ static void write_cb(uv_write_t *req, int status)
}
}
- kmp_free(WRequestPool, wrequest_pool, data);
+ free(data);
}
void wstream_release_wbuffer(WBuffer *buffer)
@@ -246,7 +230,7 @@ void wstream_release_wbuffer(WBuffer *buffer)
buffer->cb(buffer->data);
}
- kmp_free(WBufferPool, wbuffer_pool, buffer);
+ free(buffer);
}
}