Bluetooth peripheral - correct way of updating internal characteristic's value
I have defined characteristic, which can be read, it's user_data is pointing to buffer1.
Now when I want to read the data by central, Characteristic Attribute read callback is called.
In this callback, I can do something like in "samples/bluetooth/peripheral"
static ssize_t read_vnd(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
const char *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
and just return the content of buffer1 itself (if I am correct and attr->user_data points to it)
now the question is - I have a new content for buffer1 prepared in buffer2 and in procedure called from main(), I do memcpy(buffer1,buffer2,sizeof(buffer1)). Can it happen, that the memcpy instructions are interrupted by read callback, so that buffer1 is inconsistent and I should use some locking mechanism (which one?) or is memcpy safe operation and buffer1 should always be ok?
Or is there any other suggested way of updating characteristic's value than just modifying the buffer1 directly?