net: Enable SYS_LIGHTWEIGHT_PROT
net: Enable SYS_LIGHTWEIGHT_PROT

This option actually enables the use of the lwip_sys_mutex for
protecting concurrent access to such important lwIP resources as:
  select_cb_list (this is the one which orig flagged problem)
  sockets array
  mem stats (if enabled)
  heap (if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT was non-zero)
  memp pool allocs/frees
  netif->loop_last pbuf linked list
  pbuf reference counts
  ...

I first noticed this issue when I hit a crash while slamming the net
stack with a large number of TCP packets (I was actually sending 1k
data buffers from the TCPEchoServer mbed sample.)  It crashed in the
last line of this code snippet from event_callback:
  for (scb = select_cb_list; scb != NULL; scb = scb->next) {
    if (scb->sem_signalled == 0) {

It was crashing because scb had an invalid address so it generated a
bus fault.  I figured that memory was either corrupted or there was
some kind of concurrency issue.  In trying to determine which, I wanted
to walk through the select_cb_list linked list and see where it was
corrupted:
    (gdb) p scb
    $1 = (struct lwip_select_cb *) 0x85100080
    (gdb) p select_cb_list
    $2 = (struct lwip_select_cb *) 0x0

That was interesting, the head of the linked list was now NULL but it
must have had a non-NULL value when this loop started running or we
would have never gotten to the point where we hit this crash.

This was starting to look like a concurrency issue since the linked
list was modified out from underneath this thread.  Looking through the
source code for this function, I saw use of macros like
SYS_ARCH_PROTECT and SYS_ARCH_UNPROTECT which looked like they should
be providing the thead synchronization.  I disassembled the
event_callback() function in the debugger and saw no signs of the
usage of synchronizition APIs that I expected.  A search
through the code for the definition of these SYS_ARCH_UN/PROTECT
macros led me to discovering that they were actually ignored unless an
implementation defined them itself (the mbed version doesn't do so) or
the SYS_LIGHTWEIGHT_PROT macro is set to non-zero (the mbed version
didn't do this either).  Flipping the SYS_LIGHTWEIGHT_PROT macro on in
lwipopts.h fixed the crash I kept hitting, increased the size of the
code a bit, and unfortunately slows things down a bit since it now
actually serializes access to these data structures by making calls
to the RTOS sync APIs.

andreaslarssonublox/mbed,Archcady/mbed-os,bcostm/mbed-os,mbedmicro/mbed,sam-geek/mbed,jpbrucker/mbed,arostm/mbed-os,netzimme/mbed-os,monkiineko/mbed-os,ban4jp/mbed,mikaleppanen/mbed-os,Shengliang/mbed,logost/mbed,NXPmicro/mbed,FranklyDev/mbed,dbestm/mbed,rgrover/mbed,jeremybrodt/mbed,devanlai/mbed,dbestm/mbed,JasonHow44/mbed,monkiineko/mbed-os,ban4jp/mbed,EmuxEvans/mbed,nRFMesh/mbed-os,mbedmicro/mbed,fpiot/mbed-ats,bcostm/mbed-os,nvlsianpu/mbed,netzimme/mbed-os,Marcomissyou/mbed,karsev/mbed-os,jamesadevine/mbed,c1728p9/mbed-os,jrjang/mbed,naves-thiago/mbed-midi,fanghuaqi/mbed,masaohamanaka/mbed,bentwire/mbed,YarivCol/mbed-os,CalSol/mbed,betzw/mbed-os,catiedev/mbed-os,nRFMesh/mbed-os,FranklyDev/mbed,larks/mbed,DanKupiniak/mbed,Archcady/mbed-os,Sweet-Peas/mbed,rosterloh/mbed,jpbrucker/mbed,geky/mbed,maximmbed/mbed,K4zuki/mbed,Marcomissyou/mbed,tung7970/mbed-os,mnlipp/mbed,Timmmm/mbed,pbrook/mbed,karsev/mbed-os,pedromes/mbed,karsev/mbed-os,infinnovation/mbed-os,getopenmono/mbed,jferreir/mbed,CalSol/mbed,andcor02/mbed-os,kpurusho/mbed,nvlsianpu/mbed,adustm/mbed,autopulated/mbed,iriark01/mbed-drivers,GustavWi/mbed,RonEld/mbed,svogl/mbed-os,RonEld/mbed,naves-thiago/mbed-midi,fahhem/mbed-os,xcrespo/mbed,getopenmono/mbed,j-greffe/mbed-os,ryankurte/mbed-os,NXPmicro/mbed,Tiryoh/mbed,kjbracey-arm/mbed,alertby/mbed,HeadsUpDisplayInc/mbed,JasonHow44/mbed,arostm/mbed-os,al177/mbed,sg-/mbed-drivers,Tiryoh/mbed,pi19404/mbed,mbedmicro/mbed,theotherjimmy/mbed,K4zuki/mbed,bikeNomad/mbed,K4zuki/mbed,alertby/mbed,autopulated/mbed,arostm/mbed-os,infinnovation/mbed-os,pradeep-gr/mbed-os5-onsemi,larks/mbed,FranklyDev/mbed,kpurusho/mbed,brstew/MBED-BUILD,rosterloh/mbed,cvtsi2sd/mbed-os,bentwire/mbed,catiedev/mbed-os,HeadsUpDisplayInc/mbed,brstew/MBED-BUILD,kl-cruz/mbed-os,ryankurte/mbed-os,Timmmm/mbed,getopenmono/mbed,adustm/mbed,kl-cruz/mbed-os,bcostm/mbed-os,brstew/MBED-BUILD,catiedev/mbed-os,JasonHow44/mbed,RonEld/mbed,alertby/mbed,jrjang/mbed,rosterloh/mbed,j-greffe/mbed-os,j-greffe/mbed-os,c1728p9/mbed-os,fvincenzo/mbed-os,screamerbg/mbed,ban4jp/mbed,struempelix/mbed,jferreir/mbed,monkiineko/mbed-os,mmorenobarm/mbed-os,rgrover/mbed,bentwire/mbed,fahhem/mbed-os,pedromes/mbed,NXPmicro/mbed,mmorenobarm/mbed-os,mazimkhan/mbed-os,masaohamanaka/mbed,fvincenzo/mbed-os,Archcady/mbed-os,NordicSemiconductor/mbed,Marcomissyou/mbed,nabilbendafi/mbed,svastm/mbed,kpurusho/mbed,maximmbed/mbed,devanlai/mbed,YarivCol/mbed-os,DanKupiniak/mbed,ARM-software/mbed-beetle,logost/mbed,ryankurte/mbed-os,fahhem/mbed-os,ARM-software/mbed-beetle,netzimme/mbed-os,pradeep-gr/mbed-os5-onsemi,radhika-raghavendran/mbed-os5.1-onsemi,Willem23/mbed,j-greffe/mbed-os,larks/mbed,al177/mbed,andcor02/mbed-os,nRFMesh/mbed-os,arostm/mbed-os,NitinBhaskar/mbed,fpiot/mbed-ats,nabilbendafi/mbed,jamesadevine/mbed,brstew/MBED-BUILD,theotherjimmy/mbed,bulislaw/mbed-os,fanghuaqi/mbed,jferreir/mbed,pi19404/mbed,EmuxEvans/mbed,j-greffe/mbed-os,K4zuki/mbed,bulislaw/mbed-os,bcostm/mbed-os,mikaleppanen/mbed-os,HeadsUpDisplayInc/mbed,Shengliang/mbed,wodji/mbed,infinnovation/mbed-os,maximmbed/mbed,bentwire/mbed,theotherjimmy/mbed,Marcomissyou/mbed,jamesadevine/mbed,betzw/mbed-os,pbrook/mbed,Sweet-Peas/mbed,hwfwgrp/mbed,al177/mbed,monkiineko/mbed-os,bentwire/mbed,naves-thiago/mbed-midi,GustavWi/mbed,hwfwgrp/mbed,JasonHow44/mbed,tung7970/mbed-os,CalSol/mbed,Archcady/mbed-os,GustavWi/mbed,kl-cruz/mbed-os,K4zuki/mbed,kjbracey-arm/mbed,JasonHow44/mbed,bcostm/mbed-os,cvtsi2sd/mbed-os,jeremybrodt/mbed,rgrover/mbed,pbrook/mbed,Shengliang/mbed,jrjang/mbed,jrjang/mbed,tung7970/mbed-os,jeremybrodt/mbed,c1728p9/mbed-os,c1728p9/mbed-os,adamgreen/mbed,HeadsUpDisplayInc/mbed,bulislaw/mbed-os,jpbrucker/mbed,netzimme/mbed-os,bikeNomad/mbed,Sweet-Peas/mbed,Tiryoh/mbed,jeremybrodt/mbed,monkiineko/mbed-os,logost/mbed,mbedmicro/mbed,brstew/MBED-BUILD,larks/mbed,ban4jp/mbed,pradeep-gr/mbed-os5-onsemi,pedromes/mbed,kjbracey-arm/mbed,mazimkhan/mbed-os,catiedev/mbed-os,catiedev/mbed-os,Timmmm/mbed,rosterloh/mbed,dbestm/mbed,dbestm/mbed,pedromes/mbed,svogl/mbed-os,logost/mbed,Willem23/mbed,adustm/mbed,svogl/mbed-os,pedromes/mbed,tung7970/mbed-os-1,Sweet-Peas/mbed,GustavWi/mbed,c1728p9/mbed-os,mikaleppanen/mbed-os,fpiot/mbed-ats,adustm/mbed,screamerbg/mbed,alertby/mbed,YarivCol/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,svogl/mbed-os,andcor02/mbed-os,RonEld/mbed,nabilbendafi/mbed,pi19404/mbed,adustm/mbed,ryankurte/mbed-os,Timmmm/mbed,screamerbg/mbed,catiedev/mbed-os,masaohamanaka/mbed,tung7970/mbed-os-1,pi19404/mbed,bentwire/mbed,cvtsi2sd/mbed-os,adamgreen/mbed,maximmbed/mbed,mazimkhan/mbed-os,jferreir/mbed,nvlsianpu/mbed,struempelix/mbed,al177/mbed,rosterloh/mbed,svogl/mbed-os,getopenmono/mbed,pi19404/mbed,DanKupiniak/mbed,kl-cruz/mbed-os,NitinBhaskar/mbed,mmorenobarm/mbed-os,pradeep-gr/mbed-os5-onsemi,mbedmicro/mbed,wodji/mbed,netzimme/mbed-os,Archcady/mbed-os,jamesadevine/mbed,mnlipp/mbed,hwfwgrp/mbed,struempelix/mbed,mnlipp/mbed,infinnovation/mbed-os,NitinBhaskar/mbed,andcor02/mbed-os,jrjang/mbed,sam-geek/mbed,betzw/mbed-os,YarivCol/mbed-os,alertby/mbed,bulislaw/mbed-os,sg-/mbed-drivers,rosterloh/mbed,adamgreen/mbed,Tiryoh/mbed,pbrook/mbed,betzw/mbed-os,YarivCol/mbed-os,Sweet-Peas/mbed,fpiot/mbed-ats,xcrespo/mbed,fvincenzo/mbed-os,devanlai/mbed,Timmmm/mbed,fvincenzo/mbed-os,autopulated/mbed,RonEld/mbed,kpurusho/mbed,mnlipp/mbed,nabilbendafi/mbed,NXPmicro/mbed,mmorenobarm/mbed-os,Tiryoh/mbed,CalSol/mbed,radhika-raghavendran/mbed-os5.1-onsemi,wodji/mbed,struempelix/mbed,infinnovation/mbed-os,tung7970/mbed-os-1,adamgreen/mbed,struempelix/mbed,rgrover/mbed,NXPmicro/mbed,andcor02/mbed-os,wodji/mbed,screamerbg/mbed,mazimkhan/mbed-os,mikaleppanen/mbed-os,svastm/mbed,arostm/mbed-os,tung7970/mbed-os-1,masaohamanaka/mbed,larks/mbed,RonEld/mbed,j-greffe/mbed-os,Shengliang/mbed,monkiineko/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,naves-thiago/mbed-midi,HeadsUpDisplayInc/mbed,svastm/mbed,fahhem/mbed-os,nvlsianpu/mbed,getopenmono/mbed,0xc0170/mbed-drivers,xcrespo/mbed,xcrespo/mbed,bikeNomad/mbed,autopulated/mbed,xcrespo/mbed,bcostm/mbed-os,jeremybrodt/mbed,bremoran/mbed-drivers,arostm/mbed-os,Willem23/mbed,Marcomissyou/mbed,devanlai/mbed,geky/mbed,jferreir/mbed,geky/mbed,karsev/mbed-os,naves-thiago/mbed-midi,theotherjimmy/mbed,EmuxEvans/mbed,autopulated/mbed,kjbracey-arm/mbed,NordicSemiconductor/mbed,Marcomissyou/mbed,mikaleppanen/mbed-os,NitinBhaskar/mbed,FranklyDev/mbed,dbestm/mbed,devanlai/mbed,fahhem/mbed-os,nRFMesh/mbed-os,hwfwgrp/mbed,Shengliang/mbed,EmuxEvans/mbed,al177/mbed,andcor02/mbed-os,geky/mbed,fanghuaqi/mbed,hwfwgrp/mbed,NordicSemiconductor/mbed,adamgreen/mbed,GustavWi/mbed,NitinBhaskar/mbed,DanKupiniak/mbed,K4zuki/mbed,alertby/mbed,0xc0170/mbed-drivers,andreaslarssonublox/mbed,Timmmm/mbed,nRFMesh/mbed-os,svastm/mbed,jpbrucker/mbed,radhika-raghavendran/mbed-os5.1-onsemi,logost/mbed,svogl/mbed-os,Willem23/mbed,brstew/MBED-BUILD,mmorenobarm/mbed-os,fpiot/mbed-ats,al177/mbed,fanghuaqi/mbed,nvlsianpu/mbed,devanlai/mbed,screamerbg/mbed,cvtsi2sd/mbed-os,mazimkhan/mbed-os,betzw/mbed-os,ban4jp/mbed,betzw/mbed-os,cvtsi2sd/mbed-os,infinnovation/mbed-os,tung7970/mbed-os,kpurusho/mbed,wodji/mbed,kpurusho/mbed,adustm/mbed,adamgreen/mbed,CalSol/mbed,jrjang/mbed,larks/mbed,cvtsi2sd/mbed-os,pi19404/mbed,geky/mbed,karsev/mbed-os,pradeep-gr/mbed-os5-onsemi,struempelix/mbed,ryankurte/mbed-os,jferreir/mbed,ban4jp/mbed,pbrook/mbed,masaohamanaka/mbed,fanghuaqi/mbed,JasonHow44/mbed,tung7970/mbed-os-1,NXPmicro/mbed,Tiryoh/mbed,CalSol/mbed,andreaslarssonublox/mbed,Shengliang/mbed,naves-thiago/mbed-midi,sam-geek/mbed,mmorenobarm/mbed-os,bulislaw/mbed-os,bremoran/mbed-drivers,andreaslarssonublox/mbed,bikeNomad/mbed,autopulated/mbed,jpbrucker/mbed,nvlsianpu/mbed,wodji/mbed,netzimme/mbed-os,andreaslarssonublox/mbed,karsev/mbed-os,HeadsUpDisplayInc/mbed,bulislaw/mbed-os,maximmbed/mbed,bikeNomad/mbed,ARM-software/mbed-beetle,pradeep-gr/mbed-os5-onsemi,mikaleppanen/mbed-os,c1728p9/mbed-os,theotherjimmy/mbed,tung7970/mbed-os,NordicSemiconductor/mbed,fvincenzo/mbed-os,Willem23/mbed,Archcady/mbed-os,fpiot/mbed-ats,pedromes/mbed,maximmbed/mbed,nabilbendafi/mbed,kl-cruz/mbed-os,sam-geek/mbed,FranklyDev/mbed,nRFMesh/mbed-os,logost/mbed,pbrook/mbed,mnlipp/mbed,sam-geek/mbed,ARM-software/mbed-beetle,YarivCol/mbed-os,dbestm/mbed,mnlipp/mbed,xcrespo/mbed,EmuxEvans/mbed,ryankurte/mbed-os,jamesadevine/mbed,getopenmono/mbed,nabilbendafi/mbed,mazimkhan/mbed-os,iriark01/mbed-drivers,EmuxEvans/mbed,hwfwgrp/mbed,masaohamanaka/mbed,Sweet-Peas/mbed,fahhem/mbed-os,rgrover/mbed,svastm/mbed,theotherjimmy/mbed,kl-cruz/mbed-os,radhika-raghavendran/mbed-os5.1-onsemi,screamerbg/mbed,jpbrucker/mbed,jamesadevine/mbed