diff --git a/src/db/dbEvent.c b/src/db/dbEvent.c index a460e7c4f..e609a3996 100644 --- a/src/db/dbEvent.c +++ b/src/db/dbEvent.c @@ -945,10 +945,9 @@ LOCAL void event_task (void *pParm) */ int epicsShareAPI db_start_events ( dbEventCtx ctx,const char *taskname, void (*init_func)(threadId), - void *init_func_arg, int priority_offset) + void *init_func_arg, unsigned osiPriority ) { struct event_user *evUser = (struct event_user *) ctx; - int taskpri; semMutexMustTake (evUser->firstque.writelock); @@ -961,8 +960,6 @@ int epicsShareAPI db_start_events ( return DB_EVENT_OK; } - taskpri = threadGetPrioritySelf (); - taskpri -= priority_offset; evUser->pendexit = FALSE; evUser->init_func = init_func; evUser->init_func_arg = init_func_arg; @@ -970,7 +967,7 @@ int epicsShareAPI db_start_events ( taskname = EVENT_PEND_NAME; } evUser->taskid = threadCreate ( - taskname, taskpri, threadGetStackSize(threadStackMedium), + taskname, osiPriority, threadGetStackSize(threadStackMedium), event_task, (void *)evUser); if (!evUser->taskid) { semMutexGive (evUser->firstque.writelock); diff --git a/src/db/dbEvent.h b/src/db/dbEvent.h index b3e95c2be..78875059a 100644 --- a/src/db/dbEvent.h +++ b/src/db/dbEvent.h @@ -50,7 +50,7 @@ typedef void EXTRALABORFUNC (void *extralabor_arg); epicsShareFunc dbEventCtx epicsShareAPI db_init_events (void); epicsShareFunc int epicsShareAPI db_start_events ( dbEventCtx ctx, const char *taskname, void (*init_func)(void *), - void *init_func_arg, int priority_offset); + void *init_func_arg, unsigned osiPriority ); epicsShareFunc void epicsShareAPI db_close_events (dbEventCtx ctx); epicsShareFunc void epicsShareAPI db_event_flow_ctrl_mode_on (dbEventCtx ctx); epicsShareFunc void epicsShareAPI db_event_flow_ctrl_mode_off (dbEventCtx ctx); diff --git a/src/db/dbServiceIO.cpp b/src/db/dbServiceIO.cpp index 996dff6ef..eabe1c54d 100644 --- a/src/db/dbServiceIO.cpp +++ b/src/db/dbServiceIO.cpp @@ -115,7 +115,6 @@ extern "C" void cacAttachClientCtx ( void * pPrivate ) dbEventSubscription dbServiceIO::subscribe ( struct dbAddr &addr, dbSubscriptionIO &subscr, unsigned mask ) { - static const int slightlyHigherPriority = -1; caClientCtx clientCtx; dbEventSubscription es; int status; @@ -132,10 +131,18 @@ dbEventSubscription dbServiceIO::subscribe ( struct dbAddr &addr, dbSubscription this->mutex.unlock (); return 0; } + + unsigned selfPriority = threadGetPrioritySelf (); + unsigned above; + threadBoolStatus tbs = threadLowestPriorityLevelAbove + (selfPriority, &above); + if ( tbs != tbsSuccess ) { + above = selfPriority; + } status = db_start_events ( this->ctx, "CAC-event", - cacAttachClientCtx, clientCtx, slightlyHigherPriority ); + cacAttachClientCtx, clientCtx, above ); if ( status ) { - db_close_events (this->ctx); + db_close_events ( this->ctx ); this->ctx = 0; return 0; } diff --git a/src/rsrv/caservertask.c b/src/rsrv/caservertask.c index 8e998e362..aa36864f4 100644 --- a/src/rsrv/caservertask.c +++ b/src/rsrv/caservertask.c @@ -136,11 +136,13 @@ struct client *create_base_client () */ struct client *create_client (SOCKET sock) { - static const unsigned slightlyLowerPriority = 1; int status; struct client *client; int true = TRUE; int addrSize; + unsigned selfPriority; + unsigned below; + threadBoolStatus tbs; /* * see TCP(4P) this seems to make unsolicited single events much @@ -228,8 +230,14 @@ struct client *create_client (SOCKET sock) return NULL; } - status = db_start_events (client->evuser, "CAS-event", - NULL, NULL, slightlyLowerPriority); + selfPriority = threadGetPrioritySelf (); + tbs = threadHighestPriorityLevelBelow (selfPriority, &below); + if ( tbs != tbsSuccess ) { + below = selfPriority; + } + + status = db_start_events ( client->evuser, "CAS-event", + NULL, NULL, below ); if (status != DB_EVENT_OK) { errlogPrintf("CAS: unable to start the event facility\n"); destroy_client (client);