+struct afb_apiset *afb_apiset_addref(struct afb_apiset *set)
+{
+ if (set)
+ __atomic_add_fetch(&set->refcount, 1, __ATOMIC_RELAXED);
+ return set;
+}
+
+void afb_apiset_unref(struct afb_apiset *set)
+{
+ if (set && !__atomic_sub_fetch(&set->refcount, 1, __ATOMIC_RELAXED)) {
+ afb_apiset_unref(set->subset);
+ free(set->apis);
+ free(set);
+ }
+}
+
+/**
+ * Create an apiset
+ */
+struct afb_apiset *afb_apiset_create(const char *name, int timeout, struct afb_apiset *subset)
+{
+ struct afb_apiset *set;
+
+ set = malloc((name ? strlen(name) : 0) + sizeof *set);
+ if (set) {
+ set->subset = afb_apiset_addref(subset);
+ set->apis = malloc(INCR * sizeof *set->apis);
+ set->count = 0;
+ set->timeout = timeout;
+ set->refcount = 1;
+ if (name)
+ strcpy(set->name, name);
+ else
+ set->name[0] = 0;
+ }
+ return set;
+}
+
+
+/**
+ * Get the API timeout of the set
+ * @param set the api set
+ * @return the timeout in seconds
+ */
+int afb_apiset_get_timeout(struct afb_apiset *set)
+{
+ return set->timeout;
+}
+
+/**
+ * Set the API timeout of the set
+ * @param set the api set
+ * @param to the timeout in seconds
+ */
+void afb_apiset_set_timeout(struct afb_apiset *set, int to)
+{
+ set->timeout = to;
+}
+
+/**
+ * Get the subset of the set
+ * @param set the api set
+ * @return the subset of set
+ */
+struct afb_apiset *afb_apiset_get_subset(struct afb_apiset *set)
+{
+ return set->subset;
+}
+
+/**
+ * Set the subset of the set
+ * @param set the api set
+ * @param subset the subset to set
+ */
+void afb_apiset_set_subset(struct afb_apiset *set, struct afb_apiset *subset)
+{
+ struct afb_apiset *tmp = set->subset;
+ set->subset = afb_apiset_addref(subset);
+ afb_apiset_unref(tmp);
+}
+