• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/timemachine/db-4.7.25.NC/docs_src/ref/arch/
1m4_ignore([dnl
2#include <sys/types.h>
3#include <stdlib.h>
4
5#include <db.h>
6
7int foo();
8
9int
10main()
11{
12	return(foo());
13}
14
15int
16foo()
17{
18#define	MAXIMUM_RETRY	5
19	DB_ENV *dbenv;
20	DB *dbp;
21	DBT key, data;
22	DB_TXN *tid;
23	int fail, ret, t_ret;
24])
25m4_indent([dnl
26for (fail = 0;;) {
27	/* Begin the transaction. */
28	if ((ret = dbenv-__GT__txn_begin(dbenv, NULL, &tid, 0)) != 0) {
29		dbenv-__GT__err(dbenv, ret, "dbenv-__GT__txn_begin");
30		exit (1);
31	}
32m4_blank
33	/* Store the key. */
34	switch (ret = dbp-__GT__put(dbp, tid, &key, &data, 0)) {
35	case 0:
36		/* Success: commit the change. */
37		printf("db: %s: key stored.\n", (char *)key.data);
38		if ((ret = tid-__GT__commit(tid, 0)) != 0) {
39			dbenv-__GT__err(dbenv, ret, "DB_TXN-__GT__commit");
40			exit (1);
41		}
42		return (0);
43	case DB_LOCK_DEADLOCK:
44	default:
45		/* Failure: retry the operation. */
46		if ((t_ret = tid-__GT__abort(tid)) != 0) {
47			dbenv-__GT__err(dbenv, t_ret, "DB_TXN-__GT__abort");
48			exit (1);
49		}
50		if (fail++ == MAXIMUM_RETRY)
51			return (ret);
52		continue;
53	}
54}])
55m4_ignore([}])
56