From de810942e17703a2d53be242c8bc362c23d6799e Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 29 Apr 1999 22:26:58 +0000 Subject: [PATCH] ITS#141: move body of next_id_save() into new function next_id_get_save(), so the (read id, write id) sequence is protected by li_nextid_mutex. --- servers/slapd/back-ldbm/nextid.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/servers/slapd/back-ldbm/nextid.c b/servers/slapd/back-ldbm/nextid.c index 7c6f226413..031e0a1d36 100644 --- a/servers/slapd/back-ldbm/nextid.c +++ b/servers/slapd/back-ldbm/nextid.c @@ -13,6 +13,11 @@ #include "slap.h" #include "back-ldbm.h" +static ID next_id_read( Backend *be ); +static int next_id_write( Backend *be, ID id ); +static ID next_id_get_save( Backend *be, int do_save ); + + static ID next_id_read( Backend *be ) { @@ -84,15 +89,7 @@ next_id_write( Backend *be, ID id ) int next_id_save( Backend *be ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ID id = next_id_get( be ); - int rc = next_id_write( be, id ); - - if (rc == 0) { - li->li_nextid_wrote = id; - } - - return rc; + return( next_id_get_save( be, 1 ) == NOID ? -1 : 0 ); } ID @@ -156,6 +153,12 @@ next_id_return( Backend *be, ID id ) ID next_id_get( Backend *be ) +{ + return next_id_get_save( be, 0 ); +} + +static ID +next_id_get_save( Backend *be, int do_save ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; @@ -177,6 +180,14 @@ next_id_get( Backend *be ) id = li->li_nextid; + if ( do_save ) { + if ( next_id_write( be, id ) == 0 ) { + li->li_nextid_wrote = id; + } else { + id = NOID; + } + } + ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); return( id ); -- 2.39.5