id.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include "threadimpl.h"
  5. int
  6. threadid(void)
  7. {
  8. return _threadgetproc()->thread->id;
  9. }
  10. int
  11. threadpid(int id)
  12. {
  13. int pid;
  14. Proc *p;
  15. Thread *t;
  16. if (id < 0)
  17. return -1;
  18. if (id == 0)
  19. return _threadgetproc()->pid;
  20. lock(&_threadpq.lock);
  21. for (p = _threadpq.head; p->next; p = p->next){
  22. lock(&p->lock);
  23. for (t = p->threads.head; t; t = t->nextt)
  24. if (t->id == id){
  25. pid = p->pid;
  26. unlock(&p->lock);
  27. unlock(&_threadpq.lock);
  28. return pid;
  29. }
  30. unlock(&p->lock);
  31. }
  32. unlock(&_threadpq.lock);
  33. return -1;
  34. }
  35. int
  36. threadsetgrp(int ng)
  37. {
  38. int og;
  39. Thread *t;
  40. t = _threadgetproc()->thread;
  41. og = t->grp;
  42. t->grp = ng;
  43. return og;
  44. }
  45. int
  46. threadgetgrp(void)
  47. {
  48. return _threadgetproc()->thread->grp;
  49. }
  50. void
  51. threadsetname(char *name)
  52. {
  53. Thread *t;
  54. t = _threadgetproc()->thread;
  55. if (t->cmdname)
  56. free(t->cmdname);
  57. t->cmdname = strdup(name);
  58. }
  59. char*
  60. threadgetname(void)
  61. {
  62. return _threadgetproc()->thread->cmdname;
  63. }
  64. void**
  65. threaddata(void)
  66. {
  67. return &_threadgetproc()->thread->udata;
  68. }
  69. void**
  70. procdata(void)
  71. {
  72. return &_threadgetproc()->udata;
  73. }