tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
}
+/*
+ * Stupid/simple growable array implementation:
+ */
+
+static inline void *
+grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
+{
+ if ((nr + 1) > *max) {
+ if ((*max * 2) < (nr + 1))
+ *max = nr + 5;
+ else
+ *max = *max * 2;
+ ptr = realloc(ptr, *max * sz);
+ }
+ return ptr;
+}
+
+#define DECLARE_ARRAY(type, name) \
+ unsigned nr_ ## name, max_ ## name; \
+ type * name;
+
+#define APPEND(x, name) ({ \
+ (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
+ (x)->nr_ ## name ++; \
+})
+
#endif /* MSM_PRIV_H_ */
struct fd_bo *ring_bo;
/* reloc's table: */
- struct drm_msm_gem_submit_reloc *relocs;
- uint32_t nr_relocs, max_relocs;
+ DECLARE_ARRAY(struct drm_msm_gem_submit_reloc, relocs);
uint32_t size;
};
*/
struct {
/* bo's table: */
- struct drm_msm_gem_submit_bo *bos;
- uint32_t nr_bos, max_bos;
+ DECLARE_ARRAY(struct drm_msm_gem_submit_bo, bos);
/* cmd's table: */
- struct drm_msm_gem_submit_cmd *cmds;
- uint32_t nr_cmds, max_cmds;
+ DECLARE_ARRAY(struct drm_msm_gem_submit_cmd, cmds);
} submit;
/* should have matching entries in submit.bos: */
/* Note, only in parent ringbuffer */
- struct fd_bo **bos;
- uint32_t nr_bos, max_bos;
+ DECLARE_ARRAY(struct fd_bo *, bos);
/* should have matching entries in submit.cmds: */
- struct msm_cmd **cmds;
- uint32_t nr_cmds, max_cmds;
+ DECLARE_ARRAY(struct msm_cmd *, cmds);
/* List of physical cmdstream buffers (msm_cmd) assocated with this
* logical fd_ringbuffer.
return NULL;
}
-static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
-{
- if ((nr + 1) > *max) {
- if ((*max * 2) < (nr + 1))
- *max = nr + 5;
- else
- *max = *max * 2;
- ptr = realloc(ptr, *max * sz);
- }
- return ptr;
-}
-
-#define APPEND(x, name) ({ \
- (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
- (x)->nr_ ## name ++; \
-})
-
static struct msm_cmd *current_cmd(struct fd_ringbuffer *ring)
{
struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring);