]> rtime.felk.cvut.cz Git - orte.git/commitdiff
ORTEDomain: Refactor objectEntry initialization
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 11 Mar 2015 19:58:58 +0000 (20:58 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 14 Mar 2015 17:04:12 +0000 (18:04 +0100)
orte/liborte/ORTEDomain.c

index 59b8fc123f1e230d50fcb9ed5f4d29fbe7406abf..0e2d74ee087b7ce8239775de18e6d18a772da530 100644 (file)
@@ -207,6 +207,27 @@ initTaskProp(TaskProp *tp, ORTEDomain *d, int buffSize)
   sock_init_udp(&tp->sock);
 }
 
+static int
+objectEntryInit(ObjectEntry *oe)
+{
+  pthread_condattr_t attr;
+
+  pthread_condattr_init(&attr);
+#if defined HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_DECL_CLOCK_MONOTONIC
+  if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0)
+    return -1;
+#endif
+  ObjectEntryHID_init_root_field(oe);
+  pthread_rwlock_init(&oe->objRootLock, NULL);
+  htimerRoot_init_queue(oe);
+  pthread_rwlock_init(&oe->htimRootLock, NULL);
+  pthread_cond_init(&oe->htimSendCond, &attr);
+  pthread_mutex_init(&oe->htimSendMutex, NULL);
+  oe->htimSendCondValue = 0;
+  oe->htimNeedWakeUp = ORTE_TRUE;
+  return 0;
+}
+
 ORTEDomain *
 ORTEDomainCreate(int domain, ORTEDomainProp *prop,
                 ORTEDomainAppEvents *events, Boolean manager)
@@ -222,7 +243,6 @@ ORTEDomainCreate(int domain, ORTEDomainProp *prop,
   int               i;
   uint16_t          port = 0;
   int               errno_save = 0;
-  pthread_condattr_t attr;
 
   debug(30, 2)  ("ORTEDomainCreate: %s compiled: %s,%s\n",
                 ORTE_PACKAGE_STRING, __DATE__, __TIME__);
@@ -255,20 +275,9 @@ ORTEDomainCreate(int domain, ORTEDomainProp *prop,
   assert(d->taskSend.mb.cdrCodec.wptr_max <= d->taskSend.mb.cdrCodec.buf_len);
   d->taskSend.mb.cdrCodec.data_endian = FLAG_ENDIANNESS;
 
-  //init structure objectEntry
-  pthread_condattr_init(&attr);
-#if defined HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_DECL_CLOCK_MONOTONIC
-  if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0)
-    goto err_free;
-#endif
-  ObjectEntryHID_init_root_field(&d->objectEntry);
-  pthread_rwlock_init(&d->objectEntry.objRootLock, NULL);
-  htimerRoot_init_queue(&d->objectEntry);
-  pthread_rwlock_init(&d->objectEntry.htimRootLock, NULL);
-  pthread_cond_init(&d->objectEntry.htimSendCond, &attr);
-  pthread_mutex_init(&d->objectEntry.htimSendMutex, NULL);
-  d->objectEntry.htimSendCondValue = 0;
-  d->objectEntry.htimNeedWakeUp = ORTE_TRUE;
+  if (objectEntryInit(&d->objectEntry) == -1)
+    goto err_sock;
+
   //publication,subscriptions
   d->publications.counter = d->subscriptions.counter = 0;
   CSTWriter_init_root_field(&d->publications);
@@ -745,7 +754,6 @@ err_domainProp:
   pthread_mutex_destroy(&d->objectEntry.htimSendMutex);
   pthread_rwlock_destroy(&d->objectEntry.htimRootLock);
   pthread_rwlock_destroy(&d->objectEntry.objRootLock);
-err_free:
   FREE(d);
   errno = errno_save;
   return NULL;