Permalink
Switch branches/tags
android-wear-5.1.1_r1 android-wear-5.1.0_r1 android-wear-5.0.0_r1 android-sdk-support_r11 android-sdk-adt_r20 android-sdk-adt_r16.0.1 android-sdk-4.4.2_r1.0.1 android-sdk-4.4.2_r1 android-sdk-4.0.3_r1 android-sdk-4.0.3-tools_r1 android-l-preview_r2 android-cts-verifier-4.0.3_r1 android-cts-verifier-4.0_r1 android-cts-5.1_r28 android-cts-5.1_r27 android-cts-5.1_r26 android-cts-5.1_r25 android-cts-5.1_r24 android-cts-5.1_r23 android-cts-5.1_r22 android-cts-5.1_r21 android-cts-5.1_r20 android-cts-5.1_r19 android-cts-5.1_r18 android-cts-5.1_r17 android-cts-5.1_r16 android-cts-5.1_r15 android-cts-5.1_r14 android-cts-5.1_r13 android-cts-5.1_r10 android-cts-5.1_r9 android-cts-5.1_r8 android-cts-5.1_r7 android-cts-5.1_r6 android-cts-5.1_r5 android-cts-5.1_r4 android-cts-5.1_r3 android-cts-5.1_r2 android-cts-5.1_r1 android-cts-5.0_r9 android-cts-5.0_r8 android-cts-5.0_r7 android-cts-5.0_r6 android-cts-5.0_r5 android-cts-5.0_r4 android-cts-5.0_r3 android-cts-4.4_r4 android-cts-4.4_r1 android-cts-4.2_r2 android-cts-4.2_r1 android-cts-4.1_r4 android-cts-4.1_r2 android-cts-4.1_r1 android-cts-4.0.3_r2 android-cts-4.0.3_r1 android-cts-4.0_r1 android-cts-2.3_r12 android-cts-2.3_r11 android-cts-2.3_r10 android-cts-2.2_r8 android-5.1.1_r38 android-5.1.1_r37 android-5.1.1_r36 android-5.1.1_r35 android-5.1.1_r34 android-5.1.1_r33 android-5.1.1_r30 android-5.1.1_r29 android-5.1.1_r28 android-5.1.1_r26 android-5.1.1_r25 android-5.1.1_r24 android-5.1.1_r23 android-5.1.1_r22 android-5.1.1_r20 android-5.1.1_r19 android-5.1.1_r18 android-5.1.1_r17 android-5.1.1_r16 android-5.1.1_r15 android-5.1.1_r14 android-5.1.1_r13 android-5.1.1_r12 android-5.1.1_r10 android-5.1.1_r9 android-5.1.1_r8 android-5.1.1_r7 android-5.1.1_r6 android-5.1.1_r5 android-5.1.1_r4 android-5.1.1_r3 android-5.1.1_r2 android-5.1.1_r1 android-5.1.0_r5 android-5.1.0_r4 android-5.1.0_r3 android-5.1.0_r1 android-5.0.2_r3 android-5.0.2_r1 android-5.0.1_r1
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (92 sloc) 2.64 KB
/**
* @file db_insert.c
* Inserting a key-value pair into a DB
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author Philippe Elie
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "odb.h"
static inline int add_node(odb_data_t * data, odb_key_t key, odb_value_t value)
{
odb_index_t new_node;
odb_node_t * node;
odb_index_t index;
/* no locking is necessary: iteration interface retrieve data through
* the node_base array, we doesn't increase current_size now but it's
* done by odb_commit_reservation() so the new slot is visible only
* after the increment
*/
if (data->descr->current_size >= data->descr->size) {
if (odb_grow_hashtable(data))
return EINVAL;
}
new_node = data->descr->current_size;
node = &data->node_base[new_node];
node->value = value;
node->key = key;
index = odb_do_hash(data, key);
node->next = data->hash_base[index];
data->hash_base[index] = new_node;
/* FIXME: we need wrmb() here */
odb_commit_reservation(data);
return 0;
}
int odb_update_node(odb_t * odb, odb_key_t key)
{
return odb_update_node_with_offset(odb, key, 1);
}
int odb_update_node_with_offset(odb_t * odb,
odb_key_t key,
unsigned long int offset)
{
odb_index_t index;
odb_node_t * node;
odb_data_t * data;
data = odb->data;
index = data->hash_base[odb_do_hash(data, key)];
while (index) {
node = &data->node_base[index];
if (node->key == key) {
if (node->value + offset != 0) {
node->value += offset;
} else {
/* post profile tools must handle overflow */
/* FIXME: the tricky way will be just to add
* a goto to jump right before the return
* add_node(), in this way we no longer can
* overflow. It'll work because new node are
* linked at the start of the node list for
* this bucket so this loop will see first a
* non overflowed node if one exist. When we
* grow the hashtable the most recently
* allocated node for this key will be setup
* last, so again it'll be linked at start of
* the list. pp tools looke like ok with this
* change.
*
* This change doesn't involve any file format
* change but perhaps it's a bit hacky to do
* this w/o bumping the sample file format
* version. The drawback of this is the added
* node are additive not multiplicative.
* (multiplicative as if we add more bits to
* store a value)
*/
}
return 0;
}
index = node->next;
}
return add_node(data, key, offset);
}
int odb_add_node(odb_t * odb, odb_key_t key, odb_value_t value)
{
return add_node(odb->data, key, value);
}