mirror of
https://github.com/samba-team/samba.git
synced 2025-01-13 13:18:06 +03:00
lib: Remove g_lock_do()
This puts too much logic into this lowlevel infrastructure module, given the two minor external users. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
9dd65d1f99
commit
8febbc2bcd
@ -51,10 +51,6 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key);
|
||||
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
|
||||
const uint8_t *buf, size_t buflen);
|
||||
|
||||
NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
|
||||
struct timeval timeout,
|
||||
void (*fn)(void *private_data), void *private_data);
|
||||
|
||||
int g_lock_locks(struct g_lock_ctx *ctx,
|
||||
int (*fn)(TDB_DATA key, void *private_data),
|
||||
void *private_data);
|
||||
|
@ -750,67 +750,3 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
|
||||
}
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
|
||||
struct tevent_context **pev,
|
||||
struct messaging_context **pmsg,
|
||||
struct g_lock_ctx **pg_ctx)
|
||||
{
|
||||
struct tevent_context *ev = NULL;
|
||||
struct messaging_context *msg = NULL;
|
||||
struct g_lock_ctx *g_ctx = NULL;
|
||||
|
||||
ev = samba_tevent_context_init(mem_ctx);
|
||||
if (ev == NULL) {
|
||||
d_fprintf(stderr, "ERROR: could not init event context\n");
|
||||
goto fail;
|
||||
}
|
||||
msg = messaging_init(mem_ctx, ev);
|
||||
if (msg == NULL) {
|
||||
d_fprintf(stderr, "ERROR: could not init messaging context\n");
|
||||
goto fail;
|
||||
}
|
||||
g_ctx = g_lock_ctx_init(mem_ctx, msg);
|
||||
if (g_ctx == NULL) {
|
||||
d_fprintf(stderr, "ERROR: could not init g_lock context\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
*pev = ev;
|
||||
*pmsg = msg;
|
||||
*pg_ctx = g_ctx;
|
||||
return true;
|
||||
fail:
|
||||
TALLOC_FREE(g_ctx);
|
||||
TALLOC_FREE(msg);
|
||||
TALLOC_FREE(ev);
|
||||
return false;
|
||||
}
|
||||
|
||||
NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
|
||||
struct timeval timeout,
|
||||
void (*fn)(void *private_data), void *private_data)
|
||||
{
|
||||
struct tevent_context *ev = NULL;
|
||||
struct messaging_context *msg = NULL;
|
||||
struct g_lock_ctx *g_ctx = NULL;
|
||||
NTSTATUS status;
|
||||
|
||||
if (!g_lock_init_all(talloc_tos(), &ev, &msg, &g_ctx)) {
|
||||
status = NT_STATUS_ACCESS_DENIED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
status = g_lock_lock(g_ctx, key, lock_type, timeout);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
goto done;
|
||||
}
|
||||
fn(private_data);
|
||||
g_lock_unlock(g_ctx, key);
|
||||
|
||||
done:
|
||||
TALLOC_FREE(g_ctx);
|
||||
TALLOC_FREE(msg);
|
||||
TALLOC_FREE(ev);
|
||||
return status;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user