From fe6cac45c744ed2937e9905f779244d93142f2db Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Mon, 17 Dec 2012 14:56:20 +0100 Subject: Fix driver_monitor_process() ASSERT --- erts/emulator/beam/erl_port.h | 6 ++++-- erts/emulator/beam/io.c | 16 ++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'erts/emulator') diff --git a/erts/emulator/beam/erl_port.h b/erts/emulator/beam/erl_port.h index f4d73e716a..fb07f3d5bc 100644 --- a/erts/emulator/beam/erl_port.h +++ b/erts/emulator/beam/erl_port.h @@ -430,7 +430,7 @@ ERTS_GLB_INLINE void erts_port_release(Port *); ERTS_GLB_INLINE Port *erts_thr_id2port_sflgs(Eterm id, Uint32 invalid_sflgs); ERTS_GLB_INLINE void erts_thr_port_release(Port *prt); #endif -ERTS_GLB_INLINE Port *erts_thr_drvport2port_raw(ErlDrvPort); +ERTS_GLB_INLINE Port *erts_thr_drvport2port_raw(ErlDrvPort, int); ERTS_GLB_INLINE Port *erts_drvport2port_raw(ErlDrvPort drvport); ERTS_GLB_INLINE Port *erts_drvport2port(ErlDrvPort, erts_aint32_t *); ERTS_GLB_INLINE Port *erts_drvportid2port(Eterm); @@ -622,7 +622,7 @@ erts_thr_port_release(Port *prt) #endif ERTS_GLB_INLINE Port* -erts_thr_drvport2port_raw(ErlDrvPort drvport) +erts_thr_drvport2port_raw(ErlDrvPort drvport, int lock_pdl) { #if ERTS_ENABLE_LOCK_CHECK int emu_thread = erts_lc_is_emu_thr(); @@ -631,6 +631,8 @@ erts_thr_drvport2port_raw(ErlDrvPort drvport) return NULL; else { Port *prt = (Port *) drvport; + if (lock_pdl && prt->port_data_lock) + driver_pdl_lock(prt->port_data_lock); #if ERTS_ENABLE_LOCK_CHECK if (!ERTS_IS_CRASH_DUMPING) { if (emu_thread) { diff --git a/erts/emulator/beam/io.c b/erts/emulator/beam/io.c index b2111c52e9..e466f0e299 100644 --- a/erts/emulator/beam/io.c +++ b/erts/emulator/beam/io.c @@ -82,9 +82,11 @@ static void pdl_init(void); #ifdef ERTS_SMP static void driver_monitor_lock_pdl(Port *p); static void driver_monitor_unlock_pdl(Port *p); +#define DRV_MONITOR_LOOKUP_PORT_LOCK_PDL(Port) erts_thr_drvport2port_raw((Port), 1) #define DRV_MONITOR_LOCK_PDL(Port) driver_monitor_lock_pdl(Port) #define DRV_MONITOR_UNLOCK_PDL(Port) driver_monitor_unlock_pdl(Port) #else +#define DRV_MONITOR_LOOKUP_PORT_LOCK_PDL(Port) erts_thr_drvport2port_raw((Port), 0) #define DRV_MONITOR_LOCK_PDL(Port) /* nothing */ #define DRV_MONITOR_UNLOCK_PDL(Port) /* nothing */ #endif @@ -95,7 +97,7 @@ static void driver_monitor_unlock_pdl(Port *p); static ERTS_INLINE ErlIOQueue* drvport2ioq(ErlDrvPort drvport) { - Port *prt = erts_thr_drvport2port_raw(drvport); + Port *prt = erts_thr_drvport2port_raw(drvport, 0); erts_aint32_t state = erts_atomic32_read_nob(&prt->state); if (state & ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP) return NULL; @@ -6739,9 +6741,7 @@ int driver_monitor_process(ErlDrvPort drvport, ErtsSchedulerData *sched = erts_get_scheduler_data(); #endif - prt = erts_thr_drvport2port_raw(drvport); - - DRV_MONITOR_LOCK_PDL(prt); + prt = DRV_MONITOR_LOOKUP_PORT_LOCK_PDL(drvport); state = erts_atomic32_read_nob(&prt->state); @@ -6820,9 +6820,7 @@ int driver_demonitor_process(ErlDrvPort drvport, ErtsSchedulerData *sched = erts_get_scheduler_data(); #endif - prt = erts_thr_drvport2port_raw(drvport); - - DRV_MONITOR_LOCK_PDL(prt); + prt = DRV_MONITOR_LOOKUP_PORT_LOCK_PDL(drvport); state = erts_atomic32_read_nob(&prt->state); @@ -6883,9 +6881,7 @@ ErlDrvTermData driver_get_monitored_process(ErlDrvPort drvport, ErtsSchedulerData *sched = erts_get_scheduler_data(); #endif - prt = erts_thr_drvport2port_raw(drvport); - - DRV_MONITOR_LOCK_PDL(prt); + prt = DRV_MONITOR_LOOKUP_PORT_LOCK_PDL(drvport); state = erts_atomic32_read_nob(&prt->state); if (state & ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP) { -- cgit v1.2.3