Thread.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Author : Bruce Liang
  5. * Website : https://github.com/ldcsaa
  6. * Project : https://github.com/ldcsaa/HP-Socket
  7. * Blog : http://www.cnblogs.com/ldcsaa
  8. * Wiki : http://www.oschina.net/p/hp-socket
  9. * QQ Group : 44636872, 75375912
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. #include "Thread.h"
  24. static __thread BOOL s_tlsInterrupt = FALSE;
  25. BOOL __CThread_Interrupt_::sm_bInitFlag = __CThread_Interrupt_::InitSigAction();
  26. __CThread_Interrupt_::~__CThread_Interrupt_ () {s_tlsInterrupt = FALSE;}
  27. BOOL __CThread_Interrupt_::IsInterrupted () {return s_tlsInterrupt;}
  28. BOOL __CThread_Interrupt_::InitSigAction()
  29. {
  30. struct sigaction act;
  31. sigemptyset(&act.sa_mask);
  32. act.sa_handler = SignalHandler;
  33. act.sa_flags = 0;
  34. if(IS_HAS_ERROR(sigaction(SIG_NO_INTERRUPT, &act, nullptr)))
  35. ERROR_ABORT();
  36. return TRUE;
  37. }
  38. void __CThread_Interrupt_::SignalHandler(int sig)
  39. {
  40. if(sig == SIG_NO_INTERRUPT)
  41. s_tlsInterrupt = TRUE;
  42. }