static void internal_lock_writes()

in src/clds_hash_table.c [85:101]


static void internal_lock_writes(CLDS_HASH_TABLE_HANDLE clds_hash_table)
{
    /*Codes_SRS_CLDS_HASH_TABLE_42_017: [ clds_hash_table_snapshot shall increment a counter to lock the table for writes. ]*/
    (void)interlocked_increment(&clds_hash_table->locked_for_write);

    /*Codes_SRS_CLDS_HASH_TABLE_42_018: [ clds_hash_table_snapshot shall wait for the ongoing write operations to complete. ]*/
    int32_t pending_writes;
    do
    {
        pending_writes = interlocked_add(&clds_hash_table->pending_write_operations, 0);
        if (pending_writes != 0)
        {
            // Wait for writes
            (void)wait_on_address(&clds_hash_table->pending_write_operations, pending_writes, UINT32_MAX);
        }
    } while (pending_writes != 0);
}