Skip to content

Commit

Permalink
Implement pthread_getattr_np, and add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Apr 27, 2015
1 parent fe37564 commit b05bdf8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ var LibraryPThread = {
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.pid }}} ) >> 2, PROCINFO.pid); // Process ID.

Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}}) >> 2, threadParams.stackSize);
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.stack_size }}}) >> 2, threadParams.stackSize);
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.stack }}}) >> 2, threadParams.stackBase);
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}} + 8) >> 2, threadParams.stackBase);
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}} + 12) >> 2, threadParams.detached);
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}} + 20) >> 2, threadParams.schedPolicy);
Expand Down
2 changes: 2 additions & 0 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@
"tsd",
"tsd_used",
"detached",
"stack",
"stack_size",
"attr",
"tid",
"pid",
Expand Down
9 changes: 9 additions & 0 deletions system/lib/pthread/library_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ void pthread_testcancel()
}
}

int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
{
*a = (pthread_attr_t){0};
a->_a_detach = !!t->detached;
a->_a_stackaddr = (uintptr_t)t->stack;
a->_a_stacksize = t->stack_size - DEFAULT_STACK_SIZE;
return 0;
}

static uint32_t dummyZeroAddress = 0;

int usleep(unsigned usec)
Expand Down
1 change: 1 addition & 0 deletions system/lib/pthreads.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
T pthread_condattr_setclock
T pthread_condattr_setpshared
T pthread_equal
T pthread_getattr_np
T pthread_getspecific
T pthread_key_create
T pthread_key_delete
Expand Down
12 changes: 11 additions & 1 deletion tests/pthread/test_pthread_create_pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ volatile int result = 0;
static void *thread2_start(void *arg)
{
EM_ASM(Module['print']('thread2_start!'););
result = 1;
++result;

#ifdef REPORT_RESULT
REPORT_RESULT();
Expand All @@ -31,6 +31,16 @@ int main()
{
pthread_t thr;
pthread_create(&thr, NULL, thread1_start, 0);

pthread_attr_t attr;
pthread_getattr_np(thr, &attr);
size_t stack_size;
void *stack_addr;
pthread_attr_getstack(&attr, &stack_addr, &stack_size);
printf("stack_size: %d, stack_addr: %p\n", (int)stack_size, stack_addr);
if (stack_size != 81920 || stack_addr == 0)
result = -100; // Report failure.

// pthread_join(thr, 0);

//#ifdef REPORT_RESULT
Expand Down

0 comments on commit b05bdf8

Please sign in to comment.