Пример #1
0
/*
 * database access
 */
void *data_access(void *record) {
    struct Phone_Entries *phone_entries = (struct Phone_Entries *)record; // Link our structures
    struct phone_record *person = phone_entries->record; // Link our record to our entries
    
    pthread_mutex_t *lock = phone_entries->mtx; // Link the mutex with a lock
    add_record(person); // Add the person
    pthread_mutex_unlock(lock); // Unlock the locked mutex
    pthread_mutex_lock(lock); // Lock the mutex
    remove_record(person->name); // Remove the record
    pthread_mutex_unlock(lock); // And lastly unlock again
    pthread_exit(NULL); // Exit when NULL
}
Пример #2
0
static int
findrec(struct cdb_make *cdbmp,
        const void *key, unsigned klen, unsigned hval,
        enum cdb_put_mode mode)
{
  struct cdb_rl *rl;
  struct cdb_rec *rp, *rs;
  unsigned r;
  int seeked = 0;
  int ret = 0;
  for(rl = cdbmp->cdb_rec[hval&255]; rl; rl = rl->next)
    for(rs = rl->rec, rp = rs + rl->cnt; --rp >= rs;) {
      if (rp->hval != hval)
	continue;
      /*XXX this explicit flush may be unnecessary having
       * smarter match() that looks into cdb_buf too, but
       * most of a time here spent in finding hash values
       * (above), not keys */
      if (!seeked && _cdb_make_flush(cdbmp) < 0)
        return -1;
      seeked = 1;
      r = match(cdbmp, rp->rpos, key, klen);
      if (!r)
	continue;
      if (r == 1)
	return -1;
      ret = 1;
      switch(mode) {
      case CDB_FIND_REMOVE:
        if (remove_record(cdbmp, rp->rpos, r) < 0)
          return -1;
	break;
      case CDB_FIND_FILL0:
	if (zerofill_record(cdbmp, rp->rpos, r) < 0)
          return -1;
	break;
      default: goto finish;
      }
      memmove(rp, rp + 1, (rs + rl->cnt - 1 - rp) * sizeof(*rp));
      --rl->cnt;
      --cdbmp->cdb_rcnt;
  }
finish:
  if (seeked && lseek(cdbmp->cdb_fd, cdbmp->cdb_dpos, SEEK_SET) < 0)
    return -1;
  return ret;
}
Пример #3
0
static DBusMessage *remove_service_record(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct service_adapter *serv_adapter = data;
	dbus_uint32_t handle;
	const char *sender;

	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle,
						DBUS_TYPE_INVALID) == FALSE)
		return NULL;

	sender = dbus_message_get_sender(msg);

	if (remove_record(conn, sender, serv_adapter, handle) < 0)
		return btd_error_not_available(msg);

	return dbus_message_new_method_return(msg);
}