mirror of
https://github.com/RoganDawes/P4wnP1_aloa.git
synced 2025-03-17 21:31:56 +01:00
Fix: service - event subsystem: assure RegisterReceiver doesn't return before receiver is added
This commit is contained in:
parent
776b166145
commit
9f9ea3798a
@ -60,7 +60,6 @@ func (em *EventManager) Write(p []byte) (n int, err error) {
|
||||
|
||||
func (em *EventManager) RegisterReceiver(filterEventType int64) *EventReceiver {
|
||||
// fmt.Println("!!!Event listener registered for " + strconv.Itoa(int(filterEventType)))
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
er := &EventReceiver{
|
||||
EventQueue: make(chan *pb.Event, 10), //allow buffering 10 events per receiver
|
||||
@ -133,11 +132,11 @@ func (em *EventManager) register_unregister() {
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case er := <- em.registerReceiver:
|
||||
case er := <- em.registerReceiver: // Fix: this would already unlock the RegisterReceiver method ...
|
||||
em.registeredReceiversMutex.Lock()
|
||||
em.registeredReceivers[er] = true
|
||||
em.registeredReceivers[er] = true // ... but only at this point it is assured that the Listener receives events ...
|
||||
fmt.Printf("Registered event receiver type %d, overall receiver count %d\n", er.FilterEventType, len(em.registeredReceivers))
|
||||
// signal registration by closing wait channel
|
||||
// ... this is solved by signaling the successful registration by closing wait channel (the registerReceiver method doesn't return before this channel is closed)
|
||||
close(er.waitRegister)
|
||||
em.registeredReceiversMutex.Unlock()
|
||||
case er := <- em.unregisterReceiver:
|
||||
|
86
service/SubSysGpio.go
Normal file
86
service/SubSysGpio.go
Normal file
@ -0,0 +1,86 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
pb "github.com/mame82/P4wnP1_go/proto"
|
||||
)
|
||||
|
||||
type GpioPinState byte
|
||||
const (
|
||||
GPIO_PIN_STATE_DISABLED GpioPinState = iota
|
||||
GPIO_PIN_STATE_INPUT
|
||||
GPIO_PIN_STATE_OUTPUT
|
||||
//GPIO_PIN_STATE_PWM
|
||||
//GPIO_PIN_STATE_CLOCK
|
||||
)
|
||||
|
||||
type GpioPin struct {
|
||||
*sync.Mutex
|
||||
Number pb.GPIONum
|
||||
InUse bool
|
||||
State GpioPinState
|
||||
EdgeDetectState pb.GPIOInEdge
|
||||
PullUpDown pb.GPIOInPullUpDown
|
||||
}
|
||||
|
||||
var PI_GPIO_NUMS = []pb.GPIONum{
|
||||
pb.GPIONum_NUM_2, //SDA1
|
||||
pb.GPIONum_NUM_3, //SCL1
|
||||
pb.GPIONum_NUM_4,
|
||||
pb.GPIONum_NUM_5,
|
||||
pb.GPIONum_NUM_6,
|
||||
pb.GPIONum_NUM_7, //CE1
|
||||
pb.GPIONum_NUM_8, //CE0
|
||||
pb.GPIONum_NUM_9, //MISO
|
||||
pb.GPIONum_NUM_10, //MOSI
|
||||
pb.GPIONum_NUM_11, //SCLK
|
||||
pb.GPIONum_NUM_12,
|
||||
pb.GPIONum_NUM_13,
|
||||
pb.GPIONum_NUM_14, //TXD0
|
||||
pb.GPIONum_NUM_15, //RXD0
|
||||
pb.GPIONum_NUM_16,
|
||||
pb.GPIONum_NUM_17,
|
||||
pb.GPIONum_NUM_18,
|
||||
pb.GPIONum_NUM_19,
|
||||
pb.GPIONum_NUM_20,
|
||||
pb.GPIONum_NUM_21,
|
||||
pb.GPIONum_NUM_22,
|
||||
pb.GPIONum_NUM_23,
|
||||
pb.GPIONum_NUM_24,
|
||||
pb.GPIONum_NUM_25,
|
||||
pb.GPIONum_NUM_26,
|
||||
pb.GPIONum_NUM_27,
|
||||
}
|
||||
/*
|
||||
var PI_GPIO_NUMS = []pb.GPIONum{
|
||||
pb.GPIONum_NUM_2, //SDA1
|
||||
pb.GPIONum_NUM_3, //SCL1
|
||||
pb.GPIONum_NUM_4,
|
||||
pb.GPIONum_NUM_17,
|
||||
pb.GPIONum_NUM_27,
|
||||
pb.GPIONum_NUM_22,
|
||||
pb.GPIONum_NUM_10, //MOSI
|
||||
pb.GPIONum_NUM_9, //MISO
|
||||
pb.GPIONum_NUM_11, //SCLK
|
||||
pb.GPIONum_NUM_5,
|
||||
pb.GPIONum_NUM_6,
|
||||
pb.GPIONum_NUM_13,
|
||||
pb.GPIONum_NUM_19,
|
||||
pb.GPIONum_NUM_26,
|
||||
pb.GPIONum_NUM_14, //TXD0
|
||||
pb.GPIONum_NUM_15, //RXD0
|
||||
pb.GPIONum_NUM_18,
|
||||
pb.GPIONum_NUM_23,
|
||||
pb.GPIONum_NUM_24,
|
||||
pb.GPIONum_NUM_25,
|
||||
pb.GPIONum_NUM_8, //CE0
|
||||
pb.GPIONum_NUM_7, //CE1
|
||||
pb.GPIONum_NUM_12,
|
||||
pb.GPIONum_NUM_16,
|
||||
pb.GPIONum_NUM_20,
|
||||
pb.GPIONum_NUM_21,
|
||||
}
|
||||
*/
|
||||
type GpioManager struct {
|
||||
availableGpioPins []byte
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user