Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit b1887d5

Browse files
committed
Debug for client_contexts
1 parent 06fb0ef commit b1887d5

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

interface/mmal/vc/mmal_vc_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef struct MMAL_COMPONENT_MODULE_T
8585

8686
MMAL_BOOL_T event_ctx_initialised;
8787
MMAL_VC_CLIENT_BUFFER_CONTEXT_T event_ctx; /**< Used as the ctx for event buffers */
88+
uint32_t event_ctx_handle; /**< Used as the ctx for event buffers */
8889
} MMAL_COMPONENT_MODULE_T;
8990

9091

@@ -226,7 +227,7 @@ static MMAL_STATUS_T mmal_vc_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb
226227
for (i = 0; i < pool->headers_num; i++)
227228
{
228229
drv = mmal_buffer_header_driver_data(pool->header[i]);
229-
drv->client_context = mmal_vc_allocate_client_context(&port->component->priv->module->event_ctx);
230+
drv->client_context = port->component->priv->module->event_ctx_handle;
230231
drv->magic = MMAL_MAGIC;
231232
}
232233

@@ -533,7 +534,6 @@ static void mmal_vc_port_send_callback(mmal_worker_buffer_from_host *msg)
533534
{
534535
MMAL_BUFFER_HEADER_T *buffer;
535536
MMAL_PORT_T *port;
536-
//FIXME
537537
MMAL_VC_CLIENT_BUFFER_CONTEXT_T *client_context = mmal_vc_lookup_client_context(msg->drvbuf.client_context);
538538

539539
vcos_assert(client_context);
@@ -805,6 +805,7 @@ static MMAL_STATUS_T mmal_vc_component_destroy(MMAL_COMPONENT_T *component)
805805
mmal_ports_free(component->clock, component->clock_num);
806806

807807
mmal_queue_destroy(component->priv->module->callback_queue);
808+
mmal_vc_release_client_context(&component->priv->module->event_ctx);
808809

809810
vcos_free(component->priv->module);
810811
component->priv->module = NULL;
@@ -815,6 +816,8 @@ static MMAL_STATUS_T mmal_vc_component_destroy(MMAL_COMPONENT_T *component)
815816
mmal_vc_release_client_component(component);
816817
mmal_vc_shm_exit();
817818
mmal_vc_deinit();
819+
mmal_vc_dump_client_components();
820+
mmal_vc_dump_client_contexts();
818821
return status;
819822
}
820823

@@ -1540,6 +1543,7 @@ static MMAL_STATUS_T mmal_vc_component_create(const char *name, MMAL_COMPONENT_T
15401543
module->event_ctx_initialised = MMAL_FALSE;
15411544
module->event_ctx.magic = MMAL_MAGIC;
15421545
module->event_ctx.callback_event = mmal_vc_port_send_event_callback;
1546+
module->event_ctx_handle = mmal_vc_allocate_client_context(&module->event_ctx);
15431547

15441548
/* populate component structure */
15451549
component->priv->pf_enable = mmal_vc_component_enable;

interface/mmal/vc/mmal_vc_client.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ void mmal_vc_release_client_component(MMAL_COMPONENT_T *component)
154154
vcos_mutex_unlock(&client_component_pool.lock);
155155
}
156156

157+
void mmal_vc_dump_client_components(void)
158+
{
159+
int i;
160+
int count = 0;
161+
162+
vcos_mutex_lock(&client_component_pool.lock);
163+
for (i=0; i<MAX_COMPONENT_HANDLES; i++)
164+
{
165+
if (client_component_pool.components[i].inuse)
166+
{
167+
LOG_ERROR("%s: Entry %d in use for context %p", __func__, i, client_component_pool.components[i].component);
168+
count++;
169+
}
170+
}
171+
vcos_mutex_unlock(&client_component_pool.lock);
172+
LOG_ERROR("%s: %u entries in use", __func__, count);
173+
}
174+
157175
#define MAX_CLIENT_CONTEXTS 128
158176

159177
typedef struct
@@ -209,7 +227,7 @@ void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
209227
int i;
210228

211229
vcos_mutex_lock(&client_context_pool.lock);
212-
for (i=0; i<MAX_COMPONENT_HANDLES; i++)
230+
for (i=0; i<MAX_CLIENT_CONTEXTS; i++)
213231
{
214232
if (client_context_pool.contexts[i].ctx == context)
215233
{
@@ -220,6 +238,24 @@ void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
220238
vcos_mutex_unlock(&client_context_pool.lock);
221239
}
222240

241+
void mmal_vc_dump_client_contexts(void)
242+
{
243+
int i;
244+
int count = 0;
245+
246+
vcos_mutex_lock(&client_context_pool.lock);
247+
for (i=0; i<MAX_CLIENT_CONTEXTS; i++)
248+
{
249+
if (client_context_pool.contexts[i].inuse)
250+
{
251+
LOG_ERROR("%s: Entry %d in use for context %p", __func__, i, client_context_pool.contexts[i].ctx);
252+
count++;
253+
}
254+
}
255+
vcos_mutex_unlock(&client_context_pool.lock);
256+
LOG_ERROR("%s: %u entries in use", __func__, count);
257+
}
258+
223259
/* One client per process/VC connection. Multiple threads may
224260
* be using a single client.
225261
*/

interface/mmal/vc/mmal_vc_client_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ MMAL_STATUS_T mmal_vc_send_message(MMAL_CLIENT_T *client,
7878

7979
uint32_t mmal_vc_allocate_client_component(MMAL_COMPONENT_T *component);
8080
void mmal_vc_release_client_component(MMAL_COMPONENT_T *component);
81+
void mmal_vc_dump_client_components(void);
8182

8283
uint32_t mmal_vc_allocate_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context);
8384
MMAL_VC_CLIENT_BUFFER_CONTEXT_T *mmal_vc_lookup_client_context(int index);
8485
void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context);
86+
void mmal_vc_dump_client_contexts(void);
8587
#endif
8688

0 commit comments

Comments
 (0)