-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add thread:setname and thread:getname #208
base: master
Are you sure you want to change the base?
Conversation
Is Some quick googling suggests:
|
src/thread.c
Outdated
} | ||
lua_pushstring(L, buf); | ||
return 1; | ||
} /* ct_setname() */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct
Oh, you're right, that's quite a mess. I've added checks to explicitly support the relevant functions on Linux, the BSDs and OS X. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that config.h.guess is from the autoguess project (https://github.com/wahern/autoguess/).
You may want to send your changes there?
#if HAVE_PTHREAD_SETNAME | ||
static int ct_setname(lua_State *L) { | ||
struct cthread *ct = ct_checkthread(L, 1); | ||
char *name = luaL_checkstring(L, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is too much whitespace here.
#elif HAVE_MACOSX_PTHREAD | ||
if (pthread_equal(ct->id, pthread_self())) { | ||
lua_pushboolean(L, 0); | ||
lua_pushliteral(L, "thread name cannot be set from outside the thread on this platform"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
switch(rc) { | ||
case 0: | ||
lua_pushboolean(L, 1); | ||
return 1; | ||
case ERANGE: | ||
lua_pushboolean(L, 0); | ||
lua_pushliteral(L, "thread name too long"); | ||
lua_pushinteger(L, rc); | ||
return 3; | ||
case EINVAL: | ||
lua_pushboolean(L, 0); | ||
lua_pushliteral(L, "invalid parameter when setting thread name"); | ||
lua_pushinteger(L, rc); | ||
return 3; | ||
case ENOMEM: | ||
lua_pushboolean(L, 0); | ||
lua_pushliteral(L, "out of memory when setting thread name"); | ||
lua_pushinteger(L, rc); | ||
return 3; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what if rc
is something else: needs a default
option
Adds wrappers for
pthread_setname_np
andpthread_getname_np
to the thread metatable. It's quite useful to be able to name long-running threads!