home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / tek / kn / linux / exec.c next >
Encoding:
C/C++ Source or Header  |  2001-05-12  |  14.0 KB  |  719 lines

  1.  
  2. /*
  3. **    TEKlib
  4. **    (C) 2001 TEK neoscientists
  5. **    all rights reserved.
  6. **
  7. **    tek/kn/linux/exec.c
  8. **    posix kernel backend
  9. **
  10. **    written for Linux - but this might be posix compliant, well mostly
  11. */
  12.  
  13.  
  14. #include <tek/type.h>
  15. #include <tek/kn/exec.h>
  16. #include <tek/kn/linux/exec.h>
  17.  
  18.  
  19. /* 
  20. **    MEMORY ALLOCATION
  21. **
  22. */
  23.  
  24. TAPTR kn_alloc(TUINT size)
  25. {
  26.     TUINT *mem = malloc(size + sizeof(void *) * 2);
  27.     if (mem)
  28.     {
  29.         *mem = size;
  30.         return (TAPTR) (mem + 2);
  31.     }
  32.     return TNULL;
  33. }
  34.  
  35.  
  36. TAPTR kn_alloc0(TUINT size)
  37. {
  38.     TUINT *mem = malloc(size + sizeof(void *) * 2);
  39.     if (mem)
  40.     {
  41.         *mem = size;
  42.         memset(mem + 2, 0, size);
  43.         return (TAPTR) (mem + 2);
  44.     }
  45.     return TNULL;
  46. }
  47.  
  48.  
  49. TVOID kn_free(TAPTR mem)
  50. {
  51.     free(((TUINT *) mem) - 2);
  52. }
  53.  
  54.  
  55. TAPTR kn_realloc(TAPTR oldmem, TUINT newsize)
  56. {
  57.     TUINT *mem = realloc(((TUINT *) oldmem) - 2, newsize + sizeof(void *) * 2);
  58.     if (mem)
  59.     {
  60.         *mem = newsize;
  61.         return (TAPTR) (mem + 2);
  62.     }
  63.     return TNULL;
  64. }
  65.  
  66.  
  67. TUINT kn_getsize(TAPTR mem)
  68. {
  69.     return *(((TUINT *) mem) - 2);
  70. }
  71.  
  72.  
  73.  
  74. /* 
  75. **    MEMORY MANIPULATION
  76. **
  77. */
  78.  
  79. TVOID kn_memcopy(TAPTR from, TAPTR to, TUINT numbytes)
  80. {
  81.     memcpy(to, from, numbytes);
  82. }
  83.  
  84.  
  85. TVOID kn_memcopy32(TAPTR from, TAPTR to, TUINT numbytes)
  86. {
  87.     memcpy(to, from, numbytes);
  88. }
  89.  
  90.  
  91. TVOID kn_memset(TAPTR dest, TUINT numbytes, TUINT8 fillval)
  92. {
  93.     memset(dest, (int) fillval, numbytes);
  94. }
  95.  
  96.  
  97. TVOID kn_memset32(TAPTR dest, TUINT numbytes, TUINT fillval)
  98. {
  99.     TUINT i, *m = dest;
  100.     for (i = 0; i < numbytes >> 2; ++i)
  101.     {
  102.         *m++ = fillval;
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. /* 
  109. **    LOCK
  110. **
  111. */
  112.  
  113. TBOOL kn_initlock(TKNOB *lock)
  114. {
  115.     if (sizeof(TKNOB) >= sizeof(pthread_mutex_t))
  116.     {
  117.         pthread_mutexattr_t attr;
  118.         pthread_mutexattr_init(&attr);
  119.         /*pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);*/
  120.         if (pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP) == 0)
  121.         {
  122.             pthread_mutex_init((pthread_mutex_t *) lock, &attr);
  123.             pthread_mutexattr_destroy(&attr);
  124.             return TTRUE;
  125.         }
  126.         pthread_mutexattr_destroy(&attr);
  127.     }
  128.     else
  129.     {
  130.         pthread_mutex_t *mut = kn_alloc(sizeof(pthread_mutex_t));
  131.         if (mut)
  132.         {
  133.             pthread_mutexattr_t attr;
  134.             pthread_mutexattr_init(&attr);
  135.             /*pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);*/
  136.             if (pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP) == 0)
  137.             {
  138.                 pthread_mutex_init(mut, &attr);
  139.                 pthread_mutexattr_destroy(&attr);
  140.                 *((pthread_mutex_t **) lock) = mut;
  141.                 return TTRUE;
  142.             }
  143.             pthread_mutexattr_destroy(&attr);
  144.         }
  145.     }
  146.  
  147.     dbkprintf(20,"*** TEKLIB kernel: could not create lock\n");
  148.     return TFALSE;
  149. }
  150.  
  151.  
  152. TVOID kn_destroylock(TKNOB *lock)
  153. {
  154.     if (sizeof(TKNOB) >= sizeof(pthread_mutex_t))
  155.     {
  156.         if (pthread_mutex_destroy((pthread_mutex_t *) lock) == EBUSY) dbkprintf(10,"*** kn_destroylock(0): mutex_destroy busy!\n");
  157.     }
  158.     else
  159.     {
  160.         if (pthread_mutex_destroy(*((pthread_mutex_t **) lock)) == EBUSY) dbkprintf(10,"*** kn_destroylock(1): mutex_destroy busy!\n");
  161.         kn_free(*((pthread_mutex_t **) lock));
  162.     }
  163. }
  164.  
  165.  
  166. TVOID kn_lock(TKNOB *lock)
  167. {
  168.     if (sizeof(TKNOB) >= sizeof(pthread_mutex_t))
  169.     {
  170.         if (pthread_mutex_lock((pthread_mutex_t *) lock)) dbkprintf(10,"*** kn_lock(0): mutex_lock\n");
  171.     }
  172.     else
  173.     {
  174.         if (pthread_mutex_lock(*((pthread_mutex_t **) lock))) dbkprintf(10,"*** kn_lock(1): mutex_lock\n");
  175.     }
  176. }
  177.  
  178.  
  179. TVOID kn_unlock(TKNOB *lock)
  180. {
  181.     if (sizeof(TKNOB) >= sizeof(pthread_mutex_t))
  182.     {
  183.         if (pthread_mutex_unlock((pthread_mutex_t *) lock)) dbkprintf(10,"*** kn_unlock(0): mutex_unlock\n");
  184.     }
  185.     else
  186.     {
  187.         if (pthread_mutex_unlock(*((pthread_mutex_t **) lock))) dbkprintf(10,"*** kn_unlock(1): mutex_unlock\n");
  188.     }
  189. }
  190.  
  191.  
  192.  
  193. /* 
  194. **    TIMER
  195. **
  196. */
  197.  
  198. TBOOL kn_inittimer(TKNOB *timer)
  199. {
  200.     if (sizeof(TKNOB) >= sizeof(struct posixtimer))
  201.     {
  202.         struct posixtimer *t = (struct posixtimer *) timer;
  203.         if (pthread_cond_init(&t->cond, NULL) == 0)
  204.         {
  205.             pthread_mutex_init(&t->mutex, NULL);
  206.             gettimeofday(&t->timeval, NULL);
  207.             return TTRUE;
  208.         }
  209.     }
  210.     else
  211.     {
  212.         struct posixtimer *t = kn_alloc(sizeof(struct posixtimer));
  213.         if (t)
  214.         {
  215.             if (pthread_cond_init(&t->cond, NULL) == 0)
  216.             {
  217.                 pthread_mutex_init(&t->mutex, NULL);
  218.                 gettimeofday(&t->timeval, NULL);
  219.                 *((struct posixtimer **) timer) = t;
  220.                 return TTRUE;
  221.             }
  222.             kn_free(t);
  223.         }
  224.     }
  225.  
  226.     dbkprintf(20,"*** TEKLIB kernel: could not create timer\n");
  227.     return TFALSE;
  228. }
  229.  
  230.  
  231. TVOID kn_destroytimer(TKNOB *timer)
  232. {
  233.     if (sizeof(TKNOB) >= sizeof(struct posixtimer))
  234.     {
  235.         struct posixtimer *t = (struct posixtimer *) timer;
  236.  
  237.         if (pthread_mutex_destroy(&t->mutex)) dbkprintf(10,"*** kn_destroytimer: mutex_destroy(0)\n");
  238.         if (pthread_cond_destroy(&t->cond)) dbkprintf(10,"*** kn_destroytimer: cond_destroy(0)\n");
  239.     }
  240.     else
  241.     {
  242.         struct posixtimer *t = *((struct posixtimer **) timer);
  243.  
  244.         if (pthread_mutex_destroy(&t->mutex)) dbkprintf(10,"*** kn_destroytimer: mutex_destroy(1)\n");
  245.         if (pthread_cond_destroy(&t->cond)) dbkprintf(10,"*** kn_destroytimer: cond_destroy(1)\n");
  246.  
  247.         kn_free(t);
  248.     }
  249. }
  250.  
  251.  
  252. TVOID kn_querytimer(TKNOB *timer, TTIME *tektime)
  253. {
  254.     float sec;
  255.     struct posixtimer *t;
  256.  
  257.     if (sizeof(TKNOB) >= sizeof(struct posixtimer))
  258.     {
  259.         t = (struct posixtimer *) timer;
  260.     }
  261.     else
  262.     {
  263.         t = *((struct posixtimer **) timer);
  264.     }
  265.     
  266.     gettimeofday((struct timeval *) tektime, NULL);
  267.  
  268.     sec =     ((float)(tektime->sec - t->timeval.tv_sec)) + 
  269.         0.000001f * tektime->usec - 0.000001f * t->timeval.tv_usec;
  270.  
  271.     tektime->sec = (TUINT) sec;
  272.     tektime->usec = (sec - tektime->sec) * 1000000;
  273. }
  274.  
  275.  
  276. TVOID kn_timedelay(TKNOB *timer, TTIME *tektime)
  277. {
  278.     if (tektime)
  279.     {
  280.         struct timeval now;
  281.         struct timespec then;
  282.     
  283.         struct posixtimer *t;
  284.         if (sizeof(TKNOB) >= sizeof(struct posixtimer))
  285.         {
  286.             t = (struct posixtimer *) timer;
  287.         }
  288.         else
  289.         {
  290.             t = *((struct posixtimer **) timer);
  291.         }
  292.     
  293.         pthread_mutex_lock(&t->mutex);
  294.  
  295.         gettimeofday(&now, NULL);
  296.     
  297.         then.tv_sec = now.tv_sec + tektime->sec;
  298.         then.tv_nsec = now.tv_usec + tektime->usec;
  299.         if (then.tv_nsec >= 1000000)
  300.         {
  301.             then.tv_nsec -= 1000000;
  302.             then.tv_sec++;
  303.         }
  304.         then.tv_nsec *= 1000;
  305.     
  306.         if (pthread_cond_timedwait(&t->cond, &t->mutex, &then) != ETIMEDOUT)
  307.         {
  308.             dbkprintf(10,"*** TEKLIB kn_timedelay: pthread_cond_timedwait\n");
  309.         }
  310.  
  311.         pthread_mutex_unlock(&t->mutex);
  312.     }
  313. }
  314.  
  315.  
  316. TVOID kn_resettimer(TKNOB *timer)
  317. {
  318.     struct posixtimer *t;
  319.  
  320.     if (sizeof(TKNOB) >= sizeof(struct posixtimer))
  321.     {
  322.         t = (struct posixtimer *) timer;
  323.     }
  324.     else
  325.     {
  326.         t = *((struct posixtimer **) timer);
  327.     }
  328.  
  329.     gettimeofday(&t->timeval, NULL);
  330. }
  331.  
  332.  
  333.  
  334. /* 
  335. **    EVENT
  336. **
  337. */
  338.  
  339. TBOOL kn_initevent(TKNOB *event)
  340. {
  341.     if (sizeof(TKNOB) >= sizeof(struct posixevent))
  342.     {
  343.         struct posixevent *evt = (struct posixevent *) event;
  344.         if (pthread_cond_init(&evt->cond, NULL) == 0)
  345.         {
  346.             pthread_mutex_init(&evt->mutex, NULL);
  347.             evt->status = 0;
  348.             return TTRUE;
  349.         }
  350.     }
  351.     else
  352.     {
  353.         struct posixevent *evt = kn_alloc(sizeof(struct posixevent));
  354.         if (evt)
  355.         {
  356.             if (pthread_cond_init(&evt->cond, NULL) == 0)
  357.             {
  358.                 pthread_mutex_init(&evt->mutex, NULL);
  359.                 evt->status = 0;
  360.                 *((struct posixevent **) event) = evt;
  361.                 return TTRUE;
  362.             }
  363.             kn_free(evt);
  364.         }
  365.     }
  366.  
  367.     dbkprintf(20,"*** TEKLIB kernel: could not create event\n");
  368.     return TFALSE;
  369. }
  370.  
  371.  
  372. TVOID kn_destroyevent(TKNOB *event)
  373. {
  374.     if (sizeof(TKNOB) >= sizeof(struct posixevent))
  375.     {
  376.         struct posixevent *evt = (struct posixevent *) event;
  377.         if (pthread_mutex_destroy(&evt->mutex)) dbkprintf(10,"*** kn_destroyevent: mutex_destroy(0)\n");
  378.         if (pthread_cond_destroy(&evt->cond)) dbkprintf(10,"*** kn_destroyevent: cond_destroy(0)\n");
  379.     }
  380.     else
  381.     {
  382.         struct posixevent *evt = *((struct posixevent **) event);
  383.         if (pthread_mutex_destroy(&evt->mutex)) dbkprintf(10,"*** kn_destroyevent: mutex_destroy(1)\n");
  384.         if (pthread_cond_destroy(&evt->cond)) dbkprintf(10,"*** kn_destroyevent: cond_destroy(1)\n");
  385.         kn_free(evt);
  386.     }
  387. }
  388.  
  389.  
  390. TVOID kn_doevent(TKNOB *event)
  391. {
  392.     struct posixevent *evt;
  393.     if (sizeof(TKNOB) >= sizeof(struct posixevent))
  394.     {
  395.         evt = (struct posixevent *) event;
  396.     }
  397.     else
  398.     {
  399.         evt = *((struct posixevent **) event);
  400.     }
  401.     if (pthread_mutex_lock(&evt->mutex)) dbkprintf(10,"*** kn_doevent: mutex_lock\n");
  402.     evt->status = 1;
  403.     if (pthread_cond_signal(&evt->cond)) dbkprintf(10,"*** kn_doevent: cond_signal\n");
  404.     if (pthread_mutex_unlock(&evt->mutex)) dbkprintf(10,"*** kn_doevent: mutex_unlock\n");
  405. }
  406.  
  407.  
  408. TVOID kn_waitevent(TKNOB *event)
  409. {
  410.     struct posixevent *evt;
  411.     if (sizeof(TKNOB) >= sizeof(struct posixevent))
  412.     {
  413.         evt = (struct posixevent *) event;
  414.     }
  415.     else
  416.     {
  417.         evt = *((struct posixevent **) event);
  418.     }
  419.     if (pthread_mutex_lock(&evt->mutex)) dbkprintf(10,"*** kn_waitvent: mutex_lock\n");
  420.     while (evt->status == 0)
  421.     {
  422.         if (pthread_cond_wait(&evt->cond, &evt->mutex)) dbkprintf(10,"*** kn_waitevent: cond_wait\n");
  423.     }
  424.     evt->status = 0;
  425.     if (pthread_mutex_unlock(&evt->mutex)) dbkprintf(10,"*** kn_waitvent: mutex_unlock\n");
  426. }
  427.  
  428.  
  429. TBOOL kn_timedwaitevent(TKNOB *event, TKNOB *timer, TTIME *tektime)
  430. {
  431.     TBOOL occured;
  432.     
  433.     struct timeval now;
  434.     struct timespec then;
  435.     int retcode;
  436.  
  437.     struct posixevent *evt;
  438.  
  439.     if (sizeof(TKNOB) >= sizeof(struct posixevent))
  440.     {
  441.         evt = (struct posixevent *) event;
  442.     }
  443.     else
  444.     {
  445.         evt = *((struct posixevent **) event);
  446.     }
  447.  
  448.     pthread_mutex_lock(&evt->mutex);
  449.  
  450.     if (tektime)
  451.     {
  452.         gettimeofday(&now, NULL);
  453.     
  454.         then.tv_sec = now.tv_sec + tektime->sec;
  455.         then.tv_nsec = now.tv_usec + tektime->usec;
  456.         if (then.tv_nsec >= 1000000)
  457.         {
  458.             then.tv_nsec -= 1000000;
  459.             then.tv_sec++;
  460.         }
  461.         then.tv_nsec *= 1000;
  462.     
  463.         retcode = 0;
  464.         while (evt->status == 0 && retcode != ETIMEDOUT)
  465.         {
  466.             retcode = pthread_cond_timedwait(&evt->cond, &evt->mutex, &then);
  467.         }
  468.         occured = evt->status;
  469.         evt->status = 0;
  470.     }
  471.     else
  472.     {
  473.         occured = evt->status;
  474.         evt->status = 0;
  475.     }
  476.  
  477.     pthread_mutex_unlock(&evt->mutex);
  478.  
  479.     return occured;
  480. }
  481.  
  482.  
  483.  
  484. /* 
  485. **    THREAD
  486. **
  487. **    flaw: we assume that the first TSD key created has index 0.
  488. **
  489. */
  490.  
  491. static void *posixthread_entry(struct posixthread *thread)
  492. {
  493.     pthread_key_t tsdkey = 0;
  494.  
  495.     pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  496.  
  497.     if (pthread_setspecific(tsdkey, (void *) thread) != 0)
  498.     {
  499.         dbkprintf(20,"*** TEKLIB kernel: failed to set TSD key 0\n");
  500.     }
  501.  
  502.     (*thread->function)(thread->data);
  503.  
  504.     /*pthread_exit(NULL);*/
  505.     return NULL;
  506. }
  507.  
  508.  
  509. TBOOL kn_initthread(TKNOB *thread, TVOID (*function)(TAPTR task), TAPTR data)
  510. {
  511.     if (sizeof(TKNOB) >= sizeof(struct posixthread))
  512.     {
  513.         struct posixthread *t = (struct posixthread *) thread;
  514.         pthread_attr_t attr;
  515.  
  516.         t->function = function;
  517.         t->data = data;
  518.  
  519.         if (pthread_attr_init(&attr) == 0)
  520.         {
  521.             if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0)
  522.             {
  523.                 if (pthread_create(&t->pthread, &attr, (void *(*)(void *)) posixthread_entry, t) == 0)
  524.                 {
  525.                     pthread_attr_destroy(&attr);
  526.                     return TTRUE;
  527.                 }
  528.             }
  529.             pthread_attr_destroy(&attr);
  530.         }
  531.     }
  532.     else
  533.     {
  534.         struct posixthread *t = kn_alloc(sizeof(struct posixthread));
  535.         if (t)
  536.         {
  537.             pthread_attr_t attr;
  538.     
  539.             t->function = function;
  540.             t->data = data;
  541.     
  542.             if (pthread_attr_init(&attr) == 0)
  543.             {
  544.                 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0)
  545.                 {
  546.                     if (pthread_create(&t->pthread, &attr, (void *(*)(void *)) posixthread_entry, t) == 0)
  547.                     {
  548.                         pthread_attr_destroy(&attr);
  549.                         *((struct posixthread **) thread) = t;
  550.                         return TTRUE;
  551.                     }
  552.                 }
  553.                 pthread_attr_destroy(&attr);
  554.             }
  555.             kn_free(t);
  556.         }
  557.     }
  558.  
  559.     dbkprintf(20,"*** TEKLIB kernel: could not create thread\n");
  560.     return TFALSE;
  561. }
  562.  
  563.  
  564. TBOOL kn_initbasecontext(TKNOB *thread, TAPTR data)
  565. {
  566.     if (sizeof(TKNOB) >= sizeof(struct posixthread))
  567.     {
  568.         struct posixthread *t = (struct posixthread *) thread;
  569.  
  570.         kn_memset(t, sizeof(struct posixthread), 0);
  571.  
  572.         if (pthread_key_create(&t->tsdkey, NULL) == 0)
  573.         {
  574.             if (t->tsdkey == 0)
  575.             {
  576.                 if (pthread_setspecific(t->tsdkey, thread) == 0)
  577.                 {                
  578.                     sigset_t newmask;
  579.                     sigemptyset(&newmask);
  580.                     sigaddset(&newmask, SIGPIPE);
  581.                     sigprocmask(SIG_BLOCK, &newmask, NULL);
  582.  
  583.                     pthread_mutex_init(&t->proclock, NULL);
  584.  
  585.                     pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  586.                     t->data = data;
  587.                     return TTRUE;
  588.                 }
  589.             }
  590.             else
  591.             {
  592.                 dbkprintf(20,"*** TEKLIB kernel: TSD key created != 0\n");
  593.             }
  594.             pthread_key_delete(t->tsdkey);
  595.         }
  596.     }
  597.     else
  598.     {
  599.         struct posixthread *t = kn_alloc0(sizeof(struct posixthread));
  600.         if (t)
  601.         {
  602.             if (pthread_key_create(&t->tsdkey, NULL) == 0)
  603.             {
  604.                 if (t->tsdkey == 0)
  605.                 {
  606.                     if (pthread_setspecific(t->tsdkey, t) == 0)
  607.                     {
  608.                         sigset_t newmask;
  609.                         sigemptyset(&newmask);
  610.                         sigaddset(&newmask, SIGPIPE);
  611.                         sigprocmask(SIG_BLOCK, &newmask, NULL);
  612.  
  613.                         pthread_mutex_init(&t->proclock, NULL);
  614.  
  615.                         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  616.                         t->data = data;
  617.                         *((struct posixthread **) thread) = t;
  618.                         return TTRUE;
  619.                     }
  620.                 }
  621.                 else
  622.                 {
  623.                     dbkprintf(20,"*** TEKLIB kernel: TSD key created != 0\n");
  624.                 }
  625.                 pthread_key_delete(t->tsdkey);
  626.             }
  627.         }
  628.     }    
  629.  
  630.     dbkprintf(20,"*** TEKLIB kernel: could not establish basecontext\n");
  631.     return TFALSE;
  632. }
  633.  
  634.  
  635. TVOID kn_destroybasecontext(TKNOB *thread)
  636. {
  637.     if (sizeof(TKNOB) >= sizeof(struct posixthread))
  638.     {
  639.         pthread_mutex_destroy(&((struct posixthread *) thread)->proclock);
  640.         pthread_key_delete(((struct posixthread *) thread)->tsdkey);
  641.     }
  642.     else
  643.     {
  644.         pthread_mutex_destroy(&(*((struct posixthread **) thread))->proclock);
  645.         pthread_key_delete((*((struct posixthread **) thread))->tsdkey);
  646.         kn_free(*((struct posixthread **) thread));
  647.     }
  648. }
  649.  
  650.  
  651. TVOID kn_deinitthread(TKNOB *thread)
  652. {
  653.  
  654. }
  655.  
  656.  
  657. TVOID kn_destroythread(TKNOB *thread)
  658. {
  659.     if (sizeof(TKNOB) < sizeof(struct posixthread))
  660.     {
  661.         kn_free(*((struct posixthread **) thread));
  662.     }
  663. }
  664.  
  665.  
  666. TAPTR kn_findself(TVOID)
  667. {
  668.     pthread_key_t tsdkey = 0;
  669.     return ((struct posixthread *) pthread_getspecific(tsdkey))->data;
  670. }
  671.  
  672.  
  673.  
  674. TINT kn_getrandomseed(TKNOB *timer)
  675. {
  676.     struct timeval nt1, nt2;
  677.  
  678.     gettimeofday(&nt1, NULL);
  679.     gettimeofday(&nt2, NULL);
  680.     
  681.     return (nt1.tv_usec + nt2.tv_usec * 4279 + nt2.tv_sec);
  682. }
  683.  
  684.  
  685.  
  686.  
  687. #if 0
  688.  
  689. /* 
  690. **    posix-special:
  691. **
  692. */
  693.  
  694. TVOID kn_lockbasecontext(TKNOB *thread)
  695. {
  696.     if (sizeof(TKNOB) >= sizeof(struct posixthread))
  697.     {
  698.         if (pthread_mutex_lock(&((struct posixthread *) thread)->proclock)) dbkprintf(10,"lockbasecontext1\n");
  699.     }
  700.     else
  701.     {
  702.         if (pthread_mutex_lock(&(*((struct posixthread **) thread))->proclock)) dbkprintf(10,"lockbasecontext2\n");
  703.     }
  704. }
  705.  
  706. TVOID kn_unlockbasecontext(TKNOB *thread)
  707. {
  708.     if (sizeof(TKNOB) >= sizeof(struct posixthread))
  709.     {
  710.         if (pthread_mutex_unlock(&((struct posixthread *) thread)->proclock)) dbkprintf(10,"unlockbasecontext1\n");
  711.     }
  712.     else
  713.     {
  714.         if (pthread_mutex_unlock(&(*((struct posixthread **) thread))->proclock)) dbkprintf(10,"unlockbasecontext2\n");
  715.     }
  716. }
  717.  
  718. #endif
  719.