protect



Summary

#include <dataman/dataman.h>

protect(idx_name) else ...

char *idx_name;

Description

This procedure is used to "lock" a cooperating process out of a database record. The procedure protects the record that the named index's MFRP currently points to, and that record also becomes the current master record. If the record is not already protected, the caller gets exclusive access over other processes that try to protect the same record. If the record is already protected, up to three attempts are made internally to protect it. If the procedure still can't protect the record it returns to the else clause. Protect also assures that the version in memory is the most recent version that has been written to disk.

Example

    #include <dataman/dataman.h>

    main(int argc, char *argv[])
    {
        key k_buff;
          ...
        move(k_buff,stat_key,strlen(stat_key));
        get(idx1,k_buff) else
            fatal("Statistic record key not found","");
        while (1) {
            protect(idx1) else {
                show(10,10,"Waiting for update",ENDLIST);
                continue;
            }
            break;
        }
          ...        /* update stats */
        clear(idx1);
    }

«previous  next»