~ubuntu-branches/ubuntu/vivid/ck/vivid-proposed

« back to all changes in this revision

Viewing changes to src/ck_rhs.c

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2014-09-10 22:16:03 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140910221603-bozg1pm8y27b76us
Tags: 0.4.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
        if (hs->mode & CK_RHS_MODE_READ_MOSTLY)
328
328
                size = sizeof(struct ck_rhs_map) +
329
329
                    (sizeof(void *) * n_entries +
330
 
                     sizeof(struct ck_rhs_no_entry_desc) * n_entries + 
 
330
                     sizeof(struct ck_rhs_no_entry_desc) * n_entries +
331
331
                     2 * CK_MD_CACHELINE - 1);
332
332
        else
333
333
                size = sizeof(struct ck_rhs_map) +
334
 
                    (sizeof(struct ck_rhs_entry_desc) * n_entries + 
 
334
                    (sizeof(struct ck_rhs_entry_desc) * n_entries +
335
335
                     CK_MD_CACHELINE - 1);
336
336
        map = hs->m->malloc(size);
337
337
        if (map == NULL)
408
408
{
409
409
 
410
410
        if (probes & map->offset_mask) {
411
 
                offset = (offset &~ map->offset_mask) + 
 
411
                offset = (offset &~ map->offset_mask) +
412
412
                    ((offset + 1) & map->offset_mask);
413
413
                return offset;
414
414
        } else
421
421
{
422
422
 
423
423
        if (probes & map->offset_mask) {
424
 
                offset = (offset &~ map->offset_mask) + ((offset - 1) & 
 
424
                offset = (offset &~ map->offset_mask) + ((offset - 1) &
425
425
                    map->offset_mask);
426
426
                return offset;
427
 
        } else 
 
427
        } else
428
428
                return ((offset - probes) & map->mask);
429
429
}
430
430
 
616
616
                if (behavior != CK_RHS_PROBE_NO_RH) {
617
617
                        struct ck_rhs_entry_desc *desc = (void *)&map->entries.no_entries.descs[offset];
618
618
 
619
 
                        if (pr == -1 && 
 
619
                        if (pr == -1 &&
620
620
                            desc->in_rh == false && desc->probes < probes) {
621
621
                                pr = offset;
622
622
                                *n_probes = probes;
730
730
                if ((behavior != CK_RHS_PROBE_NO_RH)) {
731
731
                        struct ck_rhs_entry_desc *desc = &map->entries.descs[offset];
732
732
 
733
 
                        if (pr == -1 && 
 
733
                        if (pr == -1 &&
734
734
                            desc->in_rh == false && desc->probes < probes) {
735
735
                                pr = offset;
736
736
                                *n_probes = probes;
818
818
}
819
819
 
820
820
static void
821
 
ck_rhs_add_wanted(struct ck_rhs *hs, long end_offset, long old_slot, 
 
821
ck_rhs_add_wanted(struct ck_rhs *hs, long end_offset, long old_slot,
822
822
        unsigned long h)
823
823
{
824
824
        struct ck_rhs_map *map = hs->map;
872
872
        while (probes > (unsigned long)map->offset_mask + 1) {
873
873
                offset -= ((probes - 1) &~ map->offset_mask);
874
874
                offset &= map->mask;
875
 
                offset = (offset &~ map->offset_mask) + 
 
875
                offset = (offset &~ map->offset_mask) +
876
876
                    ((offset - map->offset_mask) & map->offset_mask);
877
877
                probes -= map->offset_mask + 1;
878
878
        }
948
948
                prev = prevs[--prevs_nb];
949
949
                ck_pr_store_ptr(ck_rhs_entry_addr(map, orig_slot),
950
950
                    ck_rhs_entry(map, prev));
951
 
                h = ck_rhs_get_first_offset(map, orig_slot, 
 
951
                h = ck_rhs_get_first_offset(map, orig_slot,
952
952
                    desc->probes);
953
953
                ck_rhs_add_wanted(hs, orig_slot, prev, h);
954
954
                ck_pr_inc_uint(&map->generation[h & CK_RHS_G_MASK]);
966
966
        struct ck_rhs_map *map = hs->map;
967
967
        struct ck_rhs_entry_desc *desc, *new_desc = NULL;
968
968
        unsigned long h;
969
 
        
 
969
 
970
970
        desc = ck_rhs_desc(map, slot);
971
971
        h = ck_rhs_remove_wanted(hs, slot, -1);
972
972
        while (desc->wanted > 0) {
991
991
                                break;
992
992
                        wanted_probes++;
993
993
                }
994
 
                if (wanted_probes == map->probe_maximum) {
 
994
                if (!(wanted_probes < map->probe_maximum)) {
995
995
                        desc->wanted = 0;
996
996
                        break;
997
997
                }
1140
1140
                 * period if we can guarantee earlier position of
1141
1141
                 * duplicate key.
1142
1142
                 */
1143
 
                ck_rhs_add_wanted(hs, first, -1, h); 
 
1143
                ck_rhs_add_wanted(hs, first, -1, h);
1144
1144
                if (object != NULL) {
1145
1145
                        ck_pr_inc_uint(&map->generation[h & CK_RHS_G_MASK]);
1146
1146
                        ck_pr_fence_atomic_store();
1155
1155
                ck_pr_store_ptr(ck_rhs_entry_addr(map, slot), insert);
1156
1156
                ck_rhs_set_probes(map, slot, n_probes);
1157
1157
                if (object == NULL)
1158
 
                        ck_rhs_add_wanted(hs, slot, -1, h); 
 
1158
                        ck_rhs_add_wanted(hs, slot, -1, h);
1159
1159
        }
1160
1160
 
1161
1161
        if (object == NULL) {
1209
1209
                /* Insert key into first bucket in probe sequence. */
1210
1210
                ck_pr_store_ptr(ck_rhs_entry_addr(map, first), insert);
1211
1211
                desc->probes = n_probes;
1212
 
                ck_rhs_add_wanted(hs, first, -1, h); 
 
1212
                ck_rhs_add_wanted(hs, first, -1, h);
1213
1213
        } else {
1214
1214
                /* An empty slot was found. */
1215
1215
                ck_pr_store_ptr(ck_rhs_entry_addr(map, slot), insert);
1216
1216
                ck_rhs_set_probes(map, slot, n_probes);
1217
 
                ck_rhs_add_wanted(hs, slot, -1, h); 
 
1217
                ck_rhs_add_wanted(hs, slot, -1, h);
1218
1218
        }
1219
1219
 
1220
1220
        map->n_entries++;
1253
1253
        unsigned int g, g_p, probe;
1254
1254
        unsigned int *generation;
1255
1255
 
1256
 
        do { 
 
1256
        do {
1257
1257
                map = ck_pr_load_ptr(&hs->map);
1258
1258
                generation = &map->generation[h & CK_RHS_G_MASK];
1259
1259
                g = ck_pr_load_uint(generation);
1332
1332
        hs->map = ck_rhs_map_create(hs, n_entries);
1333
1333
        return hs->map != NULL;
1334
1334
}
1335