If something like this were actually created, would it
look anything like the file I just attached.  I have yet
to put the rest of the headers, etc on... but it
technically should be a working  pthread_create()
function as far as I can tell, if I'm not as stupid
as I think I am ;)

-----------------------------
Brad House
Sr. Developer
Main Street Softworks, Inc.

[EMAIL PROTECTED]
(352) 378-8228
-----------------------------

int le_threadid;
int le_pthreadattr;

typedef struct function_params {
  zval **function_name;
  zval ***args_ptr;
} function_params;

void *call_user_function(void *params)
{
  function_params *my_params=params;
  zval *retval;
  CLS_FETCH();
  if (call_user_function_ex(CG(function_table), NULL, *(my_params->function_name), 
&retval, 0, my_params->args_ptr, 0) != SUCCESS) {
    zend_error(E_ERROR, "Function call failed");
  }
  return(retval);
}

/* {{{ proto int pthread_create(int pthread_attr, string function_name, args...)
        RETURN:
                Success:  resource id of pthread_t (thread id)
                Fail: -1
        INPUT:
                pthread_attr: resource id for pthread attributes.  -1 for none
                function_name: php function name to call
                args...: all arguments to be passed to function
*/
PHP_FUNCTION(pthread_create)
{
  zval **pthread_attr, ***args=NULL;
  pthread_t *thread;
  pthread_attr_t *attr=NULL;
  function_params *my_params;
  int argcount;
  int ret;

  argcount=ZEND_NUM_ARGS();
  if (argcount < 2) {
    WRONG_PARAM_COUNT;
  }
  args=(zval ***)emalloc(argcount*sizeof(zval **));
  if (zend_get_parameters_array_ex(argcount, args) != SUCCESS) {
    free(args);
    WRONG_PARAM_COUNT;
  }
  if ((*args[1])->type != IS_STRING) {
    efree(args);
    zend_error(E_ERROR, "Function requires string argument");
  }
  my_params=(function_params *)emalloc(1*sizeof(function_params));
  my_params->function_name=args[1];
  my_params->args_ptr=args+2;
  thread=(pthread_t *)emalloc(1*sizeof(pthread_t));
  if (Z_LVAL_PP(args[0]) != -1) {
    ZEND_FETCH_RESOURCE(attr, pthread_attr_t *, args[0], -1, "pthread_attribute", 
le_pthreadattr);
  }
  ret=pthread_create(thread, attr, (void *)call_user_function, (void *)my_params);
  if (ret != 0) {
    efree(my_params);
    efree(args);
    efree(thread);
    RETURN_LONG(-1);
  }
  ZEND_REGISTER_RESOURCE(return_value, thread, le_thread);
}



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to